ObjFW  Check-in [fb95acc8ab]

Overview
Comment:More style improvements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fb95acc8abcde52095b08dac37e204366d0d33d7692dd35da74399620da9f3ed
User & Date: js on 2011-04-22 21:08:30
Other Links: manifest | tags
Context
2011-04-22
21:59
OFURL: Do -[copy] in a try block to prevent leaks. check-in: 22ee389a21 user: js tags: trunk
21:08
More style improvements. check-in: fb95acc8ab user: js tags: trunk
20:43
OFStreamObserver: Don't ignore the timeout when using select(). check-in: 4b08544ddd user: js tags: trunk
Changes

Modified src/OFPlugin.m from [1a436fda73] to [ce104d5d58].

38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64
65







-
+











-
-
+
+








@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{
	OFAutoreleasePool *pool;
	OFMutableString *file;
	of_plugin_handle_t handle;
	OFPlugin *(*init_plugin)();
	OFPlugin *(*initPlugin)();
	OFPlugin *plugin;

	pool = [[OFAutoreleasePool alloc] init];
	file = [OFMutableString stringWithString: path];
	[file appendCString: PLUGIN_SUFFIX];

	if ((handle = dlopen([file cString], RTLD_LAZY)) == NULL)
		@throw [OFInitializationFailedException newWithClass: self];

	[pool release];

	init_plugin = (OFPlugin*(*)())dlsym(handle, "init_plugin");
	if (init_plugin == NULL || (plugin = init_plugin()) == nil) {
	initPlugin = (OFPlugin*(*)())dlsym(handle, "init_plugin");
	if (initPlugin == NULL || (plugin = initPlugin()) == nil) {
		dlclose(handle);
		@throw [OFInitializationFailedException newWithClass: self];
	}

	plugin->handle = handle;
	return plugin;
}

Modified src/OFStreamObserver.h from [ad26e6202d] to [923c073c02].

77
78
79
80
81
82
83
84
85


86
87
88
89
90




91
92

93
94
95
96
97
98
99
77
78
79
80
81
82
83


84
85
86




87
88
89
90
91

92
93
94
95
96
97
98
99







-
-
+
+

-
-
-
-
+
+
+
+

-
+







@interface OFStreamObserver: OFObject
{
	OFMutableArray *readStreams;
	OFMutableArray *writeStreams;
	OFMutableArray *queue, *queueInfo;
	id <OFStreamObserverDelegate> delegate;
#ifdef OF_HAVE_POLL
	OFDataArray *fds;
	OFMutableDictionary *fdToStream;
	OFDataArray *FDs;
	OFMutableDictionary *FDToStream;
#else
	fd_set readfds;
	fd_set writefds;
	fd_set exceptfds;
	int nfds;
	fd_set readFDs;
	fd_set writeFDs;
	fd_set exceptFDs;
	int nFDs;
#endif
	int cancelFd[2];
	int cancelFD[2];
#ifdef _WIN32
	struct sockaddr_in cancelAddr;
#endif
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFStreamObserverDelegate> delegate;

Modified src/OFStreamObserver.m from [4bdac00ac8] to [94e7d25075].

73
74
75
76
77
78
79
80

81
82

83
84
85
86
87
88
89

90
91
92
93
94
95
96
97


98
99
100


101
102
103
104
105
106
107
108
109
110


111
112
113
114
115
116
117

118
119
120
121
122
123
124
125


126
127
128


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
73
74
75
76
77
78
79

80
81

82
83
84
85
86
87
88

89
90
91
92
93
94
95


96
97
98


99
100
101
102
103
104
105
106
107
108


109
110
111
112
113
114
115
116

117
118
119
120
121
122
123


124
125
126


127
128
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







-
+

-
+






-
+






-
-
+
+

-
-
+
+








-
-
+
+






-
+






-
-
+
+

-
-
+
+











-
-
+
+







-
-
+
+







#endif

		readStreams = [[OFMutableArray alloc] init];
		writeStreams = [[OFMutableArray alloc] init];
		queue = [[OFMutableArray alloc] init];
		queueInfo = [[OFMutableArray alloc] init];
#ifdef OF_HAVE_POLL
		fds = [[OFDataArray alloc] initWithItemSize:
		FDs = [[OFDataArray alloc] initWithItemSize:
		    sizeof(struct pollfd)];
		fdToStream = [[OFMutableDictionary alloc] init];
		FDToStream = [[OFMutableDictionary alloc] init];
#else
		FD_ZERO(&readfds);
		FD_ZERO(&writefds);
#endif

#ifndef _WIN32
		if (pipe(cancelFd))
		if (pipe(cancelFD))
			@throw [OFInitializationFailedException
			    newWithClass: isa];
#else
		/* Make sure WSAStartup has been called */
		[OFTCPSocket class];

		cancelFd[0] = socket(AF_INET, SOCK_DGRAM, 0);
		cancelFd[1] = socket(AF_INET, SOCK_DGRAM, 0);
		cancelFD[0] = socket(AF_INET, SOCK_DGRAM, 0);
		cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0);

		if (cancelFd[0] == INVALID_SOCKET ||
		    cancelFd[1] == INVALID_SOCKET)
		if (cancelFD[0] == INVALID_SOCKET ||
		    cancelFD[1] == INVALID_SOCKET)
			@throw [OFInitializationFailedException
			    newWithClass: isa];

		cancelAddr.sin_family = AF_INET;
		cancelAddr.sin_port = 0;
		cancelAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
		cancelAddr2 = cancelAddr;

		if (bind(cancelFd[0], (struct sockaddr*)&cancelAddr,
		    sizeof(cancelAddr)) || bind(cancelFd[1],
		if (bind(cancelFD[0], (struct sockaddr*)&cancelAddr,
		    sizeof(cancelAddr)) || bind(cancelFD[1],
		    (struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2)))
			@throw [OFInitializationFailedException
			    newWithClass: isa];

		cancelAddrLen = sizeof(cancelAddr);

		if (getsockname(cancelFd[0], (struct sockaddr*)&cancelAddr,
		if (getsockname(cancelFD[0], (struct sockaddr*)&cancelAddr,
		    &cancelAddrLen))
			@throw [OFInitializationFailedException
			    newWithClass: isa];
#endif

#ifdef OF_HAVE_POLL
		p.fd = cancelFd[0];
		[fds addItem: &p];
		p.fd = cancelFD[0];
		[FDs addItem: &p];
#else
		FD_SET(cancelFd[0], &readfds);
		nfds = cancelFd[0] + 1;
		FD_SET(cancelFD[0], &readFDs);
		nFDs = cancelFD[0] + 1;
#endif
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	close(cancelFd[0]);
	close(cancelFd[1]);
	close(cancelFD[0]);
	close(cancelFD[1]);

	[(id)delegate release];
	[readStreams release];
	[writeStreams release];
	[queue release];
	[queueInfo release];
#ifdef OF_HAVE_POLL
	[fdToStream release];
	[fds release];
	[FDToStream release];
	[FDs release];
#endif

	[super dealloc];
}

- (id <OFStreamObserverDelegate>)delegate
{
165
166
167
168
169
170
171
172
173
174



175
176
177
178
179


180
181
182
183
184
185
186
187
188
189





190
191
192
193
194
195
196
197
198
199



200
201
202


203
204
205

206
207

208
209
210
211
212
213
214



215
216
217
218
219
220
221
222

223
224
225

226
227
228


229
230
231
232
233
234
235
236
237
238


239
240

241
242

243
244
245


246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282

283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

301
302

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

340
341

342
343
344
345


346
347
348
349

350
351

352
353
354
355


356
357
358
359
360

361
362

363
364
365
366
367



368
369
370
371
372

373
374

375
376
377
378
379



380
381
382
383
384
385
386
165
166
167
168
169
170
171



172
173
174
175
176
177


178
179
180
181
182
183
184
185




186
187
188
189
190
191
192
193
194
195
196
197



198
199
200
201


202
203
204
205

206
207

208
209
210
211
212



213
214
215
216
217
218
219
220
221
222

223
224
225

226
227


228
229
230
231
232
233
234
235
236
237


238
239
240

241
242

243
244


245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282

283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

301
302

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

340
341

342
343
344


345
346
347
348
349

350
351

352
353
354


355
356
357
358
359
360

361
362

363
364
365



366
367
368
369
370
371
372

373
374

375
376
377



378
379
380
381
382
383
384
385
386
387







-
-
-
+
+
+



-
-
+
+






-
-
-
-
+
+
+
+
+







-
-
-
+
+
+

-
-
+
+


-
+

-
+




-
-
-
+
+
+







-
+


-
+

-
-
+
+








-
-
+
+

-
+

-
+

-
-
+
+














-
+

-
+

















-
+

-
+

















-
+

-
+

















-
+

-
+









-
-
+
+



-
+

-
+

-
+


-
-
+
+



-
+

-
+


-
-
+
+




-
+

-
+


-
-
-
+
+
+




-
+

-
+


-
-
-
+
+
+







	delegate = delegate_;
}

#ifdef OF_HAVE_POLL
- (void)_addStream: (OFStream*)stream
	withEvents: (short)events
{
	struct pollfd *fds_c = [fds cArray];
	size_t i, count = [fds count];
	int fd = [stream fileDescriptor];
	struct pollfd *FDsCArray = [FDs cArray];
	size_t i, count = [FDs count];
	int fileDescriptor = [stream fileDescriptor];
	BOOL found = NO;

	for (i = 0; i < count; i++) {
		if (fds_c[i].fd == fd) {
			fds_c[i].events |= events;
		if (FDsCArray[i].fd == fileDescriptor) {
			FDsCArray[i].events |= events;
			found = YES;
		}
	}

	if (!found) {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		struct pollfd p = { fd, events | POLLERR, 0 };
		[fds addItem: &p];
		[fdToStream setObject: stream
			       forKey: [OFNumber numberWithInt: fd]];
		struct pollfd p = { fileDescriptor, events | POLLERR, 0 };
		[FDs addItem: &p];
		[FDToStream setObject: stream
			       forKey: [OFNumber numberWithInt:
				       fileDescriptor]];
		[pool release];
	}
}

- (void)_removeStream: (OFStream*)stream
	   withEvents: (short)events
{
	struct pollfd *fds_c = [fds cArray];
	size_t i, nfds = [fds count];
	int fd = [stream fileDescriptor];
	struct pollfd *FDsCArray = [FDs cArray];
	size_t i, nFDs = [FDs count];
	int fileDescriptor = [stream fileDescriptor];

	for (i = 0; i < nfds; i++) {
		if (fds_c[i].fd == fd) {
	for (i = 0; i < nFDs; i++) {
		if (FDsCArray[i].fd == fileDescriptor) {
			OFAutoreleasePool *pool;

			fds_c[i].events &= ~events;
			FDsCArray[i].events &= ~events;

			if ((fds_c[i].events & ~POLLERR) != 0)
			if ((FDsCArray[i].events & ~POLLERR) != 0)
				return;

			pool = [[OFAutoreleasePool alloc] init];

			[fds removeItemAtIndex: i];
			[fdToStream removeObjectForKey:
			    [OFNumber numberWithInt: fd]];
			[FDs removeItemAtIndex: i];
			[FDToStream removeObjectForKey:
			    [OFNumber numberWithInt: fileDescriptor]];

			[pool release];
		}
	}
}
#else
- (void)_addStream: (OFStream*)stream
	 withFDSet: (fd_set*)fdset
	 withFDSet: (fd_set*)FDSet
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	int fd = [stream fileDescriptor];
	int fileDescriptor = [stream fileDescriptor];

	FD_SET(fd, fdset);
	FD_SET(fd, &exceptfds);
	FD_SET(fileDescriptor, FDSet);
	FD_SET(fileDescriptor, &exceptFDs);

	if (fd >= nfds)
		nfds = fd + 1;

	[pool release];
}

- (void)_removeStream: (OFStream*)stream
	    withFDSet: (fd_set*)fdset
	   otherFDSet: (fd_set*)other_fdset
	    withFDSet: (fd_set*)FDSet
	   otherFDSet: (fd_set*)otherFDSet
{
	int fd = [stream fileDescriptor];
	int fileDescriptor = [stream fileDescriptor];

	FD_CLR(fd, fdset);
	FD_CLR(fileDescriptor, FDSet);

	if (!FD_ISSET(fd, other_fdset))
		FD_CLR(fd, &exceptfds);
	if (!FD_ISSET(fileDescriptor, otherFDSet))
		FD_CLR(fileDescriptor, &exceptfds);
}
#endif

- (void)addStreamToObserveForReading: (OFStream*)stream
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFNumber *qi = [OFNumber numberWithInt: QUEUE_ADD | QUEUE_READ];

	@synchronized (queue) {
		[queue addObject: stream];
		[queueInfo addObject: qi];
	}

#ifndef _WIN32
	assert(write(cancelFd[1], "", 1) > 0);
	assert(write(cancelFD[1], "", 1) > 0);
#else
	assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif

	[pool release];
}

- (void)addStreamToObserveForWriting: (OFStream*)stream
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFNumber *qi = [OFNumber numberWithInt: QUEUE_ADD | QUEUE_WRITE];

	@synchronized (queue) {
		[queue addObject: stream];
		[queueInfo addObject: qi];
	}

#ifndef _WIN32
	assert(write(cancelFd[1], "", 1) > 0);
	assert(write(cancelFD[1], "", 1) > 0);
#else
	assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif

	[pool release];
}

- (void)removeStreamToObserveForReading: (OFStream*)stream
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFNumber *qi = [OFNumber numberWithInt: QUEUE_REMOVE | QUEUE_READ];

	@synchronized (queue) {
		[queue addObject: stream];
		[queueInfo addObject: qi];
	}

#ifndef _WIN32
	assert(write(cancelFd[1], "", 1) > 0);
	assert(write(cancelFD[1], "", 1) > 0);
#else
	assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif

	[pool release];
}

- (void)removeStreamToObserveForWriting: (OFStream*)stream
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFNumber *qi = [OFNumber numberWithInt: QUEUE_REMOVE | QUEUE_WRITE];

	@synchronized (queue) {
		[queue addObject: stream];
		[queueInfo addObject: qi];
	}

#ifndef _WIN32
	assert(write(cancelFd[1], "", 1) > 0);
	assert(write(cancelFD[1], "", 1) > 0);
#else
	assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif

	[pool release];
}

- (void)_processQueue
{
	@synchronized (queue) {
		OFStream **queue_c = [queue cArray];
		OFNumber **queueInfo_c = [queueInfo cArray];
		OFStream **queueCArray = [queue cArray];
		OFNumber **queueInfoCArray = [queueInfo cArray];
		size_t i, count = [queue count];

		for (i = 0; i < count; i++) {
			switch ([queueInfo_c[i] intValue]) {
			switch ([queueInfoCArray[i] intValue]) {
			case QUEUE_ADD | QUEUE_READ:
				[readStreams addObject: queue_c[i]];
				[readStreams addObject: queueCArray[i]];
#ifdef OF_HAVE_POLL
				[self _addStream: queue_c[i]
				[self _addStream: queueCArray[i]
				      withEvents: POLLIN];
#else
				[self _addStream: queue_c[i]
				       withFDSet: &readfds];
				[self _addStream: queueCArray[i]
				       withFDSet: &readFDs];
#endif
				break;
			case QUEUE_ADD | QUEUE_WRITE:
				[writeStreams addObject: queue_c[i]];
				[writeStreams addObject: queueCArray[i]];
#ifdef OF_HAVE_POLL
				[self _addStream: queue_c[i]
				[self _addStream: queueCArray[i]
				      withEvents: POLLOUT];
#else
				[self _addStream: queue_c[i]
				       withFDSet: &writefds];
				[self _addStream: queueCArray[i]
				       withFDSet: &writeFDs];
#endif
				break;
			case QUEUE_REMOVE | QUEUE_READ:
				[readStreams removeObjectIdenticalTo:
				    queue_c[i]];
				    queueCArray[i]];
#ifdef OF_HAVE_POLL
				[self _removeStream: queue_c[i]
				[self _removeStream: queueCArray[i]
					 withEvents: POLLIN];
#else
				[self _removeStream: queue_c[i]
					  withFDSet: &readfds
					 otherFDSet: &writefds];
				[self _removeStream: queueCArray[i]
					  withFDSet: &readFDs
					 otherFDSet: &writeFDs];
#endif
				break;
			case QUEUE_REMOVE | QUEUE_WRITE:
				[writeStreams removeObjectIdenticalTo:
				    queue_c[i]];
				    queueCArray[i]];
#ifdef OF_HAVE_POLL
				[self _removeStream: queue_c[i]
				[self _removeStream: queueCArray[i]
					 withEvents: POLLOUT];
#else
				[self _removeStream: queue_c[i]
					  withFDSet: &writefds
					 otherFDSet: &readfds];
				[self _removeStream: queueCArray[i]
					  withFDSet: &writeFDs
					 otherFDSet: &readFDs];
#endif
				break;
			default:
				assert(0);
			}
		}

397
398
399
400
401
402
403
404
405


406
407
408
409
410




411
412
413
414
415
416
417
398
399
400
401
402
403
404


405
406
407




408
409
410
411
412
413
414
415
416
417
418







-
-
+
+

-
-
-
-
+
+
+
+







- (BOOL)observeWithTimeout: (int)timeout
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	BOOL foundInCache = NO;
	OFStream **cArray;
	size_t i, count;
#ifdef OF_HAVE_POLL
	struct pollfd *fds_c;
	size_t nfds;
	struct pollfd *FDsCArray;
	size_t nFDs;
#else
	fd_set readfds_;
	fd_set writefds_;
	fd_set exceptfds_;
	struct timeval tv;
	fd_set readFDs_;
	fd_set writeFDs_;
	fd_set exceptFDs_;
	struct timeval time;
#endif

	[self _processQueue];

	cArray = [readStreams cArray];
	count = [readStreams count];

427
428
429
430
431
432
433
434
435


436
437
438

439
440
441
442

443
444
445

446
447
448
449
450
451



452
453
454


455
456
457
458
459
460


461
462
463
464
465
466
467



468
469
470
471
472
473
474



475
476
477
478
479

480
481
482
483
484
485



486
487
488
489



490
491
492
493


494
495
496


497
498
499
500


501
502

503
504

505
506
507
508
509

510
511

512
513
514
515
516

517
518
519
520
521

522
523
524

525
526
527
528
529
530
531
532

533
534

535
536
537
538
539

540
541
542
543
544
545
546
428
429
430
431
432
433
434


435
436
437
438

439
440
441
442

443
444
445

446
447
448
449



450
451
452
453


454
455
456
457
458
459


460
461
462
463
464
465



466
467
468
469
470
471
472



473
474
475
476
477
478
479

480
481
482
483



484
485
486
487



488
489
490
491
492


493
494
495


496
497
498
499


500
501
502

503
504

505
506
507
508
509

510
511

512
513
514
515
516

517
518
519
520
521

522
523
524

525
526
527
528
529
530
531
532

533
534

535
536
537
538
539

540
541
542
543
544
545
546
547







-
-
+
+


-
+



-
+


-
+



-
-
-
+
+
+

-
-
+
+




-
-
+
+




-
-
-
+
+
+




-
-
-
+
+
+




-
+



-
-
-
+
+
+

-
-
-
+
+
+


-
-
+
+

-
-
+
+


-
-
+
+

-
+

-
+




-
+

-
+




-
+




-
+


-
+







-
+

-
+




-
+







	 * As long as we have data in the cache for any stream, we don't want
	 * to block.
	 */
	if (foundInCache)
		return YES;

#ifdef OF_HAVE_POLL
	fds_c = [fds cArray];
	nfds = [fds count];
	FDsCArray = [FDs cArray];
	nFDs = [FDs count];

# ifdef OPEN_MAX
	if (nfds > OPEN_MAX)
	if (nFDs > OPEN_MAX)
		@throw [OFOutOfRangeException newWithClass: isa];
# endif

	if (poll(fds_c, (nfds_t)nfds, timeout) < 1)
	if (poll(FDsCArray, (nfds_t)nFDs, timeout) < 1)
		return NO;

	for (i = 0; i < nfds; i++) {
	for (i = 0; i < nFDs; i++) {
		OFNumber *num;
		OFStream *stream;

		if (fds_c[i].revents & POLLIN) {
			if (fds_c[i].fd == cancelFd[0]) {
				char buf;
		if (FDsCArray[i].revents & POLLIN) {
			if (FDsCArray[i].fd == cancelFD[0]) {
				char buffer;

				assert(read(cancelFd[0], &buf, 1) > 0);
				fds_c[i].revents = 0;
				assert(read(cancelFD[0], &buffer, 1) > 0);
				FDsCArray[i].revents = 0;

				continue;
			}

			num = [OFNumber numberWithInt: fds_c[i].fd];
			stream = [fdToStream objectForKey: num];
			num = [OFNumber numberWithInt: FDsCArray[i].fd];
			stream = [FDToStream objectForKey: num];
			[delegate streamDidBecomeReadyForReading: stream];
			[pool releaseObjects];
		}

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

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

		fds_c[i].revents = 0;
		FDsCArray[i].revents = 0;
	}
#else
# ifdef FD_COPY
	FD_COPY(&readfds, &readfds_);
	FD_COPY(&writefds, &writefds_);
	FD_COPY(&exceptfds, &exceptfds_);
	FD_COPY(&readFDs, &readFDs_);
	FD_COPY(&writeFDs, &writeFDs_);
	FD_COPY(&exceptFDs, &exceptFDs_);
# else
	readfds_ = readfds;
	writefds_ = writefds;
	exceptfds_ = exceptfds;
	readFDs_ = readFDs;
	writeFDs_ = writeFDs;
	exceptFDs_ = exceptFDs;
# endif

	tv.tv_sec = timeout / 1000;
	tv.tv_usec = (timeout % 1000) * 1000;
	time.tv_sec = timeout / 1000;
	time.tv_usec = (timeout % 1000) * 1000;

	if (select(nfds, &readfds_, &writefds_, &exceptfds_,
	    (timeout != -1 ? &tv : NULL)) < 1)
	if (select(nFDs, &readFDs_, &writeFDs_, &exceptFDs_,
	    (timeout != -1 ? &time : NULL)) < 1)
		return NO;

	if (FD_ISSET(cancelFd[0], &readfds_)) {
		char buf;
	if (FD_ISSET(cancelFD[0], &readFDs_)) {
		char buffer;
#ifndef _WIN32
		assert(read(cancelFd[0], &buf, 1) > 0);
		assert(read(cancelFD[0], &buffer, 1) > 0);
#else
		assert(recvfrom(cancelFd[0], &buf, 1, 0, NULL, NULL) > 0);
		assert(recvfrom(cancelFD[0], &buffer, 1, 0, NULL, NULL) > 0);
#endif
	}

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

		if (FD_ISSET(fd, &readfds_)) {
		if (FD_ISSET(fileDescriptor, &readFDs_)) {
			[delegate streamDidBecomeReadyForReading: cArray[i]];
			[pool releaseObjects];
		}

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

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

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

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

		if (FD_ISSET(fd, &writefds_)) {
		if (FD_ISSET(fileDescriptor, &writeFDs_)) {
			[delegate streamDidBecomeReadyForWriting: cArray[i]];
			[pool releaseObjects];
		}

		if (FD_ISSET(fd, &exceptfds_)) {
		if (FD_ISSET(fileDescriptor, &exceptFDs_)) {
			[delegate streamDidReceiveException: cArray[i]];
			[pool releaseObjects];
		}
	}
#endif

	[pool release];

Modified src/OFString+URLEncoding.m from [5910a2a036] to [756001522a].

27
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53




54
55
56
57
58


59
60
61
62





63
64
65
66
67

68
69
70

71
72
73
74
75
76
77

78
79


80
81


82
83

84
85
86

87
88
89
90
91


92
93
94
95
96




97
98

99
100
101
102
103
104
105
106
107









108
109

110
111
112
113
114
115
116
117




118
119
120
121
122
123

124
125
126


127
128
129
130
131

132
133

134
135
136
137
27
28
29
30
31
32
33


34
35
36
37
38


39
40
41
42
43

44
45
46
47




48
49
50
51
52
53
54


55
56
57



58
59
60
61
62
63
64
65
66

67
68
69

70
71
72
73
74
75
76
77
78


79
80


81
82


83

84

85
86
87
88


89
90
91




92
93
94
95
96

97
98
99







100
101
102
103
104
105
106
107
108
109

110
111
112
113
114




115
116
117
118
119
120
121
122
123

124
125


126
127
128
129
130
131

132
133

134
135
136
137
138







-
-
+
+



-
-





-
+



-
-
-
-
+
+
+
+



-
-
+
+

-
-
-
+
+
+
+
+




-
+


-
+







+
-
-
+
+
-
-
+
+
-
-
+
-

-
+



-
-
+
+

-
-
-
-
+
+
+
+

-
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
+




-
-
-
-
+
+
+
+





-
+

-
-
+
+




-
+

-
+





/* Reference for static linking */
int _OFString_URLEncoding_reference;

@implementation OFString (URLEncoding)
- (OFString*)stringByURLEncoding
{
	const char *s;
	char *ret_c;
	const char *string_ = string;
	char *retCString;
	size_t i;
	OFString *ret;

	s = string;

	/*
	 * Worst case: 3 times longer than before.
	 * Oh, and we can't use [self allocWithSize:] here as self might be a
	 * @"" literal.
	 */
	if ((ret_c = malloc((length * 3) + 1)) == NULL)
	if ((retCString = malloc((length * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: (length * 3) + 1];

	for (i = 0; *s != '\0'; s++) {
		if (isalnum((int)*s) || *s == '-' || *s == '_' || *s == '.' ||
		    *s == '~')
			ret_c[i++] = *s;
	for (i = 0; *string_ != '\0'; string_++) {
		if (isalnum((int)*string_) || *string_ == '-' ||
		    *string_ == '_' || *string_ == '.' || *string_ == '~')
			retCString[i++] = *string_;
		else {
			uint8_t high, low;

			high = *s >> 4;
			low = *s & 0x0F;
			high = *string_ >> 4;
			low = *string_ & 0x0F;

			ret_c[i++] = '%';
			ret_c[i++] = (high > 9 ? high - 10 + 'A' : high + '0');
			ret_c[i++] = (low  > 9 ? low  - 10 + 'A' : low  + '0');
			retCString[i++] = '%';
			retCString[i++] =
			    (high > 9 ? high - 10 + 'A' : high + '0');
			retCString[i++] =
			    (low  > 9 ? low  - 10 + 'A' : low  + '0');
		}
	}

	@try {
		ret = [OFString stringWithCString: ret_c
		ret = [OFString stringWithCString: retCString
					   length: i];
	} @finally {
		free(ret_c);
		free(retCString);
	}

	return ret;
}

- (OFString*)stringByURLDecoding
{
	OFString *ret;
	const char *s;
	char *ret_c, c;
	const char *string_ = string;
	char *retCString;
	size_t i;
	int st;
	char byte = 0;
	int state = 0;
	OFString *ret;

	size_t i;
	s = string;

	if ((ret_c = malloc(length + 1)) == NULL)
	if ((retCString = malloc(length + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: length + 1];

	for (st = 0, i = 0, c = 0; *s; s++) {
		switch (st) {
	for (i = 0; *string_; string_++) {
		switch (state) {
		case 0:
			if (*s == '%')
				st = 1;
			else if (*s == '+')
				ret_c[i++] = ' ';
			if (*string_ == '%')
				state = 1;
			else if (*string_ == '+')
				retCString[i++] = ' ';
			else
				ret_c[i++] = *s;
				retCString[i++] = *string_;
			break;
		case 1:
		case 2:
			if (*s >= '0' && *s <= '9')
				c += (*s - '0') << (st == 1 ? 4 : 0);
			else if (*s >= 'A' && *s <= 'F')
				c += (*s - 'A' + 10) << (st == 1 ? 4 : 0);
			else if (*s >= 'a' && *s <= 'f')
				c += (*s - 'a' + 10) << (st == 1 ? 4 : 0);
		case 2:;
			uint8_t shift = (state == 1 ? 4  : 0);

			if (*string_ >= '0' && *string_ <= '9')
				byte += (*string_ - '0') << shift;
			else if (*string_ >= 'A' && *string_ <= 'F')
				byte += (*string_ - 'A' + 10) << shift;
			else if (*string_ >= 'a' && *string_ <= 'f')
				byte += (*string_ - 'a' + 10) << shift;
			else {
				free(ret_c);
				free(retCString);
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			if (++st == 3) {
				ret_c[i++] = c;
				st = 0;
				c = 0;
			if (++state == 3) {
				retCString[i++] = byte;
				state = 0;
				byte = 0;
			}

			break;
		}
	}
	ret_c[i] = '\0';
	retCString[i] = '\0';

	if (st) {
		free(ret_c);
	if (state != 0) {
		free(retCString);
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	@try {
		ret = [OFString stringWithCString: ret_c];
		ret = [OFString stringWithCString: retCString];
	} @finally {
		free(ret_c);
		free(retCString);
	}
	return ret;
}
@end

Modified src/OFString+XMLEscaping.m from [c2066f8693] to [bbfbe023ae].

25
26
27
28
29
30
31
32

33
34

35
36
37
38
39

40
41
42
43
44

45
46

47
48
49
50
51
52

53
54
55
56

57
58
59
60

61
62
63
64

65
66
67
68

69
70
71
72

73
74
75

76
77




78
79
80

81
82
83


84
85
86


87
88

89
90
91

92
93
94
95


96
97

98
99
100
101
25
26
27
28
29
30
31

32
33

34
35
36
37
38

39
40
41
42
43

44
45

46
47
48
49
50
51

52
53
54
55

56
57
58
59

60
61
62
63

64
65
66
67

68
69
70
71

72
73
74
75
76


77
78
79
80
81
82

83
84


85
86
87


88
89
90

91
92
93

94
95
96


97
98
99

100
101
102
103
104







-
+

-
+




-
+




-
+

-
+





-
+



-
+



-
+



-
+



-
+



-
+



+
-
-
+
+
+
+


-
+

-
-
+
+

-
-
+
+

-
+


-
+


-
-
+
+

-
+




#import "OFOutOfMemoryException.h"

int _OFString_XMLEscaping_reference;

@implementation OFString (XMLEscaping)
- (OFString*)stringByXMLEscaping
{
	char *str_c, *tmp;
	char *retCString;
	const char *append;
	size_t len, append_len;
	size_t retLength, appendLength;
	size_t i, j;
	OFString *ret;

	j = 0;
	len = length;
	retLength = length;

	/*
	 * We can't use allocMemoryWithSize: here as it might be a @"" literal
	 */
	if ((str_c = malloc(len)) == NULL)
	if ((retCString = malloc(retLength)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: len];
					      requestedSize: retLength];

	for (i = 0; i < length; i++) {
		switch (string[i]) {
			case '<':
				append = "&lt;";
				append_len = 4;
				appendLength = 4;
				break;
			case '>':
				append = "&gt;";
				append_len = 4;
				appendLength = 4;
				break;
			case '"':
				append = "&quot;";
				append_len = 6;
				appendLength = 6;
				break;
			case '\'':
				append = "&apos;";
				append_len = 6;
				appendLength = 6;
				break;
			case '&':
				append = "&amp;";
				append_len = 5;
				appendLength = 5;
				break;
			default:
				append = NULL;
				append_len = 0;
				appendLength = 0;
		}

		if (append != NULL) {
			char *newRetCString;
			if ((tmp = realloc(str_c, len + append_len)) == NULL) {
				free(str_c);

			if ((newRetCString = realloc(retCString,
			    retLength + appendLength)) == NULL) {
				free(retCString);
				@throw [OFOutOfMemoryException
				     newWithClass: isa
				    requestedSize: len + append_len];
				    requestedSize: retLength + appendLength];
			}
			str_c = tmp;
			len += append_len - 1;
			retCString = newRetCString;
			retLength += appendLength - 1;

			memcpy(str_c + j, append, append_len);
			j += append_len;
			memcpy(retCString + j, append, appendLength);
			j += appendLength;
		} else
			str_c[j++] = string[i];
			retCString[j++] = string[i];
	}

	assert(j == len);
	assert(j == retLength);

	@try {
		ret = [OFString stringWithCString: str_c
					   length: len];
		ret = [OFString stringWithCString: retCString
					   length: retLength];
	} @finally {
		free(str_c);
		free(retCString);
	}
	return ret;
}
@end

Modified src/OFString+XMLUnescaping.m from [ab5733ce2b] to [53b4061156].

28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42







-
+







int _OFString_XMLUnescaping_reference;

static OF_INLINE OFString*
parse_numeric_entity(const char *entity, size_t length)
{
	of_unichar_t c;
	size_t i;
	char buf[5];
	char buffer[5];

	if (length == 1 || *entity != '#')
		return nil;

	c = 0;
	entity++;
	length--;
63
64
65
66
67
68
69
70

71
72

73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92

93
94
95
96
97

98
99
100
101
102
103


104
105

106
107

108
109
110

111
112

113

114
115

116

117
118
119

120
121
122
123
124
125
126
127


128
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
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183
184
185

186
187
188
189
190

191
192
193
194
195
196


197
198

199
200

201
202
203

204
205

206

207
208

209

210
211
212

213
214
215
216
217
218
219
220


221
222
223
224
225
226
227
228
229
230

231
232
233

234
235
236



237
238
239
240
241
242
243
244
245
246
247

248
249
250
251

252
253
254
255
256
257
258
63
64
65
66
67
68
69

70
71

72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91

92
93
94
95
96

97
98
99
100
101


102
103
104

105
106

107
108
109

110
111
112
113

114
115
116
117

118
119
120

121
122
123
124
125
126
127
128

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
159

160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

184
185
186
187

188
189
190
191
192

193
194
195
196
197


198
199
200

201
202

203
204
205

206
207
208
209

210
211
212
213

214
215
216

217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240



241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257

258
259
260
261
262
263
264
265







-
+

-
+

-
+













-
+



-
+




-
+




-
-
+
+

-
+

-
+


-
+


+
-
+


+
-
+


-
+







-
+
+














-
+














-
+



-
+



















-
+



-
+




-
+




-
-
+
+

-
+

-
+


-
+


+
-
+


+
-
+


-
+







-
+
+









-
+



+
-
-
-
+
+
+










-
+



-
+







			if (entity[i] >= '0' && entity[i] <= '9')
				c = (c * 10) + (entity[i] - '0');
			else
				return nil;
		}
	}

	if ((i = of_string_unicode_to_utf8(c, buf)) == 0)
	if ((i = of_string_unicode_to_utf8(c, buffer)) == 0)
		return nil;
	buf[i] = 0;
	buffer[i] = 0;

	return [OFString stringWithCString: buf
	return [OFString stringWithCString: buffer
				    length: i];
}

@implementation OFString (XMLUnescaping)
- (OFString*)stringByXMLUnescaping
{
	return [self stringByXMLUnescapingWithDelegate: nil];
}

- (OFString*)stringByXMLUnescapingWithDelegate:
    (id <OFStringXMLUnescapingDelegate>)delegate
{
	size_t i, last;
	BOOL in_entity;
	BOOL inEntity;
	OFMutableString *ret;

	last = 0;
	in_entity = NO;
	inEntity = NO;
	ret = [OFMutableString string];
	((OFString*)ret)->isUTF8 = [self isUTF8];

	for (i = 0; i < length; i++) {
		if (!in_entity && string[i] == '&') {
		if (!inEntity && string[i] == '&') {
			[ret appendCStringWithoutUTF8Checking: string + last
						       length: i - last];

			last = i + 1;
			in_entity = YES;
		} else if (in_entity && string[i] == ';') {
			inEntity = YES;
		} else if (inEntity && string[i] == ';') {
			char *entity = string + last;
			size_t len = i - last;
			size_t entityLength = i - last;

			if (len == 2 && !memcmp(entity, "lt", 2))
			if (entityLength == 2 && !memcmp(entity, "lt", 2))
				[ret appendCStringWithoutUTF8Checking: "<"
							       length: 1];
			else if (len == 2 && !memcmp(entity, "gt", 2))
			else if (entityLength == 2 && !memcmp(entity, "gt", 2))
				[ret appendCStringWithoutUTF8Checking: ">"
							       length: 1];
			else if (entityLength == 4 &&
			else if (len == 4 && !memcmp(entity, "quot", 4))
			    !memcmp(entity, "quot", 4))
				[ret appendCStringWithoutUTF8Checking: "\""
							       length: 1];
			else if (entityLength == 4 &&
			else if (len == 4 && !memcmp(entity, "apos", 4))
			    !memcmp(entity, "apos", 4))
				[ret appendCStringWithoutUTF8Checking: "'"
							       length: 1];
			else if (len == 3 && !memcmp(entity, "amp", 3))
			else if (entityLength == 3 && !memcmp(entity, "amp", 3))
				[ret appendCStringWithoutUTF8Checking: "&"
							       length: 1];
			else if (entity[0] == '#') {
				OFAutoreleasePool *pool;
				OFString *tmp;

				pool = [[OFAutoreleasePool alloc] init];
				tmp = parse_numeric_entity(entity, len);
				tmp = parse_numeric_entity(entity,
				    entityLength);

				if (tmp == nil)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

				[ret appendString: tmp];
				[pool release];
			} else if (delegate != nil) {
				OFAutoreleasePool *pool;
				OFString *n, *tmp;

				pool = [[OFAutoreleasePool alloc] init];

				n = [OFString stringWithCString: entity
							 length: len];
							 length: entityLength];
				tmp =	  [delegate string: self
				containsUnknownEntityNamed: n];

				if (tmp == nil)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

				[ret appendString: tmp];
				[pool release];
			} else
				@throw [OFInvalidEncodingException
				    newWithClass: isa];

			last = i + 1;
			in_entity = NO;
			inEntity = NO;
		}
	}

	if (in_entity)
	if (inEntity)
		@throw [OFInvalidEncodingException newWithClass: isa];

	[ret appendCStringWithoutUTF8Checking: string + last
				       length: i - last];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	ret->isa = [OFString class];
	return ret;
}

#ifdef OF_HAVE_BLOCKS
- (OFString*)stringByXMLUnescapingWithBlock:
    (of_string_xml_unescaping_block_t)block
{
	size_t i, last;
	BOOL in_entity;
	BOOL inEntity;
	OFMutableString *ret;

	last = 0;
	in_entity = NO;
	inEntity = NO;
	ret = [OFMutableString string];
	((OFString*)ret)->isUTF8 = [self isUTF8];

	for (i = 0; i < length; i++) {
		if (!in_entity && string[i] == '&') {
		if (!inEntity && string[i] == '&') {
			[ret appendCStringWithoutUTF8Checking: string + last
						       length: i - last];

			last = i + 1;
			in_entity = YES;
		} else if (in_entity && string[i] == ';') {
			inEntity = YES;
		} else if (inEntity && string[i] == ';') {
			char *entity = string + last;
			size_t len = i - last;
			size_t entityLength = i - last;

			if (len == 2 && !memcmp(entity, "lt", 2))
			if (entityLength == 2 && !memcmp(entity, "lt", 2))
				[ret appendCStringWithoutUTF8Checking: "<"
							       length: 1];
			else if (len == 2 && !memcmp(entity, "gt", 2))
			else if (entityLength == 2 && !memcmp(entity, "gt", 2))
				[ret appendCStringWithoutUTF8Checking: ">"
							       length: 1];
			else if (entityLength == 4 &&
			else if (len == 4 && !memcmp(entity, "quot", 4))
			    !memcmp(entity, "quot", 4))
				[ret appendCStringWithoutUTF8Checking: "\""
							       length: 1];
			else if (entityLength == 4 &&
			else if (len == 4 && !memcmp(entity, "apos", 4))
			    !memcmp(entity, "apos", 4))
				[ret appendCStringWithoutUTF8Checking: "'"
							       length: 1];
			else if (len == 3 && !memcmp(entity, "amp", 3))
			else if (entityLength == 3 && !memcmp(entity, "amp", 3))
				[ret appendCStringWithoutUTF8Checking: "&"
							       length: 1];
			else if (entity[0] == '#') {
				OFAutoreleasePool *pool;
				OFString *tmp;

				pool = [[OFAutoreleasePool alloc] init];
				tmp = parse_numeric_entity(entity, len);
				tmp = parse_numeric_entity(entity,
				    entityLength);

				if (tmp == nil)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

				[ret appendString: tmp];
				[pool release];
			} else {
				OFAutoreleasePool *pool;
				OFString *n, *tmp;
				OFString *entityString, *tmp;

				pool = [[OFAutoreleasePool alloc] init];

				entityString = [OFString
				n = [OFString stringWithCString: entity
							 length: len];
				tmp = block(self, n);
				    stringWithCString: entity
					       length: entityLength];
				tmp = block(self, entityString);

				if (tmp == nil)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

				[ret appendString: tmp];
				[pool release];
			}

			last = i + 1;
			in_entity = NO;
			inEntity = NO;
		}
	}

	if (in_entity)
	if (inEntity)
		@throw [OFInvalidEncodingException newWithClass: isa];

	[ret appendCStringWithoutUTF8Checking: string + last
				       length: i - last];

	/*
	 * Class swizzle the string to be immutable. We declared the return type

Modified src/OFTCPSocket.h from [98f00d6f79] to [5adaf7382b].

63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







-
+







		onHost: (OFString*)host;

/**
 * Listen on the socket.
 *
 * \param backlog Maximum length for the queue of pending connections.
 */
- (void)listenWithBackLog: (int)backlog;
- (void)listenWithBackLog: (int)backLog;

/**
 * Listen on the socket.
 */
- (void)listen;

/**

Modified src/OFTCPSocket.m from [ea3cfe401f] to [1ec7691203].

313
314
315
316
317
318
319
320

321
322
323
324
325
326

327
328
329

330
331
332
333
334
335
336
313
314
315
316
317
318
319

320
321
322
323
324
325

326
327
328

329
330
331
332
333
334
335
336







-
+





-
+


-
+







	sock = INVALID_SOCKET;
	@throw [OFBindFailedException newWithClass: isa
					    socket: self
					      host: host
					      port: port];
}

- (void)listenWithBackLog: (int)backlog
- (void)listenWithBackLog: (int)backLog
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (listen(sock, backlog) == -1)
	if (listen(sock, backLog) == -1)
		@throw [OFListenFailedException newWithClass: isa
						      socket: self
						     backLog: backlog];
						     backLog: backLog];

	isListening = YES;
}

- (void)listen
{
	if (sock == INVALID_SOCKET)