Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rofl0r/proxychains-ng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrofl0r <retnyg@gmx.net>2017-05-04 03:31:56 +0300
committerrofl0r <retnyg@gmx.net>2017-05-04 05:04:21 +0300
commitcbddf15b19191257de302687df558adfae10aeb5 (patch)
treef62d2254e1ef607b9f99c0ede11fe8d2e8e065c3
parentbb3df1e4409190da2627d8a3b5bdd5e02d246f28 (diff)
properly handle non-blocking mode of socketnonblock
addressing #171
-rw-r--r--src/core.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/core.c b/src/core.c
index 827ee54..72c84b6 100644
--- a/src/core.c
+++ b/src/core.c
@@ -154,10 +154,19 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
pfd[0].fd = sock;
pfd[0].events = POLLOUT;
- fcntl(sock, F_SETFL, O_NONBLOCK);
+ int flags = fcntl(sock, F_GETFL, 0);
+ /* put socket temporarily into nonblocking mode so we can enforce
+ * the timeout. */
+ if(!(flags & O_NONBLOCK))
+ fcntl(sock, F_SETFL, flags | O_NONBLOCK);
ret = true_connect(sock, addr, len);
PDEBUG("\nconnect ret=%d\n", ret);
-
+
+ /* if the socket was already non-blocking, we assume the app takes
+ * care of handling the timeouts itself. */
+ if(flags & O_NONBLOCK)
+ return ret;
+
if(ret == -1 && errno == EINPROGRESS) {
ret = poll_retry(pfd, 1, tcp_connect_time_out);
PDEBUG("\npoll ret=%d\n", ret);
@@ -181,7 +190,7 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
ret = -1;
}
- fcntl(sock, F_SETFL, !O_NONBLOCK);
+ fcntl(sock, F_SETFL, flags);
return ret;
}