Changeset 5123


Ignore:
Timestamp:
Feb 26, 2008, 8:31:33 PM (14 years ago)
Author:
charles
Message:

(gtk) use evutils for a portability layer on making sockets nonblocking and closing sockets

Location:
trunk/gtk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/ipc.c

    r5122 r5123  
    2727#include <sys/un.h>
    2828#include <errno.h>
    29 #include <fcntl.h>
    3029#include <stdio.h>
    3130#include <stdlib.h>
     
    3534#include <gtk/gtk.h>
    3635#include <glib/gi18n.h>
     36
     37#include <libevent/evutil.h>
    3738
    3839#include <libtransmission/transmission.h>
     
    310311         g_strerror(errno));
    311312  if(0 <= con->fd)
    312     close(con->fd);
     313    EVUTIL_CLOSESOCKET(con->fd);
    313314  con->fd = -1;
    314315  rmsock();
     
    347348  if( NULL == con->source )
    348349  {
    349       close( con->fd );
     350      EVUTIL_CLOSESOCKET( con->fd );
    350351      return FALSE;
    351352  }
     
    354355  if( NULL == buf )
    355356  {
    356       close( con->fd );
     357      EVUTIL_CLOSESOCKET( con->fd );
    357358      return FALSE;
    358359  }
     
    379380  {
    380381      g_free( newcon );
    381       close( fd );
     382      EVUTIL_CLOSESOCKET( fd );
    382383      return;
    383384  }
     
    388389      ipc_freecon( newcon->ipc );
    389390      g_free( newcon );
    390       close( fd );
     391      EVUTIL_CLOSESOCKET( fd );
    391392      return;
    392393  }
     
    397398      ipc_freecon( newcon->ipc );
    398399      g_free( newcon );
    399       close( fd );
     400      EVUTIL_CLOSESOCKET( fd );
    400401      return;
    401402  }
     
    542543
    543544  if(0 <= con->fd)
    544     close(con->fd);
     545    EVUTIL_CLOSESOCKET(con->fd);
    545546  con->fd = -1;
    546547  ipc_freecon( con->ipc );
  • trunk/gtk/tr-io.c

    r5119 r5123  
    2525#include <sys/types.h>
    2626#include <sys/socket.h>
    27 #include <sys/uio.h>
    2827#include <errno.h>
    29 #include <fcntl.h>
    30 #include <string.h>
    31 #include <unistd.h>
     28#include <string.h> /* memset, memmove */
     29#include <unistd.h> /* read, write */
    3230
    3331#include <glib.h>
     32
     33#include <libevent/evutil.h> /* evutil_make_socket_nonblocking */
    3434
    3535#include "tr-io.h"
    3636#include "util.h"
    3737
    38 #define IO_BLOCKSIZE            (1024)
     38#define IO_BLOCKSIZE (1024)
    3939
    4040struct iosource {
     
    6161};
    6262
    63 static gboolean
    64 nonblock(int fd);
    6563static struct iosource *
    6664newsource(void);
     
    9391};
    9492
     93static int
     94nonblock(int fd)
     95{
     96    const int err = evutil_make_socket_nonblocking( fd );
     97    return err;
     98}
     99
    95100GSource *
    96101io_new(int fd, ioidfunc_t sent, iodatafunc_t received,
     
    98103  struct iosource *io;
    99104
    100   if(!nonblock(fd))
     105  if( nonblock( fd ) )
    101106    return NULL;
    102107
     
    126131  g_assert(NULL != accepted);
    127132
    128   if(!nonblock(fd))
     133  if( nonblock( fd ) )
    129134    return NULL;
    130135
     
    143148
    144149  return (GSource*)io;
    145 }
    146 
    147 static gboolean
    148 nonblock(int fd) {
    149   int flags;
    150 
    151   if(0 > (flags = fcntl(fd, F_GETFL)) ||
    152      0 > fcntl(fd, F_SETFL, flags | O_NONBLOCK))
    153     return FALSE;
    154 
    155   return TRUE;
    156150}
    157151
Note: See TracChangeset for help on using the changeset viewer.