kanoi 10 years ago
parent
commit
8e559ee48e
  1. 9
      src/ckpool.c
  2. 1
      src/ckpool.h
  3. 2
      src/generator.c
  4. 8
      src/libckpool.c

9
src/ckpool.c

@ -367,11 +367,11 @@ void empty_buffer(connsock_t *cs)
* of the buffer for use on the next receive. */
int read_socket_line(connsock_t *cs, int timeout)
{
int fd = cs->fd, ret = -1;
char *eom = NULL;
size_t buflen;
int ret = -1;
if (unlikely(cs->fd < 0))
if (unlikely(fd < 0))
goto out;
if (unlikely(!cs->buf))
@ -388,7 +388,7 @@ int read_socket_line(connsock_t *cs, int timeout)
while (42) {
char readbuf[PAGESIZE] = {};
ret = wait_read_select(cs->fd, eom ? 0 : timeout);
ret = wait_read_select(fd, eom ? 0 : timeout);
if (eom && !ret)
break;
if (ret < 1) {
@ -398,7 +398,7 @@ int read_socket_line(connsock_t *cs, int timeout)
LOGERR("Select failed in read_socket_line");
goto out;
}
ret = recv(cs->fd, readbuf, PAGESIZE - 4, 0);
ret = recv(fd, readbuf, PAGESIZE - 4, 0);
if (ret < 1) {
LOGERR("Failed to recv in read_socket_line");
ret = -1;
@ -423,6 +423,7 @@ int read_socket_line(connsock_t *cs, int timeout)
*eom = '\0';
out:
if (ret < 0) {
empty_buffer(cs);
dealloc(cs->buf);
Close(cs->fd);
}

1
src/ckpool.h

@ -188,6 +188,7 @@ bool ckmsgq_empty(ckmsgq_t *ckmsgq);
ckpool_t *global_ckp;
bool ping_main(ckpool_t *ckp);
void empty_buffer(connsock_t *cs);
int read_socket_line(connsock_t *cs, int timeout);
bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line);
#define send_proc(pi, msg) _send_proc(pi, msg, __FILE__, __func__, __LINE__)

2
src/generator.c

@ -225,6 +225,7 @@ static void kill_server(server_instance_t *si)
LOGNOTICE("Killing server");
cs = &si->cs;
Close(cs->fd);
empty_buffer(cs);
dealloc(cs->url);
dealloc(cs->port);
dealloc(cs->auth);
@ -1428,6 +1429,7 @@ static void kill_proxy(ckpool_t *ckp, proxy_instance_t *proxi)
LOGNOTICE("Killing proxy");
cs = proxi->cs;
Close(cs->fd);
empty_buffer(cs);
/* All our notify data is invalid if we reconnect so discard them */
mutex_lock(&proxi->notify_lock);

8
src/libckpool.c

@ -711,6 +711,8 @@ int wait_read_select(int sockd, int timeout)
{
struct pollfd sfd;
if (unlikely(sockd < 0))
return -1;
sfd.fd = sockd;
sfd.events = POLLIN;
sfd.revents = 0;
@ -726,6 +728,8 @@ int read_length(int sockd, void *buf, int len)
LOGWARNING("Invalid read length of %d requested in read_length", len);
return -1;
}
if (unlikely(sockd < 0))
return -1;
while (len) {
ret = recv(sockd, buf + ofs, len, MSG_WAITALL);
if (unlikely(ret < 1))
@ -784,6 +788,8 @@ int wait_write_select(int sockd, int timeout)
{
struct pollfd sfd;
if (unlikely(sockd < 0))
return -1;
sfd.fd = sockd;
sfd.events = POLLOUT;
sfd.revents = 0;
@ -799,6 +805,8 @@ int write_length(int sockd, const void *buf, int len)
LOGWARNING("Invalid write length of %d requested in write_length", len);
return -1;
}
if (unlikely(sockd < 0))
return -1;
while (len) {
ret = write(sockd, buf + ofs, len);
if (unlikely(ret < 0))

Loading…
Cancel
Save