summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-06-01 11:50:43 +0200
committerSebastien Helleu <flashcode@flashtux.org>2012-06-01 11:50:43 +0200
commit3b9e94c2344fdfdb38d8ccc98bca163d022349d9 (patch)
treebe6a35a8aa1ff6ca3c162a8155c887315d890cd9 /src
parentf56a936b220afb8daeeb6d26dc3da1dff84bd817 (diff)
downloadweechat-3b9e94c2344fdfdb38d8ccc98bca163d022349d9.zip
xfer: set O_NONBLOCK flag on socket using flags read
Diffstat (limited to 'src')
-rw-r--r--src/plugins/xfer/xfer-network.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c
index 93f9f5393..9580bf073 100644
--- a/src/plugins/xfer/xfer-network.c
+++ b/src/plugins/xfer/xfer-network.c
@@ -319,7 +319,7 @@ int
xfer_network_fd_cb (void *arg_xfer, int fd)
{
struct t_xfer *xfer;
- int sock;
+ int sock, flags;
struct sockaddr_in addr;
socklen_t length;
@@ -351,7 +351,10 @@ xfer_network_fd_cb (void *arg_xfer, int fd)
return WEECHAT_RC_OK;
}
xfer->sock = sock;
- if (fcntl (xfer->sock, F_SETFL, O_NONBLOCK) == -1)
+ flags = fcntl (xfer->sock, F_GETFL);
+ if (flags == -1)
+ flags = 0;
+ if (fcntl (xfer->sock, F_SETFL, flags | O_NONBLOCK) == -1)
{
weechat_printf (NULL,
_("%s%s: unable to set option \"nonblock\" "
@@ -390,7 +393,10 @@ xfer_network_fd_cb (void *arg_xfer, int fd)
return WEECHAT_RC_OK;
}
xfer->sock = sock;
- if (fcntl (xfer->sock, F_SETFL, O_NONBLOCK) == -1)
+ flags = fcntl (xfer->sock, F_GETFL);
+ if (flags == -1)
+ flags = 0;
+ if (fcntl (xfer->sock, F_SETFL, flags | O_NONBLOCK) == -1)
{
weechat_printf (NULL,
_("%s%s: unable to set option \"nonblock\" "
@@ -450,6 +456,8 @@ xfer_network_timer_cb (void *arg_xfer, int remaining_calls)
int
xfer_network_connect (struct t_xfer *xfer)
{
+ int flags;
+
if (xfer->type == XFER_TYPE_CHAT_SEND)
xfer->status = XFER_STATUS_WAITING;
else
@@ -465,11 +473,14 @@ xfer_network_connect (struct t_xfer *xfer)
if (XFER_IS_SEND(xfer->type))
{
/* listen to socket */
- if (fcntl (xfer->sock, F_SETFL, O_NONBLOCK) == -1)
+ flags = fcntl (xfer->sock, F_GETFL);
+ if (flags == -1)
+ flags = 0;
+ if (fcntl (xfer->sock, F_SETFL, flags | O_NONBLOCK) == -1)
return 0;
if (listen (xfer->sock, 1) == -1)
return 0;
- if (fcntl (xfer->sock, F_SETFL, 0) == -1)
+ if (fcntl (xfer->sock, F_SETFL, flags) == -1)
return 0;
xfer->hook_fd = weechat_hook_fd (xfer->sock,
@@ -490,7 +501,10 @@ xfer_network_connect (struct t_xfer *xfer)
/* for chat receiving, connect to listening host */
if (xfer->type == XFER_TYPE_CHAT_RECV)
{
- if (fcntl (xfer->sock, F_SETFL, O_NONBLOCK) == -1)
+ flags = fcntl (xfer->sock, F_GETFL);
+ if (flags == -1)
+ flags = 0;
+ if (fcntl (xfer->sock, F_SETFL, flags | O_NONBLOCK) == -1)
return 0;
weechat_network_connect_to (xfer->proxy, xfer->sock, xfer->address,
xfer->port);