- RPCContext is used specially to assist asynchronous interfaces, and can be used in both Service and Client.
- Each asynchronous interface will provide a Context, which offers higher-level functions, such as obtaining the remote IP, the connection seqid, and so on.
- Some functions on Context are unique to Server or Client. For example, you can set the compression mode of the response data on Server, and you can obtain the success or failure status of a request on Client.
- On the Context, you can use
get_series()
to obtain the SeriesWork, which is seamlessly integrated with the asynchronous mode of Workflow.
One complete communication consists of request+response. The sequence id of the communication on the current socket connection can be obtained, and seqid=0 indicates the first communication.
Get the remote IP address. IPv4/IPv6 is supported.
Get the remote address. The in/out parameter is the lower-level data structure sockaddr.
Get RPC Service Name.
Get RPC Method Name.
Get the SeriesWork of the current ServerTask/ClientTask.
For client only. The success or failure of the request.
For client only. The rpc status code of the request.
For client only. The error info of the request.
For client only. The error code of the request.
For client only. Get the user_data of the ClientTask. If a user generates a task through the create_xxx_task()
interface, the context can be recorded in the user_data field. You can set that field when creating the task, and retrieve it in the callback function.
For Server only. Set the data packaging type
- RPCDataProtobuf
- RPCDataThrift
- RPCDataJson
For Server only. Set the data compression type (note: the compression type for the Client is set on Client or Task)
- RPCCompressNone
- RPCCompressSnappy
- RPCCompressGzip
- RPCCompressZlib
- RPCCompressLz4
For Server only. Set the attachment.
For Server only. Get the attachment.
For Server only. Set reply callback, which is called after the operating system successfully writes the data into the socket buffer.
For Server only. Set the maximum time for sending the message, in milliseconds. -1 indicates unlimited time.
For Server only. Set the maximum connection keep-alive time, in milliseconds. -1 indicates unlimited time.