select semantics on unix domain sockets?

Volker Lendecke Volker.Lendecke at SerNet.DE
Wed Sep 28 14:44:30 GMT 2005


Hi, Tridge!

I've found some strange behaviour with Linux's unix dgram sockets that might
be interesting for Samba4.

Samba 4 uses unix domain sockets for messaging. I'm trying to do something
similar in Samba3 right now and came across some special behaviour. For
different reasons I'm implementing a central dispatching daemon. This daemon
is supposed to use a classic select/recv/send loop to dispatch messages across
unix domain sockets. I put the sockets into non-blocking mode, and when a
client had its receiving buffer full, the daemon that tried to send to that
client would spin. select said the socket is writable, but the send call
returned EAGAIN. Then I put the socket into blocking mode and retried. The
following strace shows some behaviour I don't understand:

16:29:55.868587 socket(PF_FILE, SOCK_DGRAM, 0) = 16
16:29:55.868711 stat64("/data/tmp/var/locks", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
16:29:55.868894 connect(16, {sa_family=AF_FILE, path="/data/tmp/var/locks/messaging/0.0.0.0:31213"}, 110) = 0
16:29:55.869070 select(17, [11 12 14], [16], [11], NULL) = 1 (out [16])
16:29:55.869533 gettimeofday({1127917795, 869585}, NULL) = 0
16:29:55.869635 open("/etc/localtime", O_RDONLY) = 17
16:29:55.869733 fstat64(17, {st_mode=S_IFREG|0644, st_size=837, ...}) = 0
16:29:55.869873 close(17)               = 0
16:29:55.869961 geteuid32()             = 1000
16:29:55.870049 write(5, "[2005/09/28 16:29:55.869585, 10,"..., 78) = 78
16:29:55.870167 geteuid32()             = 1000
16:29:55.870251 write(5, "  dispatching to client 0.0.0.0:"..., 38) = 38
16:29:55.870372 write(16, "\1\0\0\0\2\0\0\0\1\0\0\0\0\0\0\0\355y\0\0\0\0\0\0\355y"..., 32) = 32
16:29:59.550779 close(16)               = 0
16:29:59.559834 select(15, [11 12 14], [], [11], NULL) = 1 (in [12])

Watch the select call telling us socket 16 is writable and the write call at
timestamp 16:29:55.870372 block for some seconds. The reason it came back
after some seconds is due to the client starting to read from that socket. The
syscalls in between are from a debug message. The same happens if I use send()
instead of write() for delivery.

Am I understanding anything wrong here? BTW, I'm using Linux kernel
2.6.8-24.13 from SuSE 9.2.

The next thing I'm going to test is a unix stream socket for the dispatcher
communication. This is something I would like to avoid however, the dgram
interface guarantees message boundaries.

Thanks,

Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20050928/4aca9bd8/attachment.bin


More information about the samba-technical mailing list