diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-08-25 11:28:28 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-08-25 11:28:28 +0800 |
commit | d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619 (patch) | |
tree | 49bc1d1bb568fc046d4f6e9b540f9100e2d2eaab | |
parent | fce991c7ba4a2ebed2658352b6bd4e677773c493 (diff) | |
download | pttbbs-d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619.tar pttbbs-d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619.tar.gz pttbbs-d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619.tar.bz2 pttbbs-d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619.tar.lz pttbbs-d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619.tar.xz pttbbs-d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619.tar.zst pttbbs-d0e1cea0bea2d0b292f1a89b8a0aba8d7cee2619.zip |
* code refine: reduce potential fd flag changes in tonnectex
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4771 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | common/sys/net.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/common/sys/net.c b/common/sys/net.c index 8166ed1d..c8ae9e50 100644 --- a/common/sys/net.c +++ b/common/sys/net.c @@ -158,7 +158,7 @@ int toconnectex(const char *addr, int timeout) else { char buf[64], *port; struct sockaddr_in serv_name; - int oflags = 0; + int was_block = 1; if( (sock = socket(PF_INET, SOCK_STREAM, 0)) < 0 ){ perror("socket"); @@ -168,7 +168,8 @@ int toconnectex(const char *addr, int timeout) if (timeout > 0) { // set to non-block to allow timeout - oflags = fcntl(sock, F_GETFL, NULL); + int oflags = fcntl(sock, F_GETFL, NULL); + was_block = !(oflags & O_NONBLOCK); fcntl(sock, F_SETFL, oflags | O_NONBLOCK); } @@ -213,6 +214,11 @@ int toconnectex(const char *addr, int timeout) if (timeout > 0) { // restore flags + int oflags = fcntl(sock, F_GETFL, NULL); + if (was_block) + oflags &= ~O_NONBLOCK; + else + oflags |= O_NONBLOCK; fcntl(sock, F_SETFL, oflags); } } |