Add initial code for NSStream/NSRunLoop integration

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22608 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-03-07 09:14:37 +00:00
parent f2f9b79bd7
commit c9034890cf
6 changed files with 125 additions and 79 deletions

View file

@ -15,6 +15,7 @@
#include <Foundation/NSDebug.h>
#include <Foundation/NSNotificationQueue.h>
#include <Foundation/NSPort.h>
#include <Foundation/NSStream.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@ -29,6 +30,10 @@
#include <unistd.h>
#endif
@interface NSStream (RunLoop)
- (int) _fileDescriptor;
@end
extern BOOL GSCheckTasks();
#if GS_WITH_GC == 0
@ -114,6 +119,12 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
case ET_EDESC:
NSMapRemove(_efdMap, data);
break;
case ET_INSTREAM:
NSMapRemove(_rfdMap, data);
break;
case ET_OUTSTREAM:
NSMapRemove(_wfdMap, data);
break;
default:
NSLog(@"Ending an event of unkown type (%d)", type);
break;
@ -285,6 +296,24 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
NSMapInsert(_wfdMap, (void*)(intptr_t)fd, info);
break;
case ET_INSTREAM:
fd = [(NSStream*)info->data _fileDescriptor];
if (fd >= 0)
{
setPollfd(fd, POLLOUT, self);
NSMapInsert(_rfdMap, (void*)(intptr_t)fd, info);
}
break;
case ET_OUTSTREAM:
fd = [(NSStream*)info->data _fileDescriptor];
if (fd >= 0)
{
setPollfd(fd, POLLOUT, self);
NSMapInsert(_wfdMap, (void*)(intptr_t)fd, info);
}
break;
case ET_RPORT:
if ([info->receiver isValid] == NO)
{
@ -660,6 +689,31 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
}
}
break;
case ET_INSTREAM:
fd = [(NSStream*)info->data _fileDescriptor];
if (fd >= 0)
{
if (fd > fdEnd)
fdEnd = fd;
FD_SET (fd, &read_fds);
NSMapInsert(_rfdMap, (void*)(intptr_t)fd, info);
}
num_inputs++;
break;
case ET_OUTSTREAM:
fd = [(NSStream*)info->data _fileDescriptor];
if (fd >= 0)
{
if (fd > fdEnd)
fdEnd = fd;
FD_SET (fd, &read_fds);
NSMapInsert(_wfdMap, (void*)(intptr_t)fd, info);
}
num_inputs++;
break;
}
}
fdEnd++;