mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
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:
parent
dd23f39f09
commit
df1d7a7814
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user