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)
|
||||
|
||||
10
ipc.h
10
ipc.h
@@ -1,7 +1,5 @@
|
||||
#ifndef STRANS_IPC_H
|
||||
#define STRANS_IPC_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* Request: [flags, modifiers, key byte 0, ..., key byte 3].
|
||||
@@ -51,9 +49,9 @@ struct Ipcresp
|
||||
size_t npreedit;
|
||||
};
|
||||
|
||||
void ipcpackreq(unsigned char[Ipcreqsz], int, unsigned int, unsigned int);
|
||||
void ipcpackreq(unsigned char[Ipcreqsz], int, uint32_t, uint32_t);
|
||||
void ipcpackreset(unsigned char[Ipcreqsz], int);
|
||||
void ipcunpackreq(const unsigned char[Ipcreqsz], int*, unsigned int*, unsigned int*);
|
||||
void ipcunpackreq(const unsigned char[Ipcreqsz], int*, uint32_t*, uint32_t*);
|
||||
int ipcreqreset(const unsigned char[Ipcreqsz]);
|
||||
int ipcpackresp(unsigned char*, size_t, int, const char*, size_t, const char*, size_t, int);
|
||||
int ipcreadn(int, void*, size_t);
|
||||
@@ -61,5 +59,3 @@ int ipcsend(int, const void*, size_t);
|
||||
int ipcreadresp(int, int, char*, size_t, char*, size_t, Ipcresp*);
|
||||
int ipcpath(char*, size_t);
|
||||
int ipcconnect(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#define STRANS_TEST_ENGINE
|
||||
#include "../strans.c"
|
||||
#include "test.h"
|
||||
#include "../cutest/cutest.h"
|
||||
|
||||
extern Lang testvi;
|
||||
|
||||
Str mkstr(char*);
|
||||
int checkstr(struct ct*, char*, char*, Str*);
|
||||
Str shownpre(Im*);
|
||||
|
||||
static int typekeys(struct ct*, char*, Str*);
|
||||
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
#ifndef STRANS_TEST_H
|
||||
#define STRANS_TEST_H
|
||||
|
||||
#include "../cutest/cutest.h"
|
||||
|
||||
#ifndef STRANS_TEST_ENGINE
|
||||
#include "../dat.h"
|
||||
#include "../fn.h"
|
||||
#endif
|
||||
|
||||
extern Lang testvi;
|
||||
|
||||
@@ -72,5 +66,3 @@ void ipc_response_empty_and_preedit(struct ct*);
|
||||
void ipc_response_max_and_drain(struct ct*);
|
||||
void ipc_response_fragmented_and_truncated(struct ct*);
|
||||
void ipc_broken_peer_send(struct ct*);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user