version 1.1.2.6, 2007/01/17 21:32:26
|
version 1.1.2.7, 2007/01/17 22:12:13
|
|
|
#include "Defines.h" | #include "Defines.h" |
#include <sys/socket.h> | #include <sys/socket.h> |
#include <string.h> | #include <string.h> |
|
#include "Defines.h" |
| |
EXECUTOR_LINKAGE | EXECUTOR_LINKAGE |
int SetNonBlocking(int sock); | int SetNonBlocking(int sock); |
|
|
| |
static int RecvDescriptorArray(int sock, int descriptors[], size_t count) | static int RecvDescriptorArray(int sock, int descriptors[], size_t count) |
{ | { |
struct msghdr mh; |
|
size_t size; |
|
char* data; |
|
struct iovec iov[1]; | struct iovec iov[1]; |
char dummy; | char dummy; |
|
struct msghdr mh; |
ssize_t n; | ssize_t n; |
|
#if defined(HAVE_MSG_CONTROL) |
|
size_t size; |
|
char* data; |
struct cmsghdr* cmh = CMSG_FIRSTHDR(&mh); | struct cmsghdr* cmh = CMSG_FIRSTHDR(&mh); |
| |
/* | /* |
|
|
mh.msg_control = data; | mh.msg_control = data; |
mh.msg_controllen = size; | mh.msg_controllen = size; |
| |
|
#else /* !defined(HAVE_MSG_CONTROL) */ |
|
|
|
mh.msg_accrights = (caddr_t)descriptors; |
|
mh.msg_accrightslength = sizeof(int) * count; |
|
|
|
#endif /* defined(HAVE_MSG_CONTROL) */ |
|
|
/* | /* |
* The other process sends a single-byte message. This byte is not | * The other process sends a single-byte message. This byte is not |
* used since we only need the control data (the descriptor) but we | * used since we only need the control data (the descriptor) but we |
|
|
* does not contain what we expect. | * does not contain what we expect. |
*/ | */ |
| |
|
#if defined(HAVE_MSG_CONTROL) |
|
|
cmh = CMSG_FIRSTHDR(&mh); | cmh = CMSG_FIRSTHDR(&mh); |
| |
if (!cmh || | if (!cmh || |
|
|
| |
memcpy(descriptors, CMSG_DATA(cmh), sizeof(int) * count); | memcpy(descriptors, CMSG_DATA(cmh), sizeof(int) * count); |
| |
|
#else /* !defined(HAVE_MSG_CONTROL) */ |
|
|
|
if (mh.msg_accrightslength != sizeof(int) * count) |
|
return -1; |
|
|
|
memcpy(descriptors, mh.msg_accrights, sizeof(int) * count); |
|
|
|
#endif /* defined(HAVE_MSG_CONTROL) */ |
|
|
return 0; | return 0; |
} | } |
| |