1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* 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"
#ifndef _XOPEN_SOURCE_EXTENDED
# define _XOPEN_SOURCE_EXTENDED
#endif
#define _HPUX_ALT_XOPEN_SOCKET_API
#include <assert.h>
#include <errno.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#import "OFSequencedPacketSocket.h"
#import "OFSequencedPacketSocket+Private.h"
#import "OFData.h"
#import "OFRunLoop+Private.h"
#import "OFRunLoop.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAcceptFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFListenFailedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"
@implementation OFSequencedPacketSocket
|
|
<
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
* Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* 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"
#ifndef _XOPEN_SOURCE_EXTENDED
# define _XOPEN_SOURCE_EXTENDED
#endif
#define _HPUX_ALT_XOPEN_SOCKET_API
#include <errno.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#import "OFSequencedPacketSocket.h"
#import "OFSequencedPacketSocket+Private.h"
#import "OFData.h"
#import "OFRunLoop+Private.h"
#import "OFRunLoop.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAcceptSocketFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFListenOnSocketFailedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"
@implementation OFSequencedPacketSocket
|
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
- (void)listenWithBacklog: (int)backlog
{
if (_socket == OFInvalidSocketHandle)
@throw [OFNotOpenException exceptionWithObject: self];
if (listen(_socket, backlog) == -1)
@throw [OFListenFailedException
exceptionWithSocket: self
backlog: backlog
errNo: OFSocketErrNo()];
_listening = true;
}
|
|
|
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
- (void)listenWithBacklog: (int)backlog
{
if (_socket == OFInvalidSocketHandle)
@throw [OFNotOpenException exceptionWithObject: self];
if (listen(_socket, backlog) == -1)
@throw [OFListenOnSocketFailedException
exceptionWithSocket: self
backlog: backlog
errNo: OFSocketErrNo()];
_listening = true;
}
|
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
|
(socklen_t)sizeof(client->_remoteAddress.sockaddr);
#if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC)
if ((client->_socket = paccept(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) ==
OFInvalidSocketHandle)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
if ((client->_socket = accept4(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length, SOCK_CLOEXEC)) ==
OFInvalidSocketHandle)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#else
if ((client->_socket = accept(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length)) == OFInvalidSocketHandle)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
# if defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1)
fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC);
# endif
#endif
assert(client->_remoteAddress.length <=
(socklen_t)sizeof(client->_remoteAddress.sockaddr));
switch (((struct sockaddr *)&client->_remoteAddress.sockaddr)
->sa_family) {
case AF_INET:
client->_remoteAddress.family = OFSocketAddressFamilyIPv4;
break;
|
|
|
|
|
|
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
|
(socklen_t)sizeof(client->_remoteAddress.sockaddr);
#if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC)
if ((client->_socket = paccept(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) ==
OFInvalidSocketHandle)
@throw [OFAcceptSocketFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
if ((client->_socket = accept4(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length, SOCK_CLOEXEC)) ==
OFInvalidSocketHandle)
@throw [OFAcceptSocketFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#else
if ((client->_socket = accept(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length)) == OFInvalidSocketHandle)
@throw [OFAcceptSocketFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
# if defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1)
fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC);
# endif
#endif
OFAssert(client->_remoteAddress.length <=
(socklen_t)sizeof(client->_remoteAddress.sockaddr));
switch (((struct sockaddr *)&client->_remoteAddress.sockaddr)
->sa_family) {
case AF_INET:
client->_remoteAddress.family = OFSocketAddressFamilyIPv4;
break;
|