refactor: remove conditional compilation layers
This commit is contained in:
39
ipc.c
39
ipc.c
@@ -7,10 +7,6 @@
|
||||
#include <sys/un.h>
|
||||
#include "ipc.h"
|
||||
|
||||
#if !defined(MSG_NOSIGNAL) && !defined(SO_NOSIGPIPE)
|
||||
#error "ipcsend requires MSG_NOSIGNAL or SO_NOSIGPIPE"
|
||||
#endif
|
||||
|
||||
static void
|
||||
putlen(unsigned char p[Ipclensz], size_t n)
|
||||
{
|
||||
@@ -68,8 +64,8 @@ ipcconnect(void)
|
||||
}
|
||||
|
||||
void
|
||||
ipcpackreq(unsigned char req[Ipcreqsz], int want, unsigned int mod,
|
||||
unsigned int key)
|
||||
ipcpackreq(unsigned char req[Ipcreqsz], int want, uint32_t mod,
|
||||
uint32_t key)
|
||||
{
|
||||
req[0] = want ? Ipcreqwant : 0;
|
||||
req[1] = mod;
|
||||
@@ -87,15 +83,15 @@ ipcpackreset(unsigned char req[Ipcreqsz], int want)
|
||||
}
|
||||
|
||||
void
|
||||
ipcunpackreq(const unsigned char req[Ipcreqsz], int *want, unsigned int *mod,
|
||||
unsigned int *key)
|
||||
ipcunpackreq(const unsigned char req[Ipcreqsz], int *want, uint32_t *mod,
|
||||
uint32_t *key)
|
||||
{
|
||||
*want = (req[0] & Ipcreqwant) != 0;
|
||||
*mod = req[1] & Mmask;
|
||||
*key = (unsigned int)req[2] |
|
||||
((unsigned int)req[3] << 8) |
|
||||
((unsigned int)req[4] << 16) |
|
||||
((unsigned int)req[5] << 24);
|
||||
*key = (uint32_t)req[2] |
|
||||
((uint32_t)req[3] << 8) |
|
||||
((uint32_t)req[4] << 16) |
|
||||
((uint32_t)req[5] << 24);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -156,27 +152,10 @@ ipcsend(int fd, const void *buf, size_t n)
|
||||
{
|
||||
const unsigned char *p;
|
||||
ssize_t r;
|
||||
int flags;
|
||||
#if !defined(MSG_NOSIGNAL) && defined(SO_NOSIGPIPE)
|
||||
int one, sr;
|
||||
#endif
|
||||
|
||||
p = buf;
|
||||
#ifdef MSG_NOSIGNAL
|
||||
flags = MSG_NOSIGNAL;
|
||||
#else
|
||||
flags = 0;
|
||||
#ifdef SO_NOSIGPIPE
|
||||
one = 1;
|
||||
do
|
||||
sr = setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof one);
|
||||
while(sr < 0 && errno == EINTR);
|
||||
if(sr < 0)
|
||||
return -1;
|
||||
#endif
|
||||
#endif
|
||||
while(n > 0){
|
||||
r = send(fd, p, n, flags);
|
||||
r = send(fd, p, n, MSG_NOSIGNAL);
|
||||
if(r < 0 && errno == EINTR)
|
||||
continue;
|
||||
if(r <= 0)
|
||||
|
||||
Reference in New Issue
Block a user