ObjFW  Diff

Differences From Artifact [8054f8aa66]:

  • File src/OFKernelEventObserver.m — part of check-in [c5f0c5f9ba] at 2015-12-29 21:42:38 on branch 0.8 — Refactor OFKernelEventObserver

    This moves the locked queue for actions to
    OFKernelEventObserver_LockedQueue, which is now used for select and
    poll, but skipped for kqueue and epoll, as they natively support changes
    from another thread.

    This fixes the problem that removing an object is delayed until the next
    observe call - at which point it might have already been closed, meaning
    the fd is no longer available. This was mainly a problem with kqueue, as
    closing the fd already removed it from the kqueue, which then resulted
    in an error being returned when trying to manually remove the fd from
    the kqueue. (user: js, size: 5343) [annotate] [blame] [check-ins using]

To Artifact [5076db7548]:


23
24
25
26
27
28
29



30
31
32
33
34
35
36
#import "OFArray.h"
#import "OFStream.h"
#import "OFStream+Private.h"
#ifndef OF_HAVE_PIPE
# import "OFStreamSocket.h"
#endif
#import "OFDate.h"




#ifdef HAVE_KQUEUE
# import "OFKernelEventObserver_kqueue.h"
#endif
#ifdef HAVE_EPOLL
# import "OFKernelEventObserver_epoll.h"
#endif







>
>
>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "OFArray.h"
#import "OFStream.h"
#import "OFStream+Private.h"
#ifndef OF_HAVE_PIPE
# import "OFStreamSocket.h"
#endif
#import "OFDate.h"
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif

#ifdef HAVE_KQUEUE
# import "OFKernelEventObserver_kqueue.h"
#endif
#ifdef HAVE_EPOLL
# import "OFKernelEventObserver_epoll.h"
#endif
129
130
131
132
133
134
135




136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151




152
153
154
155
156
157
158
		cancelAddrLen = sizeof(_cancelAddr);
		if (of_getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
		    &cancelAddrLen) != 0)
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];
# endif
#endif




	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	close(_cancelFD[0]);
	if (_cancelFD[1] != _cancelFD[0])
		close(_cancelFD[1]);

	[_readObjects release];
	[_writeObjects release];





	[super dealloc];
}

- (id <OFKernelEventObserverDelegate>)delegate
{
	return _delegate;







>
>
>
>
















>
>
>
>







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
		cancelAddrLen = sizeof(_cancelAddr);
		if (of_getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
		    &cancelAddrLen) != 0)
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];
# endif
#endif

#ifdef OF_HAVE_THREADS
		_mutex = [[OFMutex alloc] init];
#endif
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	close(_cancelFD[0]);
	if (_cancelFD[1] != _cancelFD[0])
		close(_cancelFD[1]);

	[_readObjects release];
	[_writeObjects release];

#ifdef OF_HAVE_THREADS
	[_mutex release];
#endif

	[super dealloc];
}

- (id <OFKernelEventObserverDelegate>)delegate
{
	return _delegate;