summaryrefslogtreecommitdiff
path: root/gweb
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-11-08 05:00:42 +0900
committerMarcel Holtmann <marcel@holtmann.org>2010-11-08 05:00:42 +0900
commit49c08fb981ef3ea590fe626334e25e13d7be6e51 (patch)
tree9fe5115311e362e1f301744ef559cb4df8e1e7cc /gweb
parent32cca861e8b61d2e291b996206fcfbda9afdcce2 (diff)
downloadconnman-49c08fb981ef3ea590fe626334e25e13d7be6e51.tar.gz
connman-49c08fb981ef3ea590fe626334e25e13d7be6e51.tar.bz2
connman-49c08fb981ef3ea590fe626334e25e13d7be6e51.zip
Read IO flags first before setting channel to non-blocking
Diffstat (limited to 'gweb')
-rw-r--r--gweb/gweb.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/gweb/gweb.c b/gweb/gweb.c
index 04bc9bd0..5403d363 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -719,6 +719,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
static int connect_session_transport(struct web_session *session)
{
+ GIOFlags flags;
struct sockaddr_in sin;
int sk;
@@ -726,11 +727,6 @@ static int connect_session_transport(struct web_session *session)
if (sk < 0)
return -EIO;
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(session->port);
- sin.sin_addr.s_addr = inet_addr(session->address);
-
if (session->flags & SESSION_FLAG_USE_TLS)
session->transport_channel = g_io_channel_gnutls_new(sk);
else
@@ -741,13 +737,20 @@ static int connect_session_transport(struct web_session *session)
return -ENOMEM;
}
+ flags = g_io_channel_get_flags(session->transport_channel);
g_io_channel_set_flags(session->transport_channel,
- G_IO_FLAG_NONBLOCK, NULL);
+ flags | G_IO_FLAG_NONBLOCK, NULL);
+
g_io_channel_set_encoding(session->transport_channel, NULL, NULL);
g_io_channel_set_buffered(session->transport_channel, FALSE);
g_io_channel_set_close_on_unref(session->transport_channel, TRUE);
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(session->port);
+ sin.sin_addr.s_addr = inet_addr(session->address);
+
if (connect(sk, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
if (errno != EINPROGRESS) {
close(sk);