summaryrefslogtreecommitdiff
path: root/src/core/network.c
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@irssi.org>2010-04-03 20:04:15 +0000
committerahf <ahf@dbcabf3a-b0e7-0310-adc4-f8d773084564>2010-04-03 20:04:15 +0000
commitdf1d7a78147805119f045036fc87c23e2c5c8094 (patch)
tree5e8570821f4bc103b006e9c634a1984a7f8967b8 /src/core/network.c
parentdd23f39f090f22d404dd15e40d411f9f8d65a38f (diff)
downloadirssi-df1d7a78147805119f045036fc87c23e2c5c8094.zip
glib iochannel fixes from exg.
git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5137 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core/network.c')
-rw-r--r--src/core/network.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/core/network.c b/src/core/network.c
index c2aa3de5..8f5d3e8d 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -42,11 +42,18 @@ union sockaddr_union {
# define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
#endif
+GIOChannel *g_io_channel_new(int handle)
+{
+ GIOChannel *chan;
#ifdef WIN32
-# define g_io_channel_new(handle) g_io_channel_win32_new_stream_socket(handle)
+ chan = g_io_channel_win32_new_socket(handle);
#else
-# define g_io_channel_new(handle) g_io_channel_unix_new(handle)
+ chan = g_io_channel_unix_new(handle);
#endif
+ g_io_channel_set_encoding(chan, NULL, NULL);
+ g_io_channel_set_buffered(chan, FALSE);
+ return chan;
+}
/* Cygwin need this, don't know others.. */
/*#define BLOCKING_SOCKETS 1*/
@@ -341,36 +348,32 @@ GIOChannel *net_accept(GIOChannel *handle, IPADDR *addr, int *port)
int net_receive(GIOChannel *handle, char *buf, int len)
{
gsize ret;
- int err;
+ GIOStatus status;
g_return_val_if_fail(handle != NULL, -1);
g_return_val_if_fail(buf != NULL, -1);
- err = g_io_channel_read(handle, buf, len, &ret);
- if (err == 0 && ret == 0)
+ status = g_io_channel_read_chars(handle, buf, len, &ret, NULL);
+ if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
return -1; /* disconnected */
- if (err == G_IO_ERROR_AGAIN || (err != 0 && errno == EINTR))
- return 0; /* no bytes received */
-
- return err == 0 ? (int)ret : -1;
+ return ret;
}
/* Transmit data, return number of bytes sent, -1 = error */
int net_transmit(GIOChannel *handle, const char *data, int len)
{
gsize ret;
- int err;
+ GIOStatus status;
g_return_val_if_fail(handle != NULL, -1);
g_return_val_if_fail(data != NULL, -1);
- err = g_io_channel_write(handle, (char *) data, len, &ret);
- if (err == G_IO_ERROR_AGAIN ||
- (err != 0 && (errno == EINTR || errno == EPIPE)))
- return 0;
+ status = g_io_channel_write_chars(handle, (char *) data, len, &ret, NULL);
+ if (status == G_IO_STATUS_ERROR)
+ return -1;
- return err == 0 ? (int)ret : -1;
+ return ret;
}
/* Get socket address/port */