fix accept logic

git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4600 77e5149b-7576-45b1-b177-96237e5ba77b
0.95
Török Edvin 17 years ago
parent 0dc9d54110
commit 4f5a740806
  1. 4
      ChangeLog
  2. 3
      clamd/others.c
  3. 8
      clamd/server-th.c

@ -1,3 +1,7 @@
Fri Jan 9 21:11:54 EET 2009 (edwin)
------------------------------------
* clamd/others.c, clamd/server-th.c: fix accept logic
Fri Jan 9 21:04:57 EET 2009 (edwin) Fri Jan 9 21:04:57 EET 2009 (edwin)
------------------------------------ ------------------------------------
* clamd/others.c, clamd/server-th.c, clamd/server.h, * clamd/others.c, clamd/server-th.c, clamd/server.h,

@ -478,6 +478,8 @@ static void cleanup_fds(struct fd_data *data)
static int read_fd_data(struct fd_buf *buf) static int read_fd_data(struct fd_buf *buf)
{ {
ssize_t n; ssize_t n;
buf->got_newdata=1;
if (!buf->buffer) /* listen-only socket */ if (!buf->buffer) /* listen-only socket */
return 0; return 0;
/* Read the pending packet, it may contain more than one command, but /* Read the pending packet, it may contain more than one command, but
@ -488,7 +490,6 @@ static int read_fd_data(struct fd_buf *buf)
if (n < 0) if (n < 0)
return -1; return -1;
buf->off += n; buf->off += n;
buf->got_newdata=1;
return n; return n;
} }

@ -660,6 +660,8 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un
for (i=0;i < fds.nfds && new_sd >= 0; i++) { for (i=0;i < fds.nfds && new_sd >= 0; i++) {
struct fd_buf *buf = &fds.buf[i]; struct fd_buf *buf = &fds.buf[i];
if (!buf->got_newdata)
continue;
if (!buf->buffer) { if (!buf->buffer) {
/* listen only socket */ /* listen only socket */
new_sd = accept(fds.buf[i].fd, NULL, NULL); new_sd = accept(fds.buf[i].fd, NULL, NULL);
@ -686,7 +688,7 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un
#endif #endif
continue; continue;
} }
} else if (buf->fd != -1 && buf->got_newdata) { } else if (buf->fd != -1) {
const char *cmd; const char *cmd;
size_t cmdlen = 0; size_t cmdlen = 0;
size_t pos = 0; size_t pos = 0;
@ -695,6 +697,7 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un
/* Parse & dispatch commands */ /* Parse & dispatch commands */
while ((cmd = get_cmd(buf, pos, &cmdlen)) != NULL) { while ((cmd = get_cmd(buf, pos, &cmdlen)) != NULL) {
printf("%s\n",cmd);
client_conn = (client_conn_t *) malloc(sizeof(struct client_conn_tag)); client_conn = (client_conn_t *) malloc(sizeof(struct client_conn_tag));
if(client_conn) { if(client_conn) {
client_conn->sd = buf->fd; client_conn->sd = buf->fd;
@ -744,7 +747,8 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un
if (pos < buf->off) { if (pos < buf->off) {
memmove (buf->buffer, &buf->buffer[pos], buf->off - pos); memmove (buf->buffer, &buf->buffer[pos], buf->off - pos);
buf->off -= pos; buf->off -= pos;
} } else
buf->off = 0;
} }
} }

Loading…
Cancel
Save