glib iochannel fixes from exg.

git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5137 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Alexander Færøy 2010-04-03 20:04:15 +00:00 committed by ahf
commit df1d7a7814
6 changed files with 39 additions and 34 deletions

View file

@ -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);