From 38dd7db6007acf978173479370585b72d3ccb7d3 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Wed, 4 Oct 2006 21:57:19 +0200 Subject: [PATCH] remove global buffer --- cachesyncd.c | 23 +++++++++++------------ multicast.c | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cachesyncd.c b/cachesyncd.c index 184cb34..96fb882 100644 --- a/cachesyncd.c +++ b/cachesyncd.c @@ -48,17 +48,16 @@ static struct option opts[] = { }; static int usock, msock; -static char *buf; int usock_read_callback(int fd, void *privdata) { - int len = read(fd, buf, BUF_SIZE); + int len = read(fd, privdata, BUF_SIZE); if (len <= 0) { close(fd); return -1; } - mcast_send(msock, buf, len); + mcast_send(msock, privdata, len); return 0; } @@ -70,25 +69,25 @@ int usock_accept_callback(int fd, void *privdata) return 0; } - event_add_readfd(con, usock_read_callback, NULL); + event_add_readfd(con, usock_read_callback, privdata); return 0; } int msock_read_callback(int fd, void *privdata) { - int len = read(fd, buf, BUF_SIZE); + int len = read(fd, privdata, BUF_SIZE); if (len <= 0) { log_print(LOG_ERROR, "selector: multicast sock closed?"); - } else if (!strncmp(buf, "KEEPALIVE", 10)) { + } else if (!strncmp(privdata, "KEEPALIVE", 10)) { // nothing - } else if (!strncmp(buf, "DELETE ", 7)) { - log_print(LOG_DEBUG, "delete '%s'", buf +7); + } else if (!strncmp(privdata, "DELETE ", 7)) { + log_print(LOG_DEBUG, "delete '%s'", privdata +7); //delete_file(buf +7); } else { - log_print(LOG_DEBUG, "recv unknown cmd via multicast: '%s'", buf); + log_print(LOG_DEBUG, "recv unknown cmd via multicast: '%s'", privdata); } return 0; @@ -153,7 +152,7 @@ int main(int argc, char *argv[]) log_print(LOG_EVERYTIME, "cachesyncd started (pid: %d)", getpid()); - buf = malloc(BUF_SIZE); + char *buf = malloc(BUF_SIZE); if (buf == NULL) { log_print(LOG_ERROR, "selector: out of memory"); return -1; @@ -167,8 +166,8 @@ int main(int argc, char *argv[]) if (msock < 0) return -1; - event_add_readfd(usock, usock_accept_callback, NULL); - event_add_readfd(msock, msock_read_callback, NULL); + event_add_readfd(usock, usock_accept_callback, buf); + event_add_readfd(msock, msock_read_callback, buf); struct timeval tv; tv.tv_sec = 60; diff --git a/multicast.c b/multicast.c index 227d094..c748b8e 100644 --- a/multicast.c +++ b/multicast.c @@ -96,7 +96,7 @@ int mcast_init() return -1; } - char loop = 0; + char loop = 1; if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop))) { log_print(LOG_WARN, "mcast_init: setsockopt(IP_MULTICAST_LOOP)"); close(sockfd);