Browse Source

Enable keepalive and nodelay for remote clients and remove mistaken setting of noblock, and add reuseaddr option to sockets

master
Con Kolivas 11 years ago
parent
commit
9db3db3b8b
  1. 4
      src/connector.c
  2. 1
      src/generator.c
  3. 5
      src/libckpool.c

4
src/connector.c

@ -66,6 +66,7 @@ retry:
LOGERR("Failed to accept on socket %d in acceptor", ci->serverfd);
goto out;
}
keep_sockalive(fd);
LOGINFO("Connected new client %d on socket %d", ci->nfds, fd);
@ -333,6 +334,7 @@ int connector(proc_instance_t *pi)
ckpool_t *ckp = pi->ckp;
int sockd, ret = 0;
conn_instance_t ci;
const int on = 1;
int tries = 0;
if (ckp->serverurl) {
@ -365,6 +367,7 @@ int connector(proc_instance_t *pi)
ret = 1;
goto out;
}
setsockopt(sockd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
@ -391,6 +394,7 @@ int connector(proc_instance_t *pi)
close(sockd);
goto out;
}
cklock_init(&ci.lock);
memset(&ci, 0, sizeof(ci));
ci.pi = pi;

1
src/generator.c

@ -125,7 +125,6 @@ int generator(proc_instance_t *pi)
goto out;
}
keep_sockalive(cs.fd);
block_socket(cs.fd);
/* Test we can connect, authorise and get a block template */
if (!gen_gbtbase(&cs, &gbt)) {

5
src/libckpool.c

@ -329,9 +329,6 @@ void keep_sockalive(int fd)
const int tcp_one = 1;
const int tcp_keepidle = 45;
const int tcp_keepintvl = 30;
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, O_NONBLOCK | flags);
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const void *)&tcp_one, sizeof(tcp_one));
setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one));
@ -358,6 +355,7 @@ int bind_socket(char *url, char *port)
{
struct addrinfo servinfobase, *servinfo, hints, *p;
int ret, sockd = -1;
const int on = 1;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
@ -377,6 +375,7 @@ int bind_socket(char *url, char *port)
LOGWARNING("Failed to open socket for %s:%s", url, port);
goto out;
}
setsockopt(sockd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
ret = bind(sockd, p->ai_addr, p->ai_addrlen);
if (ret < 0) {
LOGWARNING("Failed to bind socket for %s:%s", url, port);

Loading…
Cancel
Save