ObjFW  Check-in [af9e349898]

Overview
Comment:Two new exceptions; fix 3 FIXMEs in OFTCPSocket.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: af9e3498984cb42e24f7e91cc5e0f78356a55d5548ccb3e45b1495d7c0b0276e
User & Date: js on 2008-12-14 01:45:40
Other Links: manifest | tags
Context
2008-12-14
02:01
Define functions unavailable on win32 and nop them there. check-in: 61bbbc20ff user: js tags: trunk
01:45
Two new exceptions; fix 3 FIXMEs in OFTCPSocket. check-in: af9e349898 user: js tags: trunk
2008-12-13
23:11
Fix two more FIXMEs in OFTCPSocket; new exception. check-in: ec3c199d1a user: js tags: trunk
Changes

Modified src/OFExceptions.h from [9bfba73e23] to [c079798d1b].

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
@interface OFAddressTranslationFailedException: OFException
{
	char *node;
	char *service;
}

/**

 * \param n The node for which translation was requested
 * \param s The service of the node for which translation was requested
 * \return A new address translation failed exception
 */
+ newWithObject: (id)obj
	andNode: (const char*)n
     andService: (const char*)s;

/**
 * Initializes an already allocated address translation failed exception.
 *

 * \param n The node for which translation was requested
 * \param s The service of the node for which translation was requested
 * \return An initialized address translation failed exception
 */
- initWithObject: (id)obj
	 andNode: (const char*)n
      andService: (const char*)s;







>











>







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
@interface OFAddressTranslationFailedException: OFException
{
	char *node;
	char *service;
}

/**
 * \param obj The object which caused the exception
 * \param n The node for which translation was requested
 * \param s The service of the node for which translation was requested
 * \return A new address translation failed exception
 */
+ newWithObject: (id)obj
	andNode: (const char*)n
     andService: (const char*)s;

/**
 * Initializes an already allocated address translation failed exception.
 *
 * \param obj The object which caused the exception
 * \param n The node for which translation was requested
 * \param s The service of the node for which translation was requested
 * \return An initialized address translation failed exception
 */
- initWithObject: (id)obj
	 andNode: (const char*)n
      andService: (const char*)s;
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
@interface OFConnectionFailedException: OFException
{
	char *host;
	uint16_t port;
}

/**

 * \param h The host to which the connection failed
 * \param p The port on the host to which the connection failed
 * \return A new connection failed exception
 */
+ newWithObject: (id)obj
	andHost: (const char*)h
	andPort: (uint16_t)p;

/**
 * Initializes an already allocated connection failed exception.
 *

 * \param h The host to which the connection failed
 * \param p The port on the host to which the connection failed
 * \return An initialized connection failed exception
 */
- initWithObject: (id)obj
	 andHost: (const char*)h
	 andPort: (uint16_t)p;







>











>







364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
@interface OFConnectionFailedException: OFException
{
	char *host;
	uint16_t port;
}

/**
 * \param obj The object which caused the exception
 * \param h The host to which the connection failed
 * \param p The port on the host to which the connection failed
 * \return A new connection failed exception
 */
+ newWithObject: (id)obj
	andHost: (const char*)h
	andPort: (uint16_t)p;

/**
 * Initializes an already allocated connection failed exception.
 *
 * \param obj The object which caused the exception
 * \param h The host to which the connection failed
 * \param p The port on the host to which the connection failed
 * \return An initialized connection failed exception
 */
- initWithObject: (id)obj
	 andHost: (const char*)h
	 andPort: (uint16_t)p;
410
411
412
413
414
415
416

417
418
419
420
421
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
{
	char *host;
	uint16_t port;
	int family;
}

/**

 * \param h The host on which binding failed
 * \param p The port on which binding failed
 * \param f The family for which binnding failed
 * \return A new bind failed exception
 */
+ newWithObject: (id)obj
	andHost: (const char*)h
	andPort: (uint16_t)p
      andFamily: (int)f;

/**
 * Initializes an already allocated bind failed exception.
 *

 * \param h The host on which binding failed
 * \param p The port on which binding failed
 * \param f The family for which binnding failed
 * \return An initialized bind failed exception
 */
- initWithObject: (id)obj
	 andHost: (const char*)h







>













>







414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
{
	char *host;
	uint16_t port;
	int family;
}

/**
 * \param obj The object which caused the exception
 * \param h The host on which binding failed
 * \param p The port on which binding failed
 * \param f The family for which binnding failed
 * \return A new bind failed exception
 */
+ newWithObject: (id)obj
	andHost: (const char*)h
	andPort: (uint16_t)p
      andFamily: (int)f;

/**
 * Initializes an already allocated bind failed exception.
 *
 * \param obj The object which caused the exception
 * \param h The host on which binding failed
 * \param p The port on which binding failed
 * \param f The family for which binnding failed
 * \return An initialized bind failed exception
 */
- initWithObject: (id)obj
	 andHost: (const char*)h
455
456
457
458
459
460
461















































- (uint16_t)port;

/**
 * \return The family for which binding failed
 */
- (int)family;
@end






















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
- (uint16_t)port;

/**
 * \return The family for which binding failed
 */
- (int)family;
@end

/**
 * An OFException indicating that listening on the socket failed.
 */
@interface OFListenFailedException: OFException
{
	int backlog;
}

/**
 * \param obj The object which caused the exception
 * \param b The requested size of the back log
 * \return A new listen failed exception
 */
+ newWithObject: (id)obj
     andBackLog: (int)b;

/**
 * Initializes an already allocated listen failed exception
 *
 * \param obj The object which caused the exception
 * \param b The requested size of the back log
 * \return An initialized listen failed exception
 */
- initWithObject: (id)obj
      andBackLog: (int)b;

/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;

/**
 * \return The requested back log.
 */
- (int)backLog;
@end

/**
 * An OFException indicating that accepting a connection failed.
 */
@interface OFAcceptFailedException: OFException {}
/**
 * \return An error message for the exception as a C string.
 */
- (const char*)cString;
@end

Modified src/OFExceptions.m from [0baa314b8c] to [e8e748fa8d].

515
516
517
518
519
520
521















































}

- (int)family
{
	return family;
}
@end






















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
}

- (int)family
{
	return family;
}
@end

@implementation OFListenFailedException
+ newWithObject: (id)obj
     andBackLog: (int)b
{
	return [[self alloc] initWithObject: obj
				 andBackLog: b];
}

- initWithObject: (id)obj
      andBackLog: (int)b
{
	if ((self = [super initWithObject: obj]))
		backlog = b;

	return self;
}

- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Failed to listen in socket of type %s with a back "
	    "log of %d!", [object name], backlog);

	return string;
}

- (int)backLog
{
	return backlog;
}
@end

@implementation OFAcceptFailedException
- (const char*)cString
{
	if (string != NULL)
		return string;

	asprintf(&string, "Failed to accept connection in socket of type %s!",
	    [object name]);

	return string;
}
@end

Modified src/OFTCPSocket.m from [4835d59f11] to [014fa32cf3].

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
}

- listenWithBackLog: (int)backlog
{
	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	if (listen(sock, backlog) < 0 ) {
		/* FIXME: Throw exception */
		return nil;
	}

	return self;
}

- listen
{
	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	if (listen(sock, 5) < 0 ) {
		/* FIXME: Throw exception */
		return nil;
	}

	return self;
}

- (OFTCPSocket*)accept
{
	OFTCPSocket *newsock;







|
|
|
<









|
|
|
<







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
}

- listenWithBackLog: (int)backlog
{
	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	if (listen(sock, backlog) < 0)
		@throw [OFListenFailedException newWithObject: self
						   andBackLog: backlog];


	return self;
}

- listen
{
	if (sock < 0)
		@throw [OFNotConnectedException newWithObject: self];

	if (listen(sock, 5) < 0)
		@throw [OFListenFailedException newWithObject: self
						   andBackLog: 5];


	return self;
}

- (OFTCPSocket*)accept
{
	OFTCPSocket *newsock;
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
		addr = [newsock getMemWithSize: sizeof(struct sockaddr)];
	} @catch(id e) {
		[newsock free];
		@throw e;
	}

	if ((s = accept(sock, addr, &addrlen)) < 0) {

		/* FIXME: Throw exception */
		return nil;
	}

	[newsock setSocket: s];
	[newsock setSocketAddress: addr
		       withLength: addrlen];

	return newsock;







>
|
<







186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
		addr = [newsock getMemWithSize: sizeof(struct sockaddr)];
	} @catch(id e) {
		[newsock free];
		@throw e;
	}

	if ((s = accept(sock, addr, &addrlen)) < 0) {
		[newsock free];
		@throw [OFAcceptFailedException newWithObject: self];

	}

	[newsock setSocket: s];
	[newsock setSocketAddress: addr
		       withLength: addrlen];

	return newsock;