Skip to content
Commits on Source (2)
......@@ -83,9 +83,10 @@ endif
# Let the user add some flags at the end
CFLAGS_APPEND =
LDFLAGS_APPEND =
CFLAGS = $(MWCFLAGS) $(CFLAGS_APPEND)
LDFLAGS = $(MWLDFLAGS)
LDFLAGS = $(MWLDFLAGS) $(LDFLAGS_APPEND)
CODE=$(wildcard *.c)
HDRS=$(wildcard *.h)
......
......@@ -60,5 +60,5 @@ void pop_cmd(char *string, int len, int *type)
free(free_me);
if (cmd_stack == NULL) last_cmd = &cmd_stack;
}
string[len]=0;
string[len - 1] = '\0';
}
#include <sys/epoll.h>
#include <string.h>
#include <socket.h>
#include "poll.h"
struct epoll_priv {
......@@ -12,15 +11,15 @@ struct epoll_priv ep = {
.pollfd = -1
};
int poll_addconn(ipc_connection_t *conn)
int poll_addconn(int fd, void *data)
{
struct epoll_event ev;
int ret;
memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLERR;
ev.data.ptr = conn;
ret = epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, conn->fd, &ev);
ev.data.ptr = data;
ret = epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, fd, &ev);
return ret;
}
......@@ -39,34 +38,25 @@ void poll_delete(int fd)
epoll_ctl(ep.pollfd, EPOLL_CTL_DEL, fd, &ev);
}
int poll_with_writes(ipc_connection_t *conn)
int poll_with_writes(int fd, void *data)
{
struct epoll_event ev;
memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLOUT | EPOLLERR;
ev.data.ptr = conn;
return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, conn->fd, &ev);
ev.data.ptr = data;
return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, fd, &ev);
}
int poll_without_writes(ipc_connection_t *conn)
int poll_without_writes(int fd, void *data)
{
int op = (data == NULL) ? EPOLL_CTL_ADD : EPOLL_CTL_MOD;
struct epoll_event ev;
memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLERR;
ev.data.ptr = conn;
return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, conn->fd, &ev);
}
int poll_fd_without_writes(int fd)
{
struct epoll_event ev;
memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLERR;
ev.data.ptr = NULL;
return epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, fd, &ev);
ev.data.ptr = data;
return epoll_ctl(ep.pollfd, op, fd, &ev);
}
int poll_wait(int timeout_millis, int (*callback)(poll_event_t *, int, void *), void *data)
......
......@@ -2,9 +2,9 @@
#include <sys/event.h>
#include <sys/time.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <socket.h>
#include "poll.h"
struct kq_priv {
......@@ -15,11 +15,11 @@ struct kq_priv kp = {
.kqd = -1
};
int poll_addconn(ipc_connection_t *conn)
int poll_addconn(int fd, void *data)
{
struct kevent ev;
EV_SET(&ev, conn->fd, EVFILT_READ, EV_ADD, 0, 0, conn);
EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, data);
return kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
}
......@@ -40,32 +40,20 @@ void poll_delete(int fd)
kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
}
int poll_with_writes(ipc_connection_t *conn)
int poll_with_writes(int fd, void *data)
{
struct kevent ev;
EV_SET(&ev, conn->fd, EVFILT_WRITE, EV_ADD, 0, 0, conn);
EV_SET(&ev, fd, EVFILT_WRITE, EV_ADD, 0, 0, data);
return kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
}
int poll_without_writes(ipc_connection_t *conn)
int poll_without_writes(int fd, void *data)
{
struct kevent ev;
int ret;
EV_SET(&ev, conn->fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
ret = kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
if (ret != 0 && errno != ENOENT)
return ret;
return 0;
}
int poll_fd_without_writes(int fd)
{
struct kevent ev;
int ret;
EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, NULL);
EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, data);
ret = kevent(kp.kqd, &ev, 1, NULL, 0, NULL);
if (ret != 0)
return ret;
......
......@@ -8,12 +8,11 @@ typedef struct {
void *data;
} poll_event_t;
extern int poll_addconn(ipc_connection_t *conn);
extern int poll_addconn(int fd, void *data);
extern int poll_init(void);
extern void poll_delete(int fd);
extern int poll_with_writes(ipc_connection_t *conn);
extern int poll_without_writes(ipc_connection_t *conn);
extern int poll_fd_without_writes(int fd);
extern int poll_with_writes(int fd, void *data);
extern int poll_without_writes(int fd, void *data);
extern int poll_wait(int timeout_millis, int (*callback)(poll_event_t *events, int nmemb, void *data), void *data);
#endif /* SERVER_POLL_H */
......@@ -4,6 +4,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <string.h>
#include <errno.h>
......
......@@ -82,7 +82,7 @@ ipc_connection_t * add_connection(int fd)
list_add_tail(&(new->list), &connection_list);
/* register interest in read events */
if (poll_addconn(new)) {
if (poll_addconn(new->fd, new)) {
fprintf(stderr, "Error adding new conn to poll: %s\n", strerror(errno));
}
......@@ -176,9 +176,8 @@ static int mainsock_event_cb(poll_event_t *events, int nmemb, void *data)
/* connections that went bad */
if (c->fd != -1 && c->state == IPCSTATE_ERROR) {
drop_connection(c);
}
} else if (c->state == IPCSTATE_PURGE && list_empty(&(c->outq))) {
/* connections with a soft close */
if (c->state == IPCSTATE_PURGE && list_empty(&(c->outq))) {
drop_connection(c);
}
}
......@@ -192,7 +191,7 @@ void watch_mainsock(int mainsock)
struct timeval last;
gettimeofday(&last, NULL);
if (poll_fd_without_writes(mainsock)) {
if (poll_without_writes(mainsock, NULL)) {
fprintf(stderr, "Error adding mainsock: %s\n", strerror(errno));
return;
}
......@@ -214,7 +213,7 @@ void write_socket(ipc_connection_t * conn)
if (list_empty(&conn->outq)) {
/* tx queue is empty, stop write events */
if (poll_without_writes(conn))
if (poll_without_writes(conn->fd, conn))
fprintf(stderr, "Error updating poll fd=%d: %s\n",
conn->fd, strerror(errno));
return;
......@@ -612,7 +611,7 @@ void msg_attach(ipc_message_t *msg, ipc_connection_t *conn)
/* nothing was queueed, switch on write notifications */
if (wasempty)
poll_with_writes(conn);
poll_with_writes(conn->fd, conn);
}
/* test if the user is gagged and apply the filter
......
......@@ -134,7 +134,7 @@ int ipcconn_connect(const char * target)
struct addrinfo *list;
int fd;
char *host = alloca(strlen(target));
char *host = alloca(strlen(target) + 1);
char *port = NULL;
strcpy(host, target);
......