Fix for notification queue item removal and for availableData

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@5246 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-11-21 06:33:45 +00:00
parent 51fe7f149c
commit 9e3c780110
3 changed files with 158 additions and 92 deletions

View file

@ -1,3 +1,12 @@
Sun Nov 21 6:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSNotificationQueue.m: Applied patch by Dan Pascu to fix bug
in removal of notificatiosn from queues. Also tidied indentation etc
to conform to GNU standards.
* Source/UnixFileHandle.m: ([-availableData]) fixed to block when no
data is availabvle on a comms channel - as per spec. This bug was
also reported by Dan <dan@services.iirux.ro>
1999-11-18 Adam Fedor <fedor@gnu.org> 1999-11-18 Adam Fedor <fedor@gnu.org>
* Source/GNUmakefile: Install unicode headers. * Source/GNUmakefile: Install unicode headers.

View file

@ -103,19 +103,22 @@ currentList()
NotificationQueueList *list; NotificationQueueList *list;
NotificationQueueList *elem; NotificationQueueList *elem;
if (q == nil)
return; /* Can't register nil object. */
list = currentList(); /* List of queues for thread. */ list = currentList(); /* List of queues for thread. */
if (list->queue == nil) if (list->queue == nil)
{
list->queue = q; /* Make this the default. */ list->queue = q; /* Make this the default. */
}
while (list->queue != q && list->next != nil) while (list->queue != q && list->next != nil)
{
list = list->next; list = list->next;
}
if (list->queue == q) if (list->queue == q)
{
return; /* Queue already registered. */ return; /* Queue already registered. */
}
elem = (NotificationQueueList*)NSAllocateObject(self, 0, elem = (NotificationQueueList*)NSAllocateObject(self, 0,
NSDefaultMallocZone()); NSDefaultMallocZone());
@ -127,9 +130,6 @@ currentList()
{ {
NotificationQueueList *list; NotificationQueueList *list;
if (q == nil)
return;
list = currentList(); list = currentList();
if (list->queue == q) if (list->queue == q)
@ -145,8 +145,10 @@ currentList()
RELEASE(tmp); /* retained in dictionary. */ RELEASE(tmp); /* retained in dictionary. */
} }
else else
{
[d removeObjectForKey: tkey]; [d removeObjectForKey: tkey];
} }
}
else else
{ {
while (list->next != nil) while (list->next != nil)
@ -197,8 +199,7 @@ typedef struct _NSNotificationQueueList
*/ */
static inline void static inline void
remove_from_queue_no_release( remove_from_queue_no_release(NSNotificationQueueList *queue,
NSNotificationQueueList* queue,
NSNotificationQueueRegistration *item) NSNotificationQueueRegistration *item)
{ {
if (item->prev) if (item->prev)
@ -229,10 +230,8 @@ remove_from_queue_no_release(
} }
static void static void
remove_from_queue( remove_from_queue(NSNotificationQueueList *queue,
NSNotificationQueueList* queue, NSNotificationQueueRegistration *item, NSZone *_zone)
NSNotificationQueueRegistration* item,
NSZone* _zone)
{ {
remove_from_queue_no_release(queue, item); remove_from_queue_no_release(queue, item);
RELEASE(item->notification); RELEASE(item->notification);
@ -241,14 +240,12 @@ remove_from_queue(
} }
static void static void
add_to_queue( add_to_queue(NSNotificationQueueList *queue, NSNotification *notification,
NSNotificationQueueList* queue, NSArray *modes, NSZone *_zone)
NSNotification* notification,
NSArray* modes,
NSZone* _zone)
{ {
NSNotificationQueueRegistration* item = NSNotificationQueueRegistration *item;
NSZoneCalloc(_zone, 1, sizeof(NSNotificationQueueRegistration));
item = NSZoneCalloc(_zone, 1, sizeof(NSNotificationQueueRegistration));
item->notification = RETAIN(notification); item->notification = RETAIN(notification);
item->name = [notification name]; item->name = [notification name];
@ -259,10 +256,14 @@ add_to_queue(
item->next = queue->tail; item->next = queue->tail;
queue->tail = item; queue->tail = item;
if (item->next) if (item->next)
{
item->next->prev = item; item->next->prev = item;
}
if (!queue->head) if (!queue->head)
{
queue->head = item; queue->head = item;
} }
}
@ -304,7 +305,9 @@ add_to_queue(
_asapQueue = NSZoneCalloc(_zone, 1, sizeof(NSNotificationQueueList)); _asapQueue = NSZoneCalloc(_zone, 1, sizeof(NSNotificationQueueList));
_idleQueue = NSZoneCalloc(_zone, 1, sizeof(NSNotificationQueueList)); _idleQueue = NSZoneCalloc(_zone, 1, sizeof(NSNotificationQueueList));
// insert in global queue list /*
* insert in global queue list
*/
[NotificationQueueList registerQueue: self]; [NotificationQueueList registerQueue: self];
return self; return self;
@ -314,16 +317,24 @@ add_to_queue(
{ {
NSNotificationQueueRegistration *item; NSNotificationQueueRegistration *item;
// remove from class instances list /*
* remove from class instances list
*/
[NotificationQueueList unregisterQueue: self]; [NotificationQueueList unregisterQueue: self];
// release self /*
* release self from queues
*/
for (item = _asapQueue->head; item; item=item->prev) for (item = _asapQueue->head; item; item=item->prev)
{
remove_from_queue(_asapQueue, item, _zone); remove_from_queue(_asapQueue, item, _zone);
}
NSZoneFree(_zone, _asapQueue); NSZoneFree(_zone, _asapQueue);
for (item = _idleQueue->head; item; item=item->prev) for (item = _idleQueue->head; item; item=item->prev)
{
remove_from_queue(_idleQueue, item, _zone); remove_from_queue(_idleQueue, item, _zone);
}
NSZoneFree(_zone, _idleQueue); NSZoneFree(_zone, _idleQueue);
RELEASE(_center); RELEASE(_center);
@ -340,39 +351,80 @@ add_to_queue(
id name = [notification name]; id name = [notification name];
id object = [notification object]; id object = [notification object];
// find in ASAP notification in queue if ((coalesceMask & NSNotificationCoalescingOnName)
&& (coalesceMask & NSNotificationCoalescingOnSender))
{
/*
* find in ASAP notification in queue matching both
*/
for (item = _asapQueue->tail; item; item = next) for (item = _asapQueue->tail; item; item = next)
{ {
next = item->next; next = item->next;
if ((coalesceMask & NSNotificationCoalescingOnName) if ((object == item->object) && [name isEqual: item->name])
&& [name isEqual: item->name])
{ {
remove_from_queue(_asapQueue, item, _zone); remove_from_queue(_asapQueue, item, _zone);
continue;
}
if ((coalesceMask & NSNotificationCoalescingOnSender)
&& (object == item->object))
{
remove_from_queue(_asapQueue, item, _zone);
continue;
} }
} }
/*
// find in idle notification in queue * find in idle notification in queue matching both
*/
for (item = _idleQueue->tail; item; item = next) for (item = _idleQueue->tail; item; item = next)
{ {
next = item->next; next = item->next;
if ((coalesceMask & NSNotificationCoalescingOnName) if ((object == item->object) && [name isEqual: item->name])
&& [name isEqual: item->name])
{ {
remove_from_queue(_asapQueue, item, _zone); remove_from_queue(_idleQueue, item, _zone);
continue;
} }
if ((coalesceMask & NSNotificationCoalescingOnSender) }
&& (object == item->object)) }
else if ((coalesceMask & NSNotificationCoalescingOnName))
{
/*
* find in ASAP notification in queue matching name
*/
for (item = _asapQueue->tail; item; item = next)
{
next = item->next;
if ([name isEqual: item->name])
{ {
remove_from_queue(_asapQueue, item, _zone); remove_from_queue(_asapQueue, item, _zone);
continue; }
}
/*
* find in idle notification in queue matching name
*/
for (item = _idleQueue->tail; item; item = next)
{
next = item->next;
if ([name isEqual: item->name])
{
remove_from_queue(_idleQueue, item, _zone);
}
}
}
else if ((coalesceMask & NSNotificationCoalescingOnSender))
{
/*
* find in ASAP notification in queue matching sender
*/
for (item = _asapQueue->tail; item; item = next)
{
next = item->next;
if (object == item->object)
{
remove_from_queue(_asapQueue, item, _zone);
}
}
/*
* find in idle notification in queue matching sender
*/
for (item = _idleQueue->tail; item; item = next)
{
next = item->next;
if (object == item->object)
{
remove_from_queue(_idleQueue, item, _zone);
}
} }
} }
} }
@ -457,9 +509,13 @@ GSNotifyASAP()
NotificationQueueList *item; NotificationQueueList *item;
for (item = currentList(); item; item = item->next) for (item = currentList(); item; item = item->next)
{
if (item->queue) if (item->queue)
{
notifyASAP(item->queue); notifyASAP(item->queue);
} }
}
}
static inline void notifyIdle(NSNotificationQueue *q) static inline void notifyIdle(NSNotificationQueue *q)
{ {
@ -492,9 +548,13 @@ GSNotifyIdle()
NotificationQueueList *item; NotificationQueueList *item;
for (item = currentList(); item; item = item->next) for (item = currentList(); item; item = item->next)
{
if (item->queue) if (item->queue)
{
notifyIdle(item->queue); notifyIdle(item->queue);
} }
}
}
BOOL BOOL
GSNotifyMore() GSNotifyMore()
@ -502,8 +562,12 @@ GSNotifyMore()
NotificationQueueList *item; NotificationQueueList *item;
for (item = currentList(); item; item = item->next) for (item = currentList(); item; item = item->next)
{
if (item->queue && ((accessQueue)item->queue)->_idleQueue->head) if (item->queue && ((accessQueue)item->queue)->_idleQueue->head)
{
return YES; return YES;
}
}
return NO; return NO;
} }

View file

@ -687,12 +687,6 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
strerror(errno)]; strerror(errno)];
} }
if (count == 0)
{
len = 0; /* End-of-file */
}
else
{
if (count > sizeof(buf)) if (count > sizeof(buf))
{ {
count = sizeof(buf); count = sizeof(buf);
@ -702,7 +696,6 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
[d appendBytes: buf length: len]; [d appendBytes: buf length: len];
} }
} }
}
if (len < 0) if (len < 0)
{ {
[NSException raise: NSFileHandleOperationException [NSException raise: NSFileHandleOperationException