From e3ba921ec1ab6866b3bf98873d01cced459ad245 Mon Sep 17 00:00:00 2001 From: sc Date: Tue, 9 Feb 1999 22:51:55 +0000 Subject: A bit of clean up Corrected bug in handling exceptions on channels. --- src/ivyloop.c | 93 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 48 deletions(-) (limited to 'src/ivyloop.c') diff --git a/src/ivyloop.c b/src/ivyloop.c index a8fc8b1..635ae8a 100644 --- a/src/ivyloop.c +++ b/src/ivyloop.c @@ -65,101 +65,100 @@ static fd_set open_fds; static int MainLoop = 1; #ifdef WIN32 -WSADATA WsaData; +WSADATA WsaData; #endif -void IvyChannelClose( Channel channel ) +void +IvyChannelClose (Channel channel) { channel->tobedeleted = 1; } -static void IvyChannelDelete( Channel channel ) +static void +IvyChannelDelete (Channel channel) { - if ( channel->handle_delete ) - (*channel->handle_delete)( channel->data ); + if (channel->handle_delete) + (*channel->handle_delete) (channel->data); - FD_CLR(channel->fd, &open_fds); - LIST_REMOVE( channels_list, channel ); + FD_CLR (channel->fd, &open_fds); + LIST_REMOVE (channels_list, channel); } -static void ChannelDefferedDelete() +static void +ChannelDefferedDelete () { - Channel channel,next; - LIST_EACH_SAFE( channels_list, channel,next) - { - if ( channel->tobedeleted ) - { - IvyChannelDelete( channel ); - } + Channel channel, next; + LIST_EACH_SAFE (channels_list, channel,next) { + if (channel->tobedeleted ) { + IvyChannelDelete (channel); } + } } -Channel IvyChannelSetUp(HANDLE fd, void *data, +Channel IvyChannelSetUp (HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) { Channel channel; - LIST_ADD( channels_list, channel ); - if ( !channel ) - { + LIST_ADD (channels_list, channel); + if (!channel) { fprintf(stderr,"NOK Memory Alloc Error\n"); exit(0); - } + } channel->fd = fd; channel->tobedeleted = 0; channel->handle_delete = handle_delete; channel->handle_read = handle_read; channel->data = data; - FD_SET( channel->fd, &open_fds ); + FD_SET (channel->fd, &open_fds); return channel; } -static void IvyChannelHandleRead(fd_set *current) +static void +IvyChannelHandleRead (fd_set *current) { - Channel channel,next; + Channel channel, next; - LIST_EACH_SAFE( channels_list, channel, next ) - { - if ( FD_ISSET( channel->fd, current ) ) - { + LIST_EACH_SAFE (channels_list, channel, next) { + if (FD_ISSET (channel->fd, current)) { (*channel->handle_read)(channel,channel->fd,channel->data); - } } + } } -static void IvyChannelHandleExcpt(fd_set *current) +static void +IvyChannelHandleExcpt (fd_set *current) { Channel channel,next; - LIST_EACH_SAFE( channels_list, channel, next ) - { - if (FD_ISSET( channel->fd, current ) ) - { - (*channel->handle_delete)(channel->data); -/* IvyChannelClose( channel ); */ - } + LIST_EACH_SAFE (channels_list, channel, next) { + if (FD_ISSET (channel->fd, current)) { + if (channel->handle_delete) + (*channel->handle_delete)(channel->data); +/* IvyChannelClose (channel); */ } + } } -void IvyChannelInit(void) +void IvyChannelInit (void) { #ifdef WIN32 int error; #else /* pour eviter les plantages quand les autres applis font core-dump */ - signal( SIGPIPE, SIG_IGN); + signal (SIGPIPE, SIG_IGN); #endif - if ( channel_initialized ) return; + if (channel_initialized) return; - FD_ZERO( &open_fds ); + FD_ZERO (&open_fds); #ifdef WIN32 - error = WSAStartup( 0x0101, &WsaData ); - if ( error == SOCKET_ERROR ) { - printf( "WSAStartup failed.\n" ); + error = WSAStartup (0x0101, &WsaData); + if (error == SOCKET_ERROR) { + printf ("WSAStartup failed.\n"); } #endif channel_initialized = 1; @@ -182,18 +181,16 @@ void IvyMainLoop(void(*hook)(void)) while (MainLoop) { ChannelDefferedDelete(); - if ( hook ) (*hook)(); + if (hook) (*hook)(); rdset = open_fds; exset = open_fds; ready = select(64, &rdset, 0, &exset, TimerGetSmallestTimeout()); - if ( ready < 0 && ( errno != EINTR )) - { + if (ready < 0 && (errno != EINTR)) { perror("select"); return; } TimerScan(); - if ( ready > 0 ) - { + if (ready > 0) { IvyChannelHandleExcpt(&exset); IvyChannelHandleRead(&rdset); continue; -- cgit v1.1