Fix sending/receiving of FDs when stream returns EAGAIN
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 4 Nov 2011 16:02:14 +0000 (16:02 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 7 Nov 2011 09:26:59 +0000 (09:26 +0000)
commitb2c62316477989f8d728af49bdac8248ab5f5463
tree051adb81c657c52fb76114fcd84523911162d035
parent4d970fd2938a0558444cddb4f5f5e63b910b5527
Fix sending/receiving of FDs when stream returns EAGAIN

The code calling sendfd/recvfd was mistakenly assuming those
calls would never block. They can in fact return EAGAIN and
this is causing us to drop the client connection when blocking
ocurrs while sending/receiving FDs.

Fixing this is a little hairy on the incoming side, since at
the point where we see the EAGAIN, we already thought we had
finished receiving all data for the packet. So we play a little
trick to reset bufferOffset again and go back into polling for
more data.

* src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Update
  virNetSocketSendFD/RecvFD to return 0 on EAGAIN, or 1
  on success
* src/rpc/virnetclient.c: Move decoding of header & fds
  out of virNetClientCallDispatch and into virNetClientIOHandleInput.
  Handling blocking when sending/receiving FDs
* src/rpc/virnetmessage.h: Add a 'donefds' field to track
  how many FDs we've sent / received
* src/rpc/virnetserverclient.c: Handling blocking when
  sending/receiving FDs
src/rpc/virnetclient.c
src/rpc/virnetmessage.h
src/rpc/virnetserverclient.c
src/rpc/virnetsocket.c
src/rpc/virnetsocket.h