mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
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:
parent
51fe7f149c
commit
9e3c780110
3 changed files with 158 additions and 92 deletions
|
@ -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.
|
||||||
|
|
|
@ -100,22 +100,25 @@ currentList()
|
||||||
|
|
||||||
+ (void) registerQueue: (NSNotificationQueue*)q
|
+ (void) registerQueue: (NSNotificationQueue*)q
|
||||||
{
|
{
|
||||||
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());
|
||||||
|
@ -125,10 +128,7 @@ currentList()
|
||||||
|
|
||||||
+ (void) unregisterQueue: (NSNotificationQueue*)q
|
+ (void) unregisterQueue: (NSNotificationQueue*)q
|
||||||
{
|
{
|
||||||
NotificationQueueList* list;
|
NotificationQueueList *list;
|
||||||
|
|
||||||
if (q == nil)
|
|
||||||
return;
|
|
||||||
|
|
||||||
list = currentList();
|
list = currentList();
|
||||||
|
|
||||||
|
@ -139,13 +139,15 @@ currentList()
|
||||||
d = GSCurrentThreadDictionary();
|
d = GSCurrentThreadDictionary();
|
||||||
if (list->next)
|
if (list->next)
|
||||||
{
|
{
|
||||||
NotificationQueueList* tmp = list->next;
|
NotificationQueueList *tmp = list->next;
|
||||||
|
|
||||||
[d setObject: tmp forKey: tkey];
|
[d setObject: tmp forKey: tkey];
|
||||||
RELEASE(tmp); /* retained in dictionary. */
|
RELEASE(tmp); /* retained in dictionary. */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
[d removeObjectForKey: tkey];
|
{
|
||||||
|
[d removeObjectForKey: tkey];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -153,7 +155,7 @@ currentList()
|
||||||
{
|
{
|
||||||
if (list->next->queue == q)
|
if (list->next->queue == q)
|
||||||
{
|
{
|
||||||
NotificationQueueList* tmp = list->next;
|
NotificationQueueList *tmp = list->next;
|
||||||
|
|
||||||
list->next = tmp->next;
|
list->next = tmp->next;
|
||||||
RELEASE(tmp);
|
RELEASE(tmp);
|
||||||
|
@ -171,20 +173,20 @@ currentList()
|
||||||
|
|
||||||
typedef struct _NSNotificationQueueRegistration
|
typedef struct _NSNotificationQueueRegistration
|
||||||
{
|
{
|
||||||
struct _NSNotificationQueueRegistration* next;
|
struct _NSNotificationQueueRegistration *next;
|
||||||
struct _NSNotificationQueueRegistration* prev;
|
struct _NSNotificationQueueRegistration *prev;
|
||||||
NSNotification* notification;
|
NSNotification *notification;
|
||||||
id name;
|
id name;
|
||||||
id object;
|
id object;
|
||||||
NSArray* modes;
|
NSArray *modes;
|
||||||
} NSNotificationQueueRegistration;
|
} NSNotificationQueueRegistration;
|
||||||
|
|
||||||
struct _NSNotificationQueueList;
|
struct _NSNotificationQueueList;
|
||||||
|
|
||||||
typedef struct _NSNotificationQueueList
|
typedef struct _NSNotificationQueueList
|
||||||
{
|
{
|
||||||
struct _NSNotificationQueueRegistration* head;
|
struct _NSNotificationQueueRegistration *head;
|
||||||
struct _NSNotificationQueueRegistration* tail;
|
struct _NSNotificationQueueRegistration *tail;
|
||||||
} NSNotificationQueueList;
|
} NSNotificationQueueList;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -197,9 +199,8 @@ 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,9 +256,13 @@ 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);
|
||||||
|
@ -335,44 +346,85 @@ add_to_queue(
|
||||||
- (void) dequeueNotificationsMatching: (NSNotification*)notification
|
- (void) dequeueNotificationsMatching: (NSNotification*)notification
|
||||||
coalesceMask: (NSNotificationCoalescing)coalesceMask
|
coalesceMask: (NSNotificationCoalescing)coalesceMask
|
||||||
{
|
{
|
||||||
NSNotificationQueueRegistration* item;
|
NSNotificationQueueRegistration *item;
|
||||||
NSNotificationQueueRegistration* next;
|
NSNotificationQueueRegistration *next;
|
||||||
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)
|
||||||
for (item = _asapQueue->tail; item; item=next)
|
&& (coalesceMask & NSNotificationCoalescingOnSender))
|
||||||
{
|
{
|
||||||
next = item->next;
|
/*
|
||||||
if ((coalesceMask & NSNotificationCoalescingOnName)
|
* find in ASAP notification in queue matching both
|
||||||
&& [name isEqual: item->name])
|
*/
|
||||||
|
for (item = _asapQueue->tail; item; item = next)
|
||||||
{
|
{
|
||||||
remove_from_queue(_asapQueue, item, _zone);
|
next = item->next;
|
||||||
continue;
|
if ((object == item->object) && [name isEqual: item->name])
|
||||||
|
{
|
||||||
|
remove_from_queue(_asapQueue, item, _zone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((coalesceMask & NSNotificationCoalescingOnSender)
|
/*
|
||||||
&& (object == item->object))
|
* find in idle notification in queue matching both
|
||||||
|
*/
|
||||||
|
for (item = _idleQueue->tail; item; item = next)
|
||||||
{
|
{
|
||||||
remove_from_queue(_asapQueue, item, _zone);
|
next = item->next;
|
||||||
continue;
|
if ((object == item->object) && [name isEqual: item->name])
|
||||||
|
{
|
||||||
|
remove_from_queue(_idleQueue, item, _zone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ((coalesceMask & NSNotificationCoalescingOnName))
|
||||||
// find in idle notification in queue
|
|
||||||
for (item = _idleQueue->tail; item; item=next)
|
|
||||||
{
|
{
|
||||||
next = item->next;
|
/*
|
||||||
if ((coalesceMask & NSNotificationCoalescingOnName)
|
* find in ASAP notification in queue matching name
|
||||||
&& [name isEqual: item->name])
|
*/
|
||||||
|
for (item = _asapQueue->tail; item; item = next)
|
||||||
{
|
{
|
||||||
remove_from_queue(_asapQueue, item, _zone);
|
next = item->next;
|
||||||
continue;
|
if ([name isEqual: item->name])
|
||||||
|
{
|
||||||
|
remove_from_queue(_asapQueue, item, _zone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((coalesceMask & NSNotificationCoalescingOnSender)
|
/*
|
||||||
&& (object == item->object))
|
* find in idle notification in queue matching name
|
||||||
|
*/
|
||||||
|
for (item = _idleQueue->tail; item; item = next)
|
||||||
{
|
{
|
||||||
remove_from_queue(_asapQueue, item, _zone);
|
next = item->next;
|
||||||
continue;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,8 +492,8 @@ static inline void notifyASAP(NSNotificationQueue *q)
|
||||||
while (list->head)
|
while (list->head)
|
||||||
{
|
{
|
||||||
NSNotificationQueueRegistration *item = list->head;
|
NSNotificationQueueRegistration *item = list->head;
|
||||||
NSNotification *notification = item->notification;
|
NSNotification *notification = item->notification;
|
||||||
NSArray *modes = item->modes;
|
NSArray *modes = item->modes;
|
||||||
|
|
||||||
remove_from_queue_no_release(list, item);
|
remove_from_queue_no_release(list, item);
|
||||||
[q postNotification: notification forModes: modes];
|
[q postNotification: notification forModes: modes];
|
||||||
|
@ -457,8 +509,12 @@ GSNotifyASAP()
|
||||||
NotificationQueueList *item;
|
NotificationQueueList *item;
|
||||||
|
|
||||||
for (item = currentList(); item; item = item->next)
|
for (item = currentList(); item; item = item->next)
|
||||||
if (item->queue)
|
{
|
||||||
notifyASAP(item->queue);
|
if (item->queue)
|
||||||
|
{
|
||||||
|
notifyASAP(item->queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void notifyIdle(NSNotificationQueue *q)
|
static inline void notifyIdle(NSNotificationQueue *q)
|
||||||
|
@ -471,8 +527,8 @@ static inline void notifyIdle(NSNotificationQueue *q)
|
||||||
if (list->head)
|
if (list->head)
|
||||||
{
|
{
|
||||||
NSNotificationQueueRegistration *item = list->head;
|
NSNotificationQueueRegistration *item = list->head;
|
||||||
NSNotification *notification = item->notification;
|
NSNotification *notification = item->notification;
|
||||||
NSArray *modes = item->modes;
|
NSArray *modes = item->modes;
|
||||||
|
|
||||||
remove_from_queue_no_release(list, item);
|
remove_from_queue_no_release(list, item);
|
||||||
[q postNotification: notification forModes: modes];
|
[q postNotification: notification forModes: modes];
|
||||||
|
@ -492,8 +548,12 @@ GSNotifyIdle()
|
||||||
NotificationQueueList *item;
|
NotificationQueueList *item;
|
||||||
|
|
||||||
for (item = currentList(); item; item = item->next)
|
for (item = currentList(); item; item = item->next)
|
||||||
if (item->queue)
|
{
|
||||||
notifyIdle(item->queue);
|
if (item->queue)
|
||||||
|
{
|
||||||
|
notifyIdle(item->queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
|
@ -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)
|
{
|
||||||
return YES;
|
if (item->queue && ((accessQueue)item->queue)->_idleQueue->head)
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -687,20 +687,13 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
strerror(errno)];
|
strerror(errno)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count == 0)
|
if (count > sizeof(buf))
|
||||||
{
|
{
|
||||||
len = 0; /* End-of-file */
|
count = sizeof(buf);
|
||||||
}
|
}
|
||||||
else
|
if ((len = read(descriptor, buf, count)) > 0)
|
||||||
{
|
{
|
||||||
if (count > sizeof(buf))
|
[d appendBytes: buf length: len];
|
||||||
{
|
|
||||||
count = sizeof(buf);
|
|
||||||
}
|
|
||||||
if ((len = read(descriptor, buf, count)) > 0)
|
|
||||||
{
|
|
||||||
[d appendBytes: buf length: len];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue