From 6f451f094d1bd2282c9f7354fe81a554b863a74c Mon Sep 17 00:00:00 2001 From: Adam Hamsik Date: Fri, 25 Feb 2011 16:18:29 +0200 Subject: [PATCH] Add proxychains singal fixes, refactor code while I was there it was pretty horrid :/. --- proxychains/core.c | 64 +++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/proxychains/core.c b/proxychains/core.c index 8879859..0ab1a83 100644 --- a/proxychains/core.c +++ b/proxychains/core.c @@ -43,6 +43,33 @@ extern int proxychains_quiet_mode; static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout) +{ + int ret; + int time_remain = timeout; + int time_elapsed = 0; + + struct timeval start_time; + struct timeval tv; + + gettimeofday(&start_time, NULL); + + do + { + //printf("Retry %d\n", time_remain); + ret = poll(fds, nfsd, time_remain); + gettimeofday(&tv, NULL); + time_elapsed = ((tv.tv_sec - start_time.tv_sec) * 1000 + (tv.tv_usec - start_time.tv_usec) / 1000); + //printf("Time elapsed %d\n", time_elapsed); + time_remain = timeout - time_elapsed; + } + while (ret == -1 && errno == EINTR && time_remain > 0); + //if (ret == -1) + //printf("Return %d %d %s\n", ret, errno, strerror(errno)); + return ret; +} + + static void encode_base_64(char* src,char* dest,int max_len) { int n,l,i; @@ -123,7 +150,7 @@ static int read_line(int fd, char *buff, size_t size) for(i=0;i