Shared memory and IPC

Rich Salz rsalz at zolera.com
Wed Sep 5 18:29:10 GMT 2001


{I think I got all the right mailing lists, per Luke's request.  I
dropped APR dev.}

I always found RPC towers -- the actual data structures that are created
from string binding handles, like "ncadg_ip_udp:[135]" -- hard to
understand.  The following OSF RFC might help a bit:
http://www.opengroup.org/rfc/rfc81.2.html

Here is an idea for how to do shared-memory IPC.  A server that supports
this protseq creates a publically-accessible semaphore and message
area.  The semaphore is set when someone wants to send a message, and
cleared when the server has read the message.
When the server sees a message is there, it read the message.  That
message contains information about the shared memory segment that the
client has set up.  The server then maps that segment, and clears the
semaphore.  The client and server now communicate through the shared
memory, using a little semahore-like byte at the start of the memory. 
Or they can create their own semphore to synchronize who owns the sahred
memory.

When the client wants to use shared-memory protseq it gets an endpoint
that contains a filename (for use with ftok() and the server's local
user id).  So the string binding handle would look like this:
ncadg_sm[id=0,ftok=/tmp/foo]  (It's convenient that we only need two
values; one tower floor with left and right sides :)  The client creates
a shared memory segment, (and perhaps/probably a semaphore) and changes
the permissions so that while it as creator has all perms, the owner is
specified by the "id" and it also has all perms.  It then sets the
server's semaphore, writes a msesage saying "here is my shared memory id
and our new semaphore" and waits for the server to set/clear the new
semaphore, meaning they've got the shared memory in common now.

Make sense?  Lots of details to do, like having dced (er rpcd for old
versions :) know how to clean up those endpoints. Since you typically
can't select() on a sysv IPC sema or shared memory, you have to spawn a
thread that sends messages back on a special internal loopback socket so
select() knows what to do.  per-fork cleanup.  etc.

Hope this helps.
	/r$
-- 
Zolera Systems, Securing web services (XML, SOAP, Signatures,
Encryption)
http://www.zolera.com




More information about the samba-technical mailing list