remove global buffer

This commit is contained in:
Olaf Rempel 2006-10-04 21:57:19 +02:00
parent 3bffc2c201
commit 38dd7db600
2 changed files with 12 additions and 13 deletions

View File

@ -48,17 +48,16 @@ static struct option opts[] = {
}; };
static int usock, msock; static int usock, msock;
static char *buf;
int usock_read_callback(int fd, void *privdata) 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) { if (len <= 0) {
close(fd); close(fd);
return -1; return -1;
} }
mcast_send(msock, buf, len); mcast_send(msock, privdata, len);
return 0; return 0;
} }
@ -70,25 +69,25 @@ int usock_accept_callback(int fd, void *privdata)
return 0; return 0;
} }
event_add_readfd(con, usock_read_callback, NULL); event_add_readfd(con, usock_read_callback, privdata);
return 0; return 0;
} }
int msock_read_callback(int fd, void *privdata) 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) { if (len <= 0) {
log_print(LOG_ERROR, "selector: multicast sock closed?"); log_print(LOG_ERROR, "selector: multicast sock closed?");
} else if (!strncmp(buf, "KEEPALIVE", 10)) { } else if (!strncmp(privdata, "KEEPALIVE", 10)) {
// nothing // nothing
} else if (!strncmp(buf, "DELETE ", 7)) { } else if (!strncmp(privdata, "DELETE ", 7)) {
log_print(LOG_DEBUG, "delete '%s'", buf +7); log_print(LOG_DEBUG, "delete '%s'", privdata +7);
//delete_file(buf +7); //delete_file(buf +7);
} else { } 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; return 0;
@ -153,7 +152,7 @@ int main(int argc, char *argv[])
log_print(LOG_EVERYTIME, "cachesyncd started (pid: %d)", getpid()); log_print(LOG_EVERYTIME, "cachesyncd started (pid: %d)", getpid());
buf = malloc(BUF_SIZE); char *buf = malloc(BUF_SIZE);
if (buf == NULL) { if (buf == NULL) {
log_print(LOG_ERROR, "selector: out of memory"); log_print(LOG_ERROR, "selector: out of memory");
return -1; return -1;
@ -167,8 +166,8 @@ int main(int argc, char *argv[])
if (msock < 0) if (msock < 0)
return -1; return -1;
event_add_readfd(usock, usock_accept_callback, NULL); event_add_readfd(usock, usock_accept_callback, buf);
event_add_readfd(msock, msock_read_callback, NULL); event_add_readfd(msock, msock_read_callback, buf);
struct timeval tv; struct timeval tv;
tv.tv_sec = 60; tv.tv_sec = 60;

View File

@ -96,7 +96,7 @@ int mcast_init()
return -1; return -1;
} }
char loop = 0; char loop = 1;
if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop))) { if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop))) {
log_print(LOG_WARN, "mcast_init: setsockopt(IP_MULTICAST_LOOP)"); log_print(LOG_WARN, "mcast_init: setsockopt(IP_MULTICAST_LOOP)");
close(sockfd); close(sockfd);