summaryrefslogtreecommitdiff
path: root/src/ivyloop.c
diff options
context:
space:
mode:
authorsc1999-02-09 22:51:55 +0000
committersc1999-02-09 22:51:55 +0000
commite3ba921ec1ab6866b3bf98873d01cced459ad245 (patch)
tree2705a7677061f2c101b5a5c356dfed57af3f828a /src/ivyloop.c
parent6c1ff14e669c4d5dea5f73ce4de6d501e6634af9 (diff)
downloadivy-c-e3ba921ec1ab6866b3bf98873d01cced459ad245.zip
ivy-c-e3ba921ec1ab6866b3bf98873d01cced459ad245.tar.gz
ivy-c-e3ba921ec1ab6866b3bf98873d01cced459ad245.tar.bz2
ivy-c-e3ba921ec1ab6866b3bf98873d01cced459ad245.tar.xz
A bit of clean up
Corrected bug in handling exceptions on channels.
Diffstat (limited to 'src/ivyloop.c')
-rw-r--r--src/ivyloop.c93
1 files changed, 45 insertions, 48 deletions
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;