diff options
author | Timo Sirainen <cras@irssi.org> | 2000-12-04 22:57:18 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-12-04 22:57:18 +0000 |
commit | 1c9f45b4a41e5553c89393cd3228b8e8e9d6131b (patch) | |
tree | 2431f899730d091c2185e651184693d5f1853dce /src/core/servers.c | |
parent | e81fdd730752012a3b34af443226f50d4771cc54 (diff) | |
download | irssi-1c9f45b4a41e5553c89393cd3228b8e8e9d6131b.zip |
Use GIOChannel instead of sockets directly. Helps porting to win32 :)
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@962 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core/servers.c')
-rw-r--r-- | src/core/servers.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/core/servers.c b/src/core/servers.c index fa9e6666..9ba883a4 100644 --- a/src/core/servers.c +++ b/src/core/servers.c @@ -51,9 +51,11 @@ void server_connect_failed(SERVER_REC *server, const char *msg) if (server->handle != NULL) net_sendbuffer_destroy(server->handle, TRUE); - if (server->connect_pipe[0] != -1) { - close(server->connect_pipe[0]); - close(server->connect_pipe[1]); + if (server->connect_pipe[0] != NULL) { + g_io_channel_close(server->connect_pipe[0]); + g_io_channel_unref(server->connect_pipe[0]); + g_io_channel_close(server->connect_pipe[1]); + g_io_channel_unref(server->connect_pipe[1]); } MODULE_DATA_DEINIT(server); @@ -129,7 +131,7 @@ void server_connect_finished(SERVER_REC *server) signal_emit("server connected", 1, server); } -static void server_connect_callback_init(SERVER_REC *server, int handle) +static void server_connect_callback_init(SERVER_REC *server, GIOChannel *handle) { int error; @@ -154,7 +156,7 @@ static void server_connect_callback_readpipe(SERVER_REC *server) SERVER_CONNECT_REC *conn; RESOLVED_IP_REC iprec; const char *errormsg; - int handle; + GIOChannel *handle; g_return_if_fail(IS_SERVER(server)); @@ -163,18 +165,20 @@ static void server_connect_callback_readpipe(SERVER_REC *server) net_gethostbyname_return(server->connect_pipe[0], &iprec); - close(server->connect_pipe[0]); - close(server->connect_pipe[1]); + g_io_channel_close(server->connect_pipe[0]); + g_io_channel_unref(server->connect_pipe[0]); + g_io_channel_close(server->connect_pipe[1]); + g_io_channel_unref(server->connect_pipe[1]); - server->connect_pipe[0] = -1; - server->connect_pipe[1] = -1; + server->connect_pipe[0] = NULL; + server->connect_pipe[1] = NULL; conn = server->connrec; - handle = iprec.error != 0 ? -1 : + handle = iprec.error != 0 ? NULL : net_connect_ip(&iprec.ip, conn->proxy != NULL ? conn->proxy_port : conn->port, conn->own_ip != NULL ? conn->own_ip : NULL); - if (handle == -1) { + if (handle == NULL) { /* failed */ if (iprec.error == 0 || !net_hosterror_notfound(iprec.error)) { /* reconnect back only if either @@ -237,19 +241,23 @@ void server_connect_init(SERVER_REC *server) int server_start_connect(SERVER_REC *server) { const char *connect_address; + int fd[2]; g_return_val_if_fail(server != NULL, FALSE); if (server->connrec->port <= 0) return FALSE; server_connect_init(server); - if (pipe(server->connect_pipe) != 0) { + if (pipe(fd) != 0) { g_warning("server_connect(): pipe() failed."); g_free(server->tag); g_free(server->nick); return FALSE; } + server->connect_pipe[0] = g_io_channel_unix_new(fd[0]); + server->connect_pipe[1] = g_io_channel_unix_new(fd[1]); + connect_address = server->connrec->proxy != NULL ? server->connrec->proxy : server->connrec->address; server->connect_pid = |