diff options
author | Alexander Færøy <ahf@irssi.org> | 2010-04-03 20:04:15 +0000 |
---|---|---|
committer | ahf <ahf@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2010-04-03 20:04:15 +0000 |
commit | df1d7a78147805119f045036fc87c23e2c5c8094 (patch) | |
tree | 5e8570821f4bc103b006e9c634a1984a7f8967b8 | |
parent | dd23f39f090f22d404dd15e40d411f9f8d65a38f (diff) | |
download | irssi-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
-rw-r--r-- | src/core/net-nonblock.c | 27 | ||||
-rw-r--r-- | src/core/network.c | 33 | ||||
-rw-r--r-- | src/core/network.h | 2 | ||||
-rw-r--r-- | src/core/servers.c | 4 | ||||
-rw-r--r-- | src/core/session.c | 3 | ||||
-rw-r--r-- | src/fe-common/core/fe-exec.c | 4 |
6 files changed, 39 insertions, 34 deletions
diff --git a/src/core/net-nonblock.c b/src/core/net-nonblock.c index 3eeef228..461b2b87 100644 --- a/src/core/net-nonblock.c +++ b/src/core/net-nonblock.c @@ -35,38 +35,37 @@ typedef struct { int tag; } SIMPLE_THREAD_REC; -#define is_fatal_error(err) \ - (err != 0 && err != G_IO_ERROR_AGAIN && errno != EINTR) - static int g_io_channel_write_block(GIOChannel *channel, void *data, int len) { gsize ret; - int err, sent; + int sent; + GIOStatus status; sent = 0; do { - err = g_io_channel_write(channel, (char *) data + sent, - len-sent, &ret); + status = g_io_channel_write_chars(channel, (char *) data + sent, + len-sent, &ret, NULL); sent += ret; - } while (sent < len && !is_fatal_error(err)); + } while (sent < len && status != G_IO_STATUS_ERROR); - return err != 0 ? -1 : 0; + return sent < len ? -1 : 0; } static int g_io_channel_read_block(GIOChannel *channel, void *data, int len) { time_t maxwait; gsize ret; - int err, received; + int received; + GIOStatus status; maxwait = time(NULL)+2; received = 0; do { - err = g_io_channel_read(channel, (char *) data + received, - len-received, &ret); + status = g_io_channel_read_chars(channel, (char *) data + received, + len-received, &ret, NULL); received += ret; } while (received < len && time(NULL) < maxwait && - (ret != 0 || !is_fatal_error(err))); + status != G_IO_STATUS_ERROR && status != G_IO_STATUS_EOF); return received < len ? -1 : 0; } @@ -282,8 +281,8 @@ int net_connect_nonblock(const char *server, int port, const IPADDR *my_ip, } rec->func = func; rec->data = data; - rec->pipes[0] = g_io_channel_unix_new(fd[0]); - rec->pipes[1] = g_io_channel_unix_new(fd[1]); + rec->pipes[0] = g_io_channel_new(fd[0]); + rec->pipes[1] = g_io_channel_new(fd[1]); /* start nonblocking host name lookup */ net_gethostbyname_nonblock(server, rec->pipes[1], 0); 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 */ diff --git a/src/core/network.h b/src/core/network.h index 8583724c..142a1793 100644 --- a/src/core/network.h +++ b/src/core/network.h @@ -41,6 +41,8 @@ struct _IPADDR { extern IPADDR ip4_any; +GIOChannel *g_io_channel_new(int handle); + /* returns 1 if IPADDRs are the same */ int net_ip_compare(IPADDR *ip1, IPADDR *ip2); diff --git a/src/core/servers.c b/src/core/servers.c index 017a2036..d4827b61 100644 --- a/src/core/servers.c +++ b/src/core/servers.c @@ -419,8 +419,8 @@ int server_start_connect(SERVER_REC *server) return FALSE; } - server->connect_pipe[0] = g_io_channel_unix_new(fd[0]); - server->connect_pipe[1] = g_io_channel_unix_new(fd[1]); + server->connect_pipe[0] = g_io_channel_new(fd[0]); + server->connect_pipe[1] = g_io_channel_new(fd[1]); connect_address = server->connrec->proxy != NULL ? server->connrec->proxy : server->connrec->address; diff --git a/src/core/session.c b/src/core/session.c index 96a809ff..b3002632 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -22,6 +22,7 @@ #include "signals.h" #include "commands.h" #include "args.h" +#include "network.h" #include "net-sendbuffer.h" #include "pidwait.h" #include "lib-config/iconfig.h" @@ -259,7 +260,7 @@ static void session_restore_server(CONFIG_NODE *node) chatnet, password, nick); if (conn != NULL) { conn->reconnection = TRUE; - conn->connect_handle = g_io_channel_unix_new(handle); + conn->connect_handle = g_io_channel_new(handle); server = proto->server_init_connect(conn); server->version = g_strdup(config_node_get_str(node, "version", NULL)); diff --git a/src/fe-common/core/fe-exec.c b/src/fe-common/core/fe-exec.c index e8bde1ca..80df81ce 100644 --- a/src/fe-common/core/fe-exec.c +++ b/src/fe-common/core/fe-exec.c @@ -304,9 +304,9 @@ static void process_exec(PROCESS_REC *rec, const char *cmd) if (rec->pid != 0) { /* parent process */ - GIOChannel *outio = g_io_channel_unix_new(in[1]); + GIOChannel *outio = g_io_channel_new(in[1]); - rec->in = g_io_channel_unix_new(out[0]); + rec->in = g_io_channel_new(out[0]); rec->out = net_sendbuffer_create(outio, 0); close(out[1]); |