Changed handling of incoming connections, so that we can send data
from the send hook without worrying about existence of socket buffers. Also, don't forget to copy peer addresses.
This commit is contained in:
parent
dfa9a53a66
commit
e1ddd99377
2 changed files with 10 additions and 5 deletions
|
@ -493,15 +493,21 @@ sk_passive_connected(sock *s, struct sockaddr *sa, int al, int type)
|
||||||
char *err;
|
char *err;
|
||||||
t->type = type;
|
t->type = type;
|
||||||
t->fd = fd;
|
t->fd = fd;
|
||||||
|
t->ttl = s->ttl;
|
||||||
|
t->tos = s->tos;
|
||||||
|
t->rbsize = s->rbsize;
|
||||||
|
t->tbsize = s->tbsize;
|
||||||
|
if (type == SK_TCP)
|
||||||
|
get_sockaddr((sockaddr *) sa, &t->daddr, &t->dport);
|
||||||
add_tail(&sock_list, &t->n);
|
add_tail(&sock_list, &t->n);
|
||||||
s->rx_hook(t, 0);
|
|
||||||
if (err = sk_setup(t))
|
if (err = sk_setup(t))
|
||||||
{
|
{
|
||||||
log(L_ERR "Incoming connection: %s: %m", err);
|
log(L_ERR "Incoming connection: %s: %m", err);
|
||||||
s->err_hook(s, errno);
|
rfree(t);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
sk_alloc_bufs(t);
|
sk_alloc_bufs(t);
|
||||||
|
s->rx_hook(t, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (errno != EINTR && errno != EAGAIN)
|
else if (errno != EINTR && errno != EAGAIN)
|
||||||
|
@ -682,7 +688,6 @@ sk_open_unix(sock *s, char *name)
|
||||||
ERR("bind");
|
ERR("bind");
|
||||||
if (listen(fd, 8))
|
if (listen(fd, 8))
|
||||||
ERR("listen");
|
ERR("listen");
|
||||||
sk_alloc_bufs(s);
|
|
||||||
add_tail(&sock_list, &s->n);
|
add_tail(&sock_list, &s->n);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,6 @@ cli_connect(sock *s, int size)
|
||||||
s->rx_hook = cli_rx;
|
s->rx_hook = cli_rx;
|
||||||
s->tx_hook = cli_tx;
|
s->tx_hook = cli_tx;
|
||||||
s->err_hook = cli_err;
|
s->err_hook = cli_err;
|
||||||
s->rbsize = 1024;
|
|
||||||
s->data = c = cli_new(s);
|
s->data = c = cli_new(s);
|
||||||
s->pool = c->pool; /* We need to have all the socket buffers allocated in the cli pool */
|
s->pool = c->pool; /* We need to have all the socket buffers allocated in the cli pool */
|
||||||
c->rx_pos = c->rx_buf;
|
c->rx_pos = c->rx_buf;
|
||||||
|
@ -266,6 +265,7 @@ cli_init_unix(void)
|
||||||
s = cli_sk = sk_new(cli_pool);
|
s = cli_sk = sk_new(cli_pool);
|
||||||
s->type = SK_UNIX_PASSIVE;
|
s->type = SK_UNIX_PASSIVE;
|
||||||
s->rx_hook = cli_connect;
|
s->rx_hook = cli_connect;
|
||||||
|
s->rbsize = 1024;
|
||||||
if (sk_open_unix(s, path_control_socket) < 0)
|
if (sk_open_unix(s, path_control_socket) < 0)
|
||||||
die("Unable to create control socket %s", path_control_socket);
|
die("Unable to create control socket %s", path_control_socket);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue