12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
+
+
+
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#define __NO_EXT_QNX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#ifndef _WIN32
# include <netinet/in.h>
# include <arpa/inet.h>
|
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
|
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
|
-
+
+
-
+
|
isListening = YES;
}
- (OFTCPSocket*)accept
{
OFTCPSocket *newsock;
struct sockaddr *addr;
struct sockaddr_storage *addr;
socklen_t addrlen;
int s;
newsock = [[[isa alloc] init] autorelease];
addrlen = sizeof(struct sockaddr);
@try {
addr = [newsock allocMemoryWithSize: sizeof(struct sockaddr)];
} @catch (id e) {
[newsock release];
@throw e;
}
if ((s = accept(sock, (struct sockaddr*)addr,
if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) {
&addrlen)) == INVALID_SOCKET) {
[newsock release];
@throw [OFAcceptFailedException newWithClass: isa
socket: self];
}
newsock->sock = s;
newsock->sockAddr = addr;
|
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
-
-
+
+
|
@throw [OFInvalidArgumentException newWithClass: isa
selector: _cmd];
#ifdef HAVE_THREADSAFE_GETADDRINFO
char *host = [self allocMemoryWithSize: NI_MAXHOST];
@try {
if (getnameinfo(sockAddr, sockAddrLen, host, NI_MAXHOST, NULL,
0, NI_NUMERICHOST))
if (getnameinfo((struct sockaddr*)sockAddr, sockAddrLen, host,
NI_MAXHOST, NULL, 0, NI_NUMERICHOST))
@throw [OFAddressTranslationFailedException
newWithClass: isa];
return [OFString stringWithCString: host];
} @finally {
[self freeMemory: host];
}
|