diff options
author | Christian Pointner <equinox@spreadspace.org> | 2010-11-27 05:39:07 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2010-11-27 05:39:07 +0000 |
commit | df849a6ae44fe40ac67a649cccbdb5af5af1bf23 (patch) | |
tree | 1df1379ba06a91b47a689ffc18edb85fd6781365 /src/tcpproxy.c | |
parent | listening on tcp sockets works now (diff) |
added REUSEADDR to listen sockets
added accept handler
git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@9 e61f0598-a718-4e21-a8f0-0aadfa62ad6b
Diffstat (limited to 'src/tcpproxy.c')
-rw-r--r-- | src/tcpproxy.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/tcpproxy.c b/src/tcpproxy.c index d55277e..d82b057 100644 --- a/src/tcpproxy.c +++ b/src/tcpproxy.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <errno.h> #include <string.h> +#include <sys/select.h> #include "datatypes.h" #include "options.h" @@ -38,7 +39,7 @@ #include "listener.h" -int main_loop(options_t* opt) +int main_loop(options_t* opt, listeners_t* listeners) { log_printf(INFO, "entering main loop"); @@ -47,14 +48,13 @@ int main_loop(options_t* opt) if(sig_fd < 0) return_value -1; - fd_set readfds, readyfds; - FD_ZERO(&readfds); - FD_SET(sig_fd, &readfds); - int nfds = (nfds < sig_fd) ? sig_fd : nfds; - while(!return_value) { - memcpy(&readyfds, &readfds, sizeof(readyfds)); - int ret = select(nfds + 1, &readyfds, NULL, NULL, NULL); + fd_set readfds; + FD_ZERO(&readfds); + FD_SET(sig_fd, &readfds); + int nfds = sig_fd; + listener_read_fds(listeners, &readfds, &nfds); + int ret = select(nfds + 1, &readfds, NULL, NULL, NULL); if(ret == -1 && errno != EINTR) { log_printf(ERROR, "select returned with error: %s", strerror(errno)); return_value = -1; @@ -63,12 +63,15 @@ int main_loop(options_t* opt) if(!ret || ret == -1) continue; - if(FD_ISSET(sig_fd, &readyfds)) { + if(FD_ISSET(sig_fd, &readfds)) { if(signal_handle()) { return_value = 1; break; } } + + return_value = listener_handle_accept(listeners, &readfds); + if(return_value) break; } signal_stop(); @@ -182,7 +185,7 @@ int main(int argc, char* argv[]) fclose(pid_file); } - ret = main_loop(&opt); + ret = main_loop(&opt, &listeners); listener_clear(&listeners); options_clear(&opt); |