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

@ -68,6 +68,10 @@ static NSDate *theFuture = nil;
extern BOOL GSCheckTasks();
@interface NSObject (OptionalPortRunLoop)
- (void) getFds: (int*)fds count: (int*)count;
@end
/*

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++;

View file

@ -15,9 +15,14 @@
#include <Foundation/NSDebug.h>
#include <Foundation/NSNotificationQueue.h>
#include <Foundation/NSPort.h>
#include <Foundation/NSStream.h>
extern BOOL GSCheckTasks();
@interface NSStream (RunLoop)
- (HANDLE) _handle;
@end
#if GS_WITH_GC == 0
SEL wRelSel;
SEL wRetSel;
@ -86,6 +91,10 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
break;
case ET_WINMSG:
break;
case ET_INSTREAM:
break;
case ET_OUTSTREAM:
break;
default:
NSLog(@"Ending an event of unkown type (%d)", type);
break;
@ -316,6 +325,22 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
NSMapInsert(winMsgMap, (void*)handle, info);
num_winMsgs++;
break;
case ET_INSTREAM:
handle = [(NSStream*)info->data _handle];
if (handle != 0)
{
NSMapInsert(handleMap, (void*)handle, info);
num_handles++;
}
break;
case ET_OUTSTREAM:
handle = [(NSStream*)info->data _handle];
if (handle != 0)
{
NSMapInsert(handleMap, (void*)handle, info);
num_handles++;
}
break;
}
}

View file

@ -26,6 +26,8 @@ SEL eventSel; /* Initialized in [NSRunLoop +initialize] */
case ET_RPORT: type = aType; break;
case ET_HANDLE: type = aType; break;
case ET_WINMSG: type = aType; break;
case ET_INSTREAM: type = aType; break;
case ET_OUTSTREAM: type = aType; break;
default:
[NSException raise: NSInvalidArgumentException
format: @"NSRunLoop - unknown event type"];