1

I need to create a client-server model which are connected through Unix socket. My client will request the server to open a file for which only server has the permissions. Server will open the file and send the FD using "sendmsg" API and client will receive the FD using the "recvmsg". Now my question is can I achieve this using the non-blocking socket? Also if it is possible, how do I know the length of message on client side?

Please point me to some non-blocking implementation of the same.

Saurabh
  • 51
  • 5
  • The blocking status of the socket has nothing to do with it. For the actual descriptor transmission, I suggest a Google search for terms like "send file descriptor over unix domain socket". Also, [what have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – Some programmer dude Jun 21 '12 at 06:14
  • Duplicate: http://stackoverflow.com/questions/1788095/descriptor-passing-with-unix-domain-sockets – Saurabh Jun 21 '12 at 06:30

2 Answers2

0

Related: http://lists.canonical.org/pipermail/kragen-hacks/2002-January/000292.html so my answer was not complete.

Saurabh
  • 1,059
  • 10
  • 20
0

You should use sendfile to transmit the file between the FD and the socket.

If the socket is non-blocking, then the sendfile (or send or sendmsg) call will likely return a value indicating a partial amount completed. Use select() or poll() to get notified of when it's possible to send again (picking up from the previous point in the file descriptor when the previous send left off).

As for the file length, you'll have to add that to your request/response protocol yourself. (e.g. call stat() on the server, send the file length, then send the file itself).

selbie
  • 100,020
  • 15
  • 103
  • 173