ObjFW  Check-in [b7767021ca]

Overview
Comment:Handle stream exceptions in OFStreamObserver.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b7767021ca3ac1b191b7d330f545a312b084f8227a8a92108d6517a7d6e57b38
User & Date: js on 2010-11-06 13:34:41
Other Links: manifest | tags
Context
2010-11-06
13:36
Correctly use FD_COPY. check-in: 1fceb27c0e user: js tags: trunk
13:34
Handle stream exceptions in OFStreamObserver. check-in: b7767021ca user: js tags: trunk
11:44
More reliable cleanup on failure in OFMutex and OFTLSKey. check-in: f1d813ef6a user: js tags: trunk
Changes

Modified src/OFStreamObserver.h from [ef35b95705] to [1bd2857348].

55
56
57
58
59
60
61


62
63
64
65
66
67
68
 * \param stream The stream on which an exception occurred
 */
- (void)streamDidReceiveException: (OFStream*)stream;
@end

/**
 * \brief A class that can observe multiple streams at once.


 */
@interface OFStreamObserver: OFObject
{
	OFMutableArray *readStreams;
	OFMutableArray *writeStreams;
	id <OFStreamObserverDelegate> delegate;
#ifdef OF_HAVE_POLL







>
>







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 * \param stream The stream on which an exception occurred
 */
- (void)streamDidReceiveException: (OFStream*)stream;
@end

/**
 * \brief A class that can observe multiple streams at once.
 *
 * Note: Currently, it can only observe sockets on Win32.
 */
@interface OFStreamObserver: OFObject
{
	OFMutableArray *readStreams;
	OFMutableArray *writeStreams;
	id <OFStreamObserverDelegate> delegate;
#ifdef OF_HAVE_POLL

Modified src/OFStreamObserver.m from [269a665b2b] to [2971c119f2].

274
275
276
277
278
279
280






281
282
283
284
285
286
287
		}

		if (fds_c[i].revents & POLLOUT) {
			num = [OFNumber numberWithInt: fds_c[i].fd];
			stream = [fdToStream objectForKey: num];
			[delegate streamDidBecomeReadyForReading: stream];
		}







		fds_c[i].revents = 0;
	}
#else
# ifdef FD_COPY
	FD_COPY(readfds, readfds_);
	FD_COPY(writefds, writefds_);







>
>
>
>
>
>







274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
		}

		if (fds_c[i].revents & POLLOUT) {
			num = [OFNumber numberWithInt: fds_c[i].fd];
			stream = [fdToStream objectForKey: num];
			[delegate streamDidBecomeReadyForReading: stream];
		}

		if (fds_c[i].revents & POLLERR) {
			num = [OFNumber numberWithInt: fds_c[i].fd];
			stream = [fdToStream objectForKey: num];
			[delegate streamDidReceiveException: stream];
		}

		fds_c[i].revents = 0;
	}
#else
# ifdef FD_COPY
	FD_COPY(readfds, readfds_);
	FD_COPY(writefds, writefds_);
297
298
299
300
301
302
303










304
305
306
307
308
309
310
311
312
313



314
315
316
317
318
319
320
		return NO;

	for (i = 0; i < count; i++) {
		int fd = [cArray[i] fileDescriptor];

		if (FD_ISSET(fd, &readfds_))
			[delegate streamDidBecomeReadyForReading: cArray[i]];










	}

	cArray = [writeStreams cArray];
	count = [writeStreams count];

	for (i = 0; i < count; i++) {
		int fd = [cArray[i] fileDescriptor];

		if (FD_ISSET(fd, &writefds_))
			[delegate streamDidBecomeReadyForWriting: cArray[i]];



	}
#endif

	[pool release];

	return YES;
}







>
>
>
>
>
>
>
>
>
>










>
>
>







303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
		return NO;

	for (i = 0; i < count; i++) {
		int fd = [cArray[i] fileDescriptor];

		if (FD_ISSET(fd, &readfds_))
			[delegate streamDidBecomeReadyForReading: cArray[i]];

		if (FD_ISSET(fd, &exceptfds_)) {
			[delegate streamDidReceiveException: cArray[i]];

			/*
			 * Prevent calling it twice in case the fd is in both
			 * sets.
			 */
			FD_CLR(fd, &exceptfds_);
		}
	}

	cArray = [writeStreams cArray];
	count = [writeStreams count];

	for (i = 0; i < count; i++) {
		int fd = [cArray[i] fileDescriptor];

		if (FD_ISSET(fd, &writefds_))
			[delegate streamDidBecomeReadyForWriting: cArray[i]];

		if (FD_ISSET(fd, &exceptfds_))
			[delegate streamDidReceiveException: cArray[i]];
	}
#endif

	[pool release];

	return YES;
}