26 #include <sys/types.h> 30 #if defined(__MINGW32__) 34 #include <sys/socket.h> 35 #include <netinet/in.h> 36 #include <arpa/inet.h> 37 #endif // defined(__MINGW32__) 41 #endif // HAVE_CONFIG_H 49 #if defined(__MINGW32__) 50 #define SOCK_SHUTDOWN_OPTION SD_BOTH 51 #define SOCK_DATATYPE char * 54 #define SOCK_SHUTDOWN_OPTION SHUT_RDWR 55 #define SOCK_DATATYPE void * 56 #define SIZE_TYPE unsigned int 57 #endif // defined(__MINGW32__) 64 ipcmd->
socket = msgget(key, 0666 | creat);
76 ipcmd->
pid = 0x07fff & getpid();
84 ipcmd->
type = IPCMD_MSQ;
96 if (msgsnd(ipcmd->
socket, data, len, 0) < 0)
112 received = msgrcv(ipcmd->
socket, data, len, ipcmd->
pid, 0);
139 struct sockaddr_in addr;
145 if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0)
149 #endif // HAVE_LIBWS2_32 154 memset(&addr, 0,
sizeof(addr));
155 addr.sin_port = htons(port);
156 addr.sin_family = AF_INET;
158 ipcmd->
socket = socket(AF_INET, SOCK_STREAM, 0);
166 addr.sin_addr.s_addr = htonl(INADDR_ANY);
167 bind(ipcmd->
socket, (
struct sockaddr *)&addr,
sizeof(addr));
169 listen(ipcmd->
socket, YPSPUR_MAX_SOCKET);
174 addr.sin_addr.s_addr = inet_addr(host);
176 if (connect(ipcmd->
socket, (
struct sockaddr *)&addr,
sizeof(addr)) == -1)
183 ipcmd->
type = IPCMD_TCP;
201 if (ipcmd->
tcp_type == IPCMD_TCP_CLIENT)
211 if (ipcmd->
tcp_type == IPCMD_TCP_CLIENT)
225 struct sockaddr_in client;
242 FD_SET(ipcmd->
socket, &fds);
243 if (nfds < ipcmd->socket)
249 FD_SET(ipcmd->
clients[i], &fds);
250 if (nfds < ipcmd->clients[i])
256 if (!select(nfds, &fds, NULL, NULL, NULL))
261 if (!FD_ISSET(ipcmd->
socket, &fds))
265 if (ipcmd->
tcp_type == IPCMD_TCP_CLIENT)
270 addr_size =
sizeof(client);
271 sock = accept(ipcmd->
socket, (
struct sockaddr *)&client, &addr_size);
284 if (i == YPSPUR_MAX_SOCKET)
294 if (ipcmd->
tcp_type == IPCMD_TCP_CLIENT)
303 if (FD_ISSET(ipcmd->
clients[i], &fds))
313 if (ipcmd->
tcp_type == IPCMD_TCP_CLIENT)
339 msgctl(ipcmd->
socket, IPC_RMID, NULL);
345 #endif // HAVE_LIBWS2_32
void ipcmd_flush_msq(struct ipcmd_t *ipcmd)
enum ipcmd_t::ipcmd_type_t type
#define YPSPUR_MAX_SOCKET
void(* flush)(struct ipcmd_t *ipcmd)
int clients[YPSPUR_MAX_SOCKET]
int ipcmd_recv_msq(struct ipcmd_t *ipcmd, YPSpur_msg *data)
int ipcmd_open_tcp(struct ipcmd_t *ipcmd, char *host, int port)
int ipcmd_recv(struct ipcmd_t *ipcmd, YPSpur_msg *data)
int ipcmd_send_msq(struct ipcmd_t *ipcmd, YPSpur_msg *data)
int ipcmd_send_tcp(struct ipcmd_t *ipcmd, YPSpur_msg *data)
enum ipcmd_t::ipcmd_tcp_type_t tcp_type
int(* recv)(struct ipcmd_t *ipcmd, YPSpur_msg *data)
void yprintf(ParamOutputLv level, const char *format,...)
void ipcmd_flush(struct ipcmd_t *ipcmd)
int ipcmd_send(struct ipcmd_t *ipcmd, YPSpur_msg *data)
void ipcmd_close(struct ipcmd_t *ipcmd)
void ipcmd_flush_tcp(struct ipcmd_t *ipcmd)
int(* send)(struct ipcmd_t *ipcmd, YPSpur_msg *data)
int ipcmd_recv_tcp(struct ipcmd_t *ipcmd, YPSpur_msg *data)
#define SOCK_SHUTDOWN_OPTION
int ipcmd_open_msq(struct ipcmd_t *ipcmd, int key, int creat)