The following code example shows the time_prot.h header file for the server.
Example 7-2 MT Auto Mode: time_prot.h
#include <rpc/types.h>
struct timev {
int second;
int minute;
int hour;
};
typedef struct timev timev;
bool_t xdr_timev();
#define TIME_PROG 0x40000001
#define TIME_VERS 1
#define TIME_GET 1
|
MT User Mode
In MT User mode, the RPC library does not create any threads. This mode works, in principle, like the single-threaded, or default mode. The only difference is that it passes copies of data structures, such as the transport service handle to the service-dispatch routine to be MT safe.
The RPC server developer takes the responsibility for creating and managing threads through the thread library. In the dispatch routine, the service developer can assign the task of procedure execution to newly created or existing threads. The thr_create() API is used to create threads having various attributes. All thread library interfaces are defined in thread.h. See the pthread_create(3THR) man page for more details.
This mode provides flexibility to the service developer. Threads can now have different stack sizes based on service requirements. Threads can be bound. Different procedures can be executed by threads with different characteristics. The service developer might choose to run some services single threaded. The service developer might choose to do special thread-specific signal processing.
As in the Auto mode, you use the rpc_control() library call to turn on User mode. Note that the rpc_control() operations shown in Table 7-1, except for RPC_SVC_MTMODE_GET(), apply only to MT Auto mode. If used in MT User mode or the single-threaded default mode, the results of the operations can be undefined.
Freeing Library Resources in User Mode
In the MT User mode, service procedures must invoke svc_done() before returning. svc_done() frees resources allocated to service a client request directed to the specified service transport handle. This function is invoked after a client request has been serviced, or after an error or abnormal condition that prevents a reply from being sent. After svc_done() is invoked, the service procedure should not reference the service transport handle. The following example shows a server in MT User mode.
Note - svc_done() must only be called within MT User mode. For more information on this call, see the rpc_svc_calls(3NSL) man page.
Example 7-3 MT User Mode: rpc_test.h
The following code example is the client for MT User mode.
Example 7-4 Client for MT User Mode



