mirror of
https://github.com/yrutschle/sslh.git
synced 2025-06-06 10:23:14 +03:00
abstract listening sockets so we have protocol information alongside the socket -- echosrv and sslh-select
This commit is contained in:
parent
c12f7a1ade
commit
f3230b4a94
@ -64,7 +64,7 @@ void start_echo(int fd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_loop(int listen_sockets[], int num_addr_listen)
|
void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen)
|
||||||
{
|
{
|
||||||
int in_socket, i;
|
int in_socket, i;
|
||||||
|
|
||||||
@ -72,12 +72,12 @@ void main_loop(int listen_sockets[], int num_addr_listen)
|
|||||||
if (!fork()) {
|
if (!fork()) {
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
in_socket = accept(listen_sockets[i], 0, 0);
|
in_socket = accept(listen_sockets[i].socketfd, 0, 0);
|
||||||
if (cfg.verbose) fprintf(stderr, "accepted fd %d\n", in_socket);
|
if (cfg.verbose) fprintf(stderr, "accepted fd %d\n", in_socket);
|
||||||
|
|
||||||
if (!fork())
|
if (!fork())
|
||||||
{
|
{
|
||||||
close(listen_sockets[i]);
|
close(listen_sockets[i].socketfd);
|
||||||
start_echo(in_socket);
|
start_echo(in_socket);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ int main(int argc, char *argv[])
|
|||||||
extern int optind;
|
extern int optind;
|
||||||
int num_addr_listen;
|
int num_addr_listen;
|
||||||
|
|
||||||
int *listen_sockets;
|
struct listen_endpoint *listen_sockets;
|
||||||
|
|
||||||
memset(&cfg, 0, sizeof(cfg));
|
memset(&cfg, 0, sizeof(cfg));
|
||||||
if (sslhcfg_cl_parse(argc, argv, &cfg))
|
if (sslhcfg_cl_parse(argc, argv, &cfg))
|
||||||
|
@ -296,7 +296,7 @@ int is_fd_active(int fd, fd_set* set)
|
|||||||
* That way, each pair of file descriptor (read from one, write to the other)
|
* That way, each pair of file descriptor (read from one, write to the other)
|
||||||
* is monitored either for read or for write, but never for both.
|
* is monitored either for read or for write, but never for both.
|
||||||
*/
|
*/
|
||||||
void main_loop(int listen_sockets[], int num_addr_listen)
|
void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen)
|
||||||
{
|
{
|
||||||
fd_set fds_r, fds_w; /* reference fd sets (used to init the next 2) */
|
fd_set fds_r, fds_w; /* reference fd sets (used to init the next 2) */
|
||||||
fd_set readfds, writefds; /* working read and write fd sets */
|
fd_set readfds, writefds; /* working read and write fd sets */
|
||||||
@ -313,10 +313,10 @@ void main_loop(int listen_sockets[], int num_addr_listen)
|
|||||||
FD_ZERO(&fds_w);
|
FD_ZERO(&fds_w);
|
||||||
|
|
||||||
for (i = 0; i < num_addr_listen; i++) {
|
for (i = 0; i < num_addr_listen; i++) {
|
||||||
FD_SET(listen_sockets[i], &fds_r);
|
FD_SET(listen_sockets[i].socketfd, &fds_r);
|
||||||
set_nonblock(listen_sockets[i]);
|
set_nonblock(listen_sockets[i].socketfd);
|
||||||
}
|
}
|
||||||
max_fd = listen_sockets[num_addr_listen-1] + 1;
|
max_fd = listen_sockets[num_addr_listen-1].socketfd + 1;
|
||||||
|
|
||||||
cnx_num_alloc = getpagesize() / sizeof(struct connection);
|
cnx_num_alloc = getpagesize() / sizeof(struct connection);
|
||||||
|
|
||||||
@ -343,8 +343,8 @@ void main_loop(int listen_sockets[], int num_addr_listen)
|
|||||||
|
|
||||||
/* Check main socket for new connections */
|
/* Check main socket for new connections */
|
||||||
for (i = 0; i < num_addr_listen; i++) {
|
for (i = 0; i < num_addr_listen; i++) {
|
||||||
if (FD_ISSET(listen_sockets[i], &readfds)) {
|
if (FD_ISSET(listen_sockets[i].socketfd, &readfds)) {
|
||||||
in_socket = accept_new_connection(listen_sockets[i], &cnx, &num_cnx);
|
in_socket = accept_new_connection(listen_sockets[i].socketfd, &cnx, &num_cnx);
|
||||||
if (in_socket > 0) {
|
if (in_socket > 0) {
|
||||||
num_probing++;
|
num_probing++;
|
||||||
FD_SET(in_socket, &fds_r);
|
FD_SET(in_socket, &fds_r);
|
||||||
@ -423,7 +423,7 @@ void main_loop(int listen_sockets[], int num_addr_listen)
|
|||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case 0: /* child */
|
case 0: /* child */
|
||||||
for (i = 0; i < num_addr_listen; i++)
|
for (i = 0; i < num_addr_listen; i++)
|
||||||
close(listen_sockets[i]);
|
close(listen_sockets[i].socketfd);
|
||||||
for (i = 0; i < num_cnx; i++)
|
for (i = 0; i < num_cnx; i++)
|
||||||
if (&cnx[i] != pcnx_i)
|
if (&cnx[i] != pcnx_i)
|
||||||
for (j = 0; j < 2; j++)
|
for (j = 0; j < 2; j++)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user