From 9fa77320ca368af97162d561bb7560b9fa55666a Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 17 Mar 2009 04:49:35 +0000 Subject: [PATCH] vol-socket-abstraction-20090317 LICENSE IPL10 windows needs the abstraction for sockets --- src/vol/daemon_com.c | 8 ++++---- src/vol/daemon_com.h | 10 +++++----- src/vol/fssync-server.c | 42 +++++++++++++++++++-------------------- src/vol/salvsync-server.c | 26 ++++++++++++------------ 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/vol/daemon_com.c b/src/vol/daemon_com.c index a500afac6..b534ffaa2 100644 --- a/src/vol/daemon_com.c +++ b/src/vol/daemon_com.c @@ -129,10 +129,10 @@ SYNC_getAddr(SYNC_endpoint_t * endpoint, SYNC_sockaddr_t * addr) * @post socket of domain specified in endpoint structure is created and * returned to caller. */ -int +osi_socket SYNC_getSock(SYNC_endpoint_t * endpoint) { - int sd; + osi_socket sd; assert((sd = socket(endpoint->domain, SOCK_STREAM, 0)) >= 0); return sd; } @@ -501,7 +501,7 @@ SYNC_ask_internal(SYNC_client_state * state, SYNC_command * com, SYNC_response * */ afs_int32 SYNC_getCom(SYNC_server_state_t * state, - int fd, + osi_socket fd, SYNC_command * com) { int n; @@ -577,7 +577,7 @@ SYNC_getCom(SYNC_server_state_t * state, */ afs_int32 SYNC_putRes(SYNC_server_state_t * state, - int fd, + osi_socket fd, SYNC_response * res) { int n; diff --git a/src/vol/daemon_com.h b/src/vol/daemon_com.h index fee96e8aa..59933a1fb 100644 --- a/src/vol/daemon_com.h +++ b/src/vol/daemon_com.h @@ -114,7 +114,7 @@ typedef struct SYNC_endpoint { * SYNC server state structure. */ typedef struct SYNC_server_state { - int fd; /**< listening socket descriptor */ + osi_socket fd; /**< listening socket descriptor */ SYNC_endpoint_t endpoint; /**< server endpoint address */ afs_uint32 proto_version; /**< our protocol version */ int bind_retry_limit; /**< upper limit on times to retry socket bind() */ @@ -129,7 +129,7 @@ typedef struct SYNC_server_state { * SYNC client state structure. */ typedef struct SYNC_client_state { - int fd; /**< client socket descriptor */ + osi_socket fd; /**< client socket descriptor */ SYNC_endpoint_t endpoint; /**< address of sync server */ afs_uint32 proto_version; /**< our protocol version */ int retry_limit; /**< max number of times for SYNC_ask to retry */ @@ -192,7 +192,7 @@ typedef struct SYNC_response { } SYNC_response; /* general prototypes */ -extern int SYNC_getSock(SYNC_endpoint_t * endpoint); +extern osi_socket SYNC_getSock(SYNC_endpoint_t * endpoint); extern void SYNC_getAddr(SYNC_endpoint_t * endpoint, SYNC_sockaddr_t * addr); /* client-side prototypes */ @@ -203,8 +203,8 @@ extern afs_int32 SYNC_closeChannel(SYNC_client_state *); /* do a graceful chann extern int SYNC_reconnect(SYNC_client_state *); /* do a reconnect after a protocol error, or from a forked child */ /* server-side prototypes */ -extern int SYNC_getCom(SYNC_server_state_t *, int fd, SYNC_command * com); -extern int SYNC_putRes(SYNC_server_state_t *, int fd, SYNC_response * res); +extern int SYNC_getCom(SYNC_server_state_t *, osi_socket fd, SYNC_command * com); +extern int SYNC_putRes(SYNC_server_state_t *, osi_socket fd, SYNC_response * res); extern int SYNC_verifyProtocolString(char * buf, size_t len); extern void SYNC_cleanupSock(SYNC_server_state_t * state); extern int SYNC_bindSock(SYNC_server_state_t * state); diff --git a/src/vol/fssync-server.c b/src/vol/fssync-server.c index 7129da757..0b51650ac 100644 --- a/src/vol/fssync-server.c +++ b/src/vol/fssync-server.c @@ -125,15 +125,15 @@ static SYNC_server_state_t fssync_server_state = /* Forward declarations */ static void * FSYNC_sync(void *); static void FSYNC_newconnection(osi_socket afd); -static void FSYNC_com(int fd); -static void FSYNC_Drop(int fd); +static void FSYNC_com(osi_socket fd); +static void FSYNC_Drop(osi_socket fd); static void AcceptOn(void); static void AcceptOff(void); static void InitHandler(void); -static int AddHandler(int fd, void (*aproc)(int)); -static int FindHandler(int afd); -static int FindHandler_r(int afd); -static int RemoveHandler(int afd); +static int AddHandler(osi_socket fd, void (*aproc)(int)); +static int FindHandler(osi_socket afd); +static int FindHandler_r(osi_socket afd); +static int RemoveHandler(osi_socket afd); #if defined(HAVE_POLL) && defined (AFS_PTHREAD_ENV) static void CallHandler(struct pollfd *fds, int nfds, int mask); static void GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds); @@ -143,7 +143,7 @@ static void GetHandler(fd_set * fdsetp, int *maxfdp); #endif extern int LogLevel; -static afs_int32 FSYNC_com_VolOp(int fd, SYNC_command * com, SYNC_response * res); +static afs_int32 FSYNC_com_VolOp(osi_socket fd, SYNC_command * com, SYNC_response * res); #ifdef AFS_DEMAND_ATTACH_FS static afs_int32 FSYNC_com_VolError(FSSYNC_VolOp_command * com, SYNC_response * res); @@ -159,9 +159,9 @@ static afs_int32 FSYNC_com_VolHdrQuery(FSSYNC_VolOp_command * com, SYNC_response static afs_int32 FSYNC_com_VolOpQuery(FSSYNC_VolOp_command * com, SYNC_response * res); #endif /* AFS_DEMAND_ATTACH_FS */ -static afs_int32 FSYNC_com_VnQry(int fd, SYNC_command * com, SYNC_response * res); +static afs_int32 FSYNC_com_VnQry(osi_socket fd, SYNC_command * com, SYNC_response * res); -static afs_int32 FSYNC_com_StatsOp(int fd, SYNC_command * com, SYNC_response * res); +static afs_int32 FSYNC_com_StatsOp(osi_socket fd, SYNC_command * com, SYNC_response * res); static afs_int32 FSYNC_com_StatsOpGeneral(FSSYNC_StatsOp_command * scom, SYNC_response * res); @@ -321,7 +321,7 @@ FSYNC_newconnection(osi_socket afd) /* this function processes commands from an fssync file descriptor (fd) */ afs_int32 FS_cnt = 0; static void -FSYNC_com(int fd) +FSYNC_com(osi_socket fd) { SYNC_command com; SYNC_response res; @@ -407,7 +407,7 @@ FSYNC_com(int fd) } static afs_int32 -FSYNC_com_VolOp(int fd, SYNC_command * com, SYNC_response * res) +FSYNC_com_VolOp(osi_socket fd, SYNC_command * com, SYNC_response * res) { int i; afs_int32 code = SYNC_OK; @@ -1239,7 +1239,7 @@ FSYNC_com_VolOpQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res) #endif /* AFS_DEMAND_ATTACH_FS */ static afs_int32 -FSYNC_com_VnQry(int fd, SYNC_command * com, SYNC_response * res) +FSYNC_com_VnQry(osi_socket fd, SYNC_command * com, SYNC_response * res) { afs_int32 code = SYNC_OK; FSSYNC_VnQry_hdr * qry = com->payload.buf; @@ -1291,7 +1291,7 @@ FSYNC_com_VnQry(int fd, SYNC_command * com, SYNC_response * res) } static afs_int32 -FSYNC_com_StatsOp(int fd, SYNC_command * com, SYNC_response * res) +FSYNC_com_StatsOp(osi_socket fd, SYNC_command * com, SYNC_response * res) { afs_int32 code = SYNC_OK; FSSYNC_StatsOp_command scom; @@ -1471,7 +1471,7 @@ FSYNC_partMatch(FSSYNC_VolOp_command * vcom, Volume * vp, int match_anon) static void -FSYNC_Drop(int fd) +FSYNC_Drop(osi_socket fd) { struct offlineInfo *p; int i; @@ -1526,7 +1526,7 @@ AcceptOff(void) /* The multiple FD handling code. */ -static int HandlerFD[MAXHANDLERS]; +static osi_socket HandlerFD[MAXHANDLERS]; static void (*HandlerProc[MAXHANDLERS]) (int); static void @@ -1576,7 +1576,7 @@ CallHandler(fd_set * fdsetp) #endif static int -AddHandler(int afd, void (*aproc) (int)) +AddHandler(osi_socket afd, void (*aproc) (int)) { register int i; ObtainWriteLock(&FSYNC_handler_lock); @@ -1594,7 +1594,7 @@ AddHandler(int afd, void (*aproc) (int)) } static int -FindHandler(register int afd) +FindHandler(register osi_socket afd) { register int i; ObtainReadLock(&FSYNC_handler_lock); @@ -1609,7 +1609,7 @@ FindHandler(register int afd) } static int -FindHandler_r(register int afd) +FindHandler_r(register osi_socket afd) { register int i; for (i = 0; i < MAXHANDLERS; i++) @@ -1621,7 +1621,7 @@ FindHandler_r(register int afd) } static int -RemoveHandler(register int afd) +RemoveHandler(register osi_socket afd) { ObtainWriteLock(&FSYNC_handler_lock); HandlerFD[FindHandler_r(afd)] = -1; @@ -1652,13 +1652,13 @@ static void GetHandler(fd_set * fdsetp, int *maxfdp) { register int i; - register int maxfd = -1; + register osi_socket maxfd = -1; FD_ZERO(fdsetp); ObtainReadLock(&FSYNC_handler_lock); /* just in case */ for (i = 0; i < MAXHANDLERS; i++) if (HandlerFD[i] != -1) { FD_SET(HandlerFD[i], fdsetp); - if (maxfd < HandlerFD[i]) + if (maxfd < HandlerFD[i] || maxfd == (osi_socket)-1) maxfd = HandlerFD[i]; } *maxfdp = maxfd; diff --git a/src/vol/salvsync-server.c b/src/vol/salvsync-server.c index 59ef63d02..bd44bcf20 100644 --- a/src/vol/salvsync-server.c +++ b/src/vol/salvsync-server.c @@ -91,17 +91,17 @@ struct Lock SALVSYNC_handler_lock; /* Forward declarations */ static void * SALVSYNC_syncThread(void *); -static void SALVSYNC_newconnection(int fd); -static void SALVSYNC_com(int fd); -static void SALVSYNC_Drop(int fd); +static void SALVSYNC_newconnection(osi_socket fd); +static void SALVSYNC_com(osi_socket fd); +static void SALVSYNC_Drop(osi_socket fd); static void AcceptOn(void); static void AcceptOff(void); static void InitHandler(void); static void CallHandler(fd_set * fdsetp); -static int AddHandler(int afd, void (*aproc) (int)); -static int FindHandler(register int afd); -static int FindHandler_r(register int afd); -static int RemoveHandler(register int afd); +static int AddHandler(osi_socket afd, void (*aproc) (int)); +static int FindHandler(register osi_socket afd); +static int FindHandler_r(register osi_socket afd); +static int RemoveHandler(register osi_socket afd); static void GetHandler(fd_set * fdsetp, int *maxfdp); static int AllocNode(struct SalvageQueueNode ** node); @@ -356,7 +356,7 @@ SALVSYNC_newconnection(int afd) /* this function processes commands from an salvsync file descriptor (fd) */ static afs_int32 SALV_cnt = 0; static void -SALVSYNC_com(int fd) +SALVSYNC_com(osi_socket fd) { SYNC_command com; SYNC_response res; @@ -727,7 +727,7 @@ SALVSYNC_com_Query(SALVSYNC_command * com, SALVSYNC_response * res) } static void -SALVSYNC_Drop(int fd) +SALVSYNC_Drop(osi_socket fd) { RemoveHandler(fd); #ifdef AFS_NT40_ENV @@ -791,7 +791,7 @@ CallHandler(fd_set * fdsetp) } static int -AddHandler(int afd, void (*aproc) (int)) +AddHandler(osi_socket afd, void (*aproc) (int)) { register int i; ObtainWriteLock(&SALVSYNC_handler_lock); @@ -809,7 +809,7 @@ AddHandler(int afd, void (*aproc) (int)) } static int -FindHandler(register int afd) +FindHandler(register osi_socket afd) { register int i; ObtainReadLock(&SALVSYNC_handler_lock); @@ -824,7 +824,7 @@ FindHandler(register int afd) } static int -FindHandler_r(register int afd) +FindHandler_r(register osi_socket afd) { register int i; for (i = 0; i < MAXHANDLERS; i++) @@ -836,7 +836,7 @@ FindHandler_r(register int afd) } static int -RemoveHandler(register int afd) +RemoveHandler(register osi_socket afd) { ObtainWriteLock(&SALVSYNC_handler_lock); HandlerFD[FindHandler_r(afd)] = -1; -- 2.39.5