Netbula LLC                                                                   sitemapcontact us
about usproductssupportdownloadpurchase


Introduction
RPCGEN Manual
  Multithread Guide
Resources
Download
RPC Forum
Anyemail Anyboard JRPC ONC RPC PowerRPC
  • Multithreading with Netbula RPC For Win32
  • How to use fix port for an RPC service and how to by-pass portmapper registration
  • How to use TCP protocol for Portmapper queries
  • How to set clnt_create() timeouts

Multithreading with Netbula RPC For Win32

Netbula RPC for Win32 supports multithreading, this document describe the procedure to build multithreaded (MT) RPC server and clients.

MT Server

There are two methods to create MT servers: thread on connect and thread on call.

Thread on connect

By calling pw_set_mt_on_connect(1) (with argument being 1) before svc{proto}_create(), the newly created service becomes a MT server.

  • UDP service
    The UDP service will run in a separate thread of itself

  • TCP service
    A new dedicated thread will be created for each client upon connection to the server, the thread exits when the client close the connection with the server.

One easy way to enable this feature is define to RPC_MT_CONNECT macro in the .x file.

Thread on call

The option will cause the server to create a new thread to handle an incoming RPC call, this option is applied to individual procedures.

  • ONC RPC
    Enable this option by setting the mt_on_call field of the callInfo structure to PWRPC_ONC_MT defined in powerrpc.h.
  • PowerRPC
    Enable this option by setting the mt_on_call field of the callInfo structure to POWERRPC_THREADING defined in powerrpc.h.

MT Client

For ONC RPC, the return result from server is stored in a static variable, to make this variable thread local, define the PWRPC_MT macro. One way to do this is to add a line

%define PWRPC_MT

in the *.x file.

A better way for programming multi-threaded client is to use the two argument form of the RPC call. Instead of using return value, one can pass in a pointer, which is used to hold the return value. To use the two argument form you must define the RPC_RETURN_ARG macro in the header. See the MSG sample client program.

How to use fix port for an RPC service and how to by-pass portmapper registration

To use fixed port number for an RPC server is very easy. You just need to define the macros

{RPC_VERSION}_tcp_server_port
{RPC_VERSION}_udp_server_port


with the port numbers you want. For example, if you add the following line to the msg.x file, the msg TCP server will use port 5555:

%#define MSGSERV_V1_tcp_server_port 5555

the UDP server will still use randomly assigned port number.

To by-pass registration with portmapper, simply define the following macros:

{RPC_VERSION}_tcp_no_pmap
{RPC_VERSION}_udp_no_pmap

For example,
#define MSGSERV_V1_tcp_no_pmap 1

will make the server skip portmapper registration for the TCP part of the server.

 

How to use TCP protocol to query the portmapper

When an RPC client connects to the server the first time, it needs to find out the port number of the RPC server through the portmapper. By default, the protocol for contacting the portmapper is UDP, which may present some problems for certains situations. To use TCP protocol for portmapper query, simply call the following function before the clnt_create() calls.

pmap_set_use_tcp(1);



| Home | Products | Support | Download | Purchase | Site Map | Contact Us |
Copyright © 2000, Netbula LLC, All Rights Reserved.