大网数据广告活动
网络与域名解析

Context Handles

· 52CE 我爱测

It is sometimes the case that distributed applications require the server program to maintain status information between client calls.

It is sometimes the case that distributed applications require the server program to maintain status information between client calls. Server programs that service more than one client at a time must keep the state information for each client. Because the client and the server use different address spaces on different computers, and they do not necessarily trust each other, common approaches to data sharing often do not work. For instance, the client and server are unable to maintain status information on their remote session in global variables because they do not share the same global address space. It is difficult to keep the information in a shared file because they run on different computers. A simplistic approach may be to ship all state to the client and have the client return it on the next call, but this approach has flaws: the server does not necessarily trust the client to return the right state, and the state may be implicitly tied to some other state on the server, such as file handles or opened sockets.

Microsoft RPC provides a powerful and secure mechanism called context handles for keeping state associated with a given client on a server. The state information is called the server's context. Clients can obtain a context handle to identify the server's context for their individual RPC sessions.

As an example, each client in a distributed application can have the server program create and update a data file for their RPC session. The server can use its file handle for each client's data file as the context handle. Each time a client requests operations on the data file that the server creates for it, the client passes the context handle to the server. The client does not actually get the file handle itself; it gets an opaque token that the server RPC run time can uniquely associate with the file handle. Since the context handle is really a file handle, the context handle only makes sense in the server's address space. However, the client program can use the context handle to tell the server on which file to perform updates.

Other data can also be context handles. For instance, a client and server can use a record number of a database record as a file handle. If the client needed to perform a number of updates on a particular record, it could obtain the record number as a context handle. It would pass the record number to the server each time it invoked a remote procedure to update the database record.

Most often a context handle points to a block of memory on the server where the server keeps various management information.

This section presents information on defining and using context handles. The discussion is presented in the following topics:

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。