stream and runloop fixups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25147 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-05-12 17:11:35 +00:00
parent 37f9a1410b
commit ef7a025c3f
7 changed files with 191 additions and 202 deletions

View file

@ -382,14 +382,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
fprintf(stderr, "\n");
}
#endif
if (pollfds_count > 0)
{
poll_return = poll (pollfds, pollfds_count, milliseconds);
}
else
{
poll_return = 0;
}
poll_return = poll (pollfds, pollfds_count, milliseconds);
#if 0
{
unsigned int i;
@ -429,33 +422,33 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
* Trigger any watchers which are set up to for every runloop wait.
*/
count = GSIArrayCount(_trigger);
while (completed == NO && count-- > 0)
while (count-- > 0)
{
GSRunLoopWatcher *watcher;
watcher = (GSRunLoopWatcher*)GSIArrayItemAtIndex(_trigger, count).obj;
if (watcher->_invalidated == NO)
{
i = [contexts count];
while (i-- > 0)
{
GSRunLoopCtxt *c = [contexts objectAtIndex: i];
if (watcher->_invalidated == NO)
{
i = [contexts count];
while (i-- > 0)
{
GSRunLoopCtxt *c = [contexts objectAtIndex: i];
if (c != self)
{
[c endEvent: (void*)watcher for: watcher];
}
}
/*
* The watcher is still valid - so call its
* receivers event handling method.
*/
[watcher->receiver receivedEvent: watcher->data
type: watcher->type
extra: watcher->data
forMode: mode];
}
GSPrivateNotifyASAP();
if (c != self)
{
[c endEvent: (void*)watcher for: watcher];
}
}
/*
* The watcher is still valid - so call its
* receivers event handling method.
*/
[watcher->receiver receivedEvent: watcher->data
type: watcher->type
extra: watcher->data
forMode: mode];
}
GSPrivateNotifyASAP();
}
/*
@ -771,15 +764,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
// NSDebugMLLog(@"NSRunLoop", @"select timeout %d,%d", timeout.tv_sec, timeout.tv_usec);
if (fdEnd >= 0)
{
select_return = select (fdEnd, &read_fds, &write_fds,
&exception_fds, select_timeout);
}
else
{
select_return = 0;
}
select_return = select (fdEnd, &read_fds, &write_fds,
&exception_fds, select_timeout);
NSDebugMLLog(@"NSRunLoop", @"select returned %d", select_return);
@ -810,7 +796,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
* Trigger any watchers which are set up to for every runloop wait.
*/
count = GSIArrayCount(_trigger);
while (completed == NO && count-- > 0)
while (count-- > 0)
{
GSRunLoopWatcher *watcher;

View file

@ -424,7 +424,6 @@ static void setNonblocking(int fd)
else if (readLen == 0)
{
[self _setStatus: NSStreamStatusAtEnd];
[self _sendEvent: NSStreamEventEndEncountered];
}
return readLen;
}
@ -462,7 +461,6 @@ static void setNonblocking(int fd)
if (fd < 0)
{
[self _recordError];
[self _sendEvent: NSStreamEventErrorOccurred];
return;
}
_loopID = (void*)(intptr_t)fd;
@ -554,31 +552,25 @@ static void setNonblocking(int fd)
{
int result;
if (_runloop)
if (NSCountMapTable(_loops) > 0)
{
setNonblocking((intptr_t)_loopID);
}
result = connect((intptr_t)_loopID, [self peerAddr], [self sockLen]);
if (result < 0)
{
if (errno == EINPROGRESS && _runloop != nil)
if (errno == EINPROGRESS && NSCountMapTable(_loops) > 0)
{
unsigned i = [_modes count];
/*
* Need to set the status first, so that the run loop can tell
* it needs to add the stream as waiting on writable, as an
* indication of opened
*/
[self _setStatus: NSStreamStatusOpening];
while (i-- > 0)
{
[_runloop addStream: self mode: [_modes objectAtIndex: i]];
}
[self _schedule];
return;
}
[self _recordError];
[self _sendEvent: NSStreamEventErrorOccurred];
return;
}
}
@ -630,7 +622,6 @@ static void setNonblocking(int fd)
else if (readLen == 0)
{
[self _setStatus: NSStreamStatusAtEnd];
[self _sendEvent: NSStreamEventEndEncountered];
}
return readLen;
}
@ -656,13 +647,9 @@ static void setNonblocking(int fd)
int error;
int result;
socklen_t len = sizeof(error);
unsigned i = [_modes count];
AUTORELEASE(RETAIN(self));
while (i-- > 0)
{
[_runloop removeStream: self mode: [_modes objectAtIndex: i]];
}
[self _unschedule];
result
= getsockopt((intptr_t)_loopID, SOL_SOCKET, SO_ERROR, &error, &len);
@ -898,7 +885,6 @@ static void setNonblocking(int fd)
if (fd < 0)
{ // make an error
[self _recordError];
[self _sendEvent: NSStreamEventErrorOccurred];
return;
}
_loopID = (void*)(intptr_t)fd;
@ -1036,31 +1022,25 @@ static void setNonblocking(int fd)
{
int result;
if (_runloop)
if (NSCountMapTable(_loops) > 0)
{
setNonblocking((intptr_t)_loopID);
}
result = connect((intptr_t)_loopID, [self peerAddr], [self sockLen]);
if (result < 0)
{
if (errno == EINPROGRESS && _runloop != nil)
if (errno == EINPROGRESS && NSCountMapTable(_loops) > 0)
{
unsigned i = [_modes count];
/*
* Need to set the status first, so that the run loop can tell
* it needs to add the stream as waiting on writable, as an
* indication of opened
*/
[self _setStatus: NSStreamStatusOpening];
while (i-- > 0)
{
[_runloop addStream: self mode: [_modes objectAtIndex: i]];
}
[self _unschedule];
return;
}
[self _recordError];
[self _sendEvent: NSStreamEventErrorOccurred];
return;
}
}
@ -1093,13 +1073,9 @@ static void setNonblocking(int fd)
int error;
socklen_t len = sizeof(error);
int result;
unsigned i = [_modes count];
AUTORELEASE(RETAIN(self));
while (i-- > 0)
{
[_runloop removeStream: self mode: [_modes objectAtIndex: i]];
}
[self _schedule];
result
= getsockopt((intptr_t)_loopID, SOL_SOCKET, SO_ERROR, &error, &len);
if (result >= 0 && !error)
@ -1619,7 +1595,6 @@ static void setNonblocking(int fd)
if (bindReturn < 0 || listenReturn < 0)
{
[self _recordError];
[self _sendEvent: NSStreamEventErrorOccurred];
return;
}
setNonblocking((intptr_t)_loopID);