[comp.windows.x] Need Help with mixing RPC and X

vrm@cathedral.cerc.wvu.wvnet.edu (Vasile R. Montan) (05/31/90)

  I have only been working with X for a short time so this may be a
basic question or even a stupid one, but I would appreciate any help
that I can get.

  I am trying to convert an RPC server and client from handling
standard input to using X.  The problem is that both RPC and X require
a callback-handling loop.  I can see how to do this if I want to poll
both the RPC port and the X event queue, but I do not have anything
else to do in the program and do not want to waste CPU for an idle
loop.  What I need is either:

1. The ability to tell XtMainLoop to look for an RPC request while
   looking for X events, and have it call an appropriate callback.

or

2. The capability to wait for either an RPC request or an X event and
   calling the appropriate procedure to handle the RPC request or the
   X event depending on what was pending.  This is similar to what I
   do no for stdin, but I have a feeling that this is not PC in X.

   For example:   main()                                                   
		  {                                                        
		    int imask;                                            
		    svc_register (...);                                   
		    for (;;) {                                            
		      imask = (svc_fds | x_file_descriptor_set_address); 
		      if (select (32, &imask, NULL, NULL, NULL) == -1);  
		        continue;                                       
		      if (imask & x_file_descriptor_set_address)         
 		        handle_x_event();                               
        	      if (imask & svc_fds)                               
		        svc_getreq (imask);                             
		    }                                                     
		  }                                                        
	
or

3. Maybe you have a better idea.

   If anyone has any ideas or knows of somewhere to look for more
information, please let me know.

   Thanks,

-- Vasile

dpb@viking.UUCP (Don Bennett 433-3311, 408) (06/01/90)

> 1. The ability to tell XtMainLoop to look for an RPC request while
>    looking for X events, and have it call an appropriate callback.
> 
> or
> 
> 2. The capability to wait for either an RPC request or an X event and
>    calling the appropriate procedure to handle the RPC request or the
>    X event depending on what was pending.  This is similar to what I
>    do no for stdin, but I have a feeling that this is not PC in X.

How about this? Works for me....

/*
 * Function Xt will use to process pending input on the RPC 
 * file descriptor;
 */

rpcListen(client_data, source, id)
caddr_t client_data;
int *source;
XtInputId *id;
{
    svc_getreq(1 << *source);
}

/*
 * main program
 */

main()
{
    int fd;

    svc_register(transp, ...);
    fd = transp->xp_sock;
    XtAppAddInput(_XtDefaultAppContext(), fd, XtInputReadMask,
                  rpcListen, 0);
    XtMainLoop();
}

   Don Bennett           (408)433-3311
   dpb@frame.com
   Frame Technology

db@witzend.East.Sun.COM (David Brownell) (06/02/90)

Re the question of how to get an X (Xt) application to act as an
RPC server (client is no issue), dpb@viking.frame.com (Don Bettnet)
writes:

>> 1. The ability to tell XtMainLoop to look for an RPC request while
>>    looking for X events, and have it call an appropriate callback.
>> 
>
>How about this? Works for me....

    > Solution deleted to avoid clutter:  it used XtAppAddInput()
    > to install an input callback on the file descriptor used by
    > the service transprot handles:  SVCXPRT *t; fd = t->xp_sock.
    > The input callback invoked svc_getreq() to handle the call.

It's worth noting that this posted solution works only for UDP RPCs.
That is, if you use TCP for simpler semantics, more data than the
default of 8 Kbytes, or better error reporting, this doesn't work.

Also, this uses the obsolete svc_getreq() call, which is limited
to 32 file descriptors.  More recent UNIXes have a much higher
limit -- this should use svc_getreqset() instead, which handles
many more file descriptors.

The issue with TCP is that the RPC library needs to allocate and
deallocate file descriptors dynamically.  To handle this within
Xt, the input callback for the tcp-based SVCXPRT must diff the RPC
file descriptors in svc_fdset before and after it calls svc_getreqset(),
invoking XtAppAddInput (or XtAddInput) on new file descriptors and
calling XtRemoveInput() one ones that've disappeared.

The upcoming release of XView will do this for you automatically if
you ask, so that you won't have to scour the innards of the window
system and notifier documentation to find out how to do this!




David Brownell			db@east.sun.com.
Sun Desktop Systems Software	(508) 671-0348
"We'll get to ISO, Mars, and Pluto ... not necessarily in that order."