diff --git a/gtk/ipc.c b/gtk/ipc.c index 6ef79a8d6..fcaf3d70b 100644 --- a/gtk/ipc.c +++ b/gtk/ipc.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,8 @@ #include #include +#include + #include #include #include @@ -309,7 +310,7 @@ serv_bind(struct constate *con) { errmsg(con->u.serv.wind, _("Failed to set up socket: %s"), g_strerror(errno)); if(0 <= con->fd) - close(con->fd); + EVUTIL_CLOSESOCKET(con->fd); con->fd = -1; rmsock(); } @@ -346,14 +347,14 @@ client_connect(char *path, struct constate *con) { all_io_closed, con); if( NULL == con->source ) { - close( con->fd ); + EVUTIL_CLOSESOCKET( con->fd ); return FALSE; } buf = ipc_mkvers( &size, "Transmission GTK+ " LONG_VERSION_STRING ); if( NULL == buf ) { - close( con->fd ); + EVUTIL_CLOSESOCKET( con->fd ); return FALSE; } @@ -378,7 +379,7 @@ srv_io_accept(GSource *source UNUSED, int fd, struct sockaddr *sa UNUSED, if( NULL == newcon->ipc ) { g_free( newcon ); - close( fd ); + EVUTIL_CLOSESOCKET( fd ); return; } @@ -387,7 +388,7 @@ srv_io_accept(GSource *source UNUSED, int fd, struct sockaddr *sa UNUSED, { ipc_freecon( newcon->ipc ); g_free( newcon ); - close( fd ); + EVUTIL_CLOSESOCKET( fd ); return; } @@ -396,7 +397,7 @@ srv_io_accept(GSource *source UNUSED, int fd, struct sockaddr *sa UNUSED, { ipc_freecon( newcon->ipc ); g_free( newcon ); - close( fd ); + EVUTIL_CLOSESOCKET( fd ); return; } @@ -541,7 +542,7 @@ destroycon(struct constate *con) { con->source = NULL; if(0 <= con->fd) - close(con->fd); + EVUTIL_CLOSESOCKET(con->fd); con->fd = -1; ipc_freecon( con->ipc ); diff --git a/gtk/tr-io.c b/gtk/tr-io.c index b06079b5c..a3a1f6be4 100644 --- a/gtk/tr-io.c +++ b/gtk/tr-io.c @@ -24,18 +24,18 @@ #include #include -#include #include -#include -#include -#include +#include /* memset, memmove */ +#include /* read, write */ #include +#include /* evutil_make_socket_nonblocking */ + #include "tr-io.h" #include "util.h" -#define IO_BLOCKSIZE (1024) +#define IO_BLOCKSIZE (1024) struct iosource { GSource source; @@ -60,8 +60,6 @@ struct iooutbuf { unsigned int id; }; -static gboolean -nonblock(int fd); static struct iosource * newsource(void); static void @@ -92,12 +90,19 @@ static GSourceFuncs sourcefuncs = { NULL }; +static int +nonblock(int fd) +{ + const int err = evutil_make_socket_nonblocking( fd ); + return err; +} + GSource * io_new(int fd, ioidfunc_t sent, iodatafunc_t received, iofunc_t closed, void *cbdata) { struct iosource *io; - if(!nonblock(fd)) + if( nonblock( fd ) ) return NULL; io = newsource(); @@ -125,7 +130,7 @@ io_new_listening(int fd, socklen_t len, ionewfunc_t accepted, g_assert(NULL != accepted); - if(!nonblock(fd)) + if( nonblock( fd ) ) return NULL; io = newsource(); @@ -144,17 +149,6 @@ io_new_listening(int fd, socklen_t len, ionewfunc_t accepted, return (GSource*)io; } -static gboolean -nonblock(int fd) { - int flags; - - if(0 > (flags = fcntl(fd, F_GETFL)) || - 0 > fcntl(fd, F_SETFL, flags | O_NONBLOCK)) - return FALSE; - - return TRUE; -} - static struct iosource * newsource(void) { GSource *source = g_source_new(&sourcefuncs, sizeof(struct iosource));