1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
/*
* 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"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
|
|
|
|
|
|
>
>
>
>
|
<
>
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/*
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3.0 only,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* version 3.0 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3.0 along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
|
︙ | | | ︙ | |
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#import "OFThread.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindIPSocketFailedException.h"
#import "OFGetOptionFailedException.h"
#import "OFNotOpenException.h"
#import "OFSetOptionFailedException.h"
static const OFRunLoopMode connectRunLoopMode =
@"OFSCTPSocketConnectRunLoopMode";
|
|
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#import "OFThread.h"
#import "OFAlreadyOpenException.h"
#import "OFBindIPSocketFailedException.h"
#import "OFGetOptionFailedException.h"
#import "OFNotOpenException.h"
#import "OFSetOptionFailedException.h"
static const OFRunLoopMode connectRunLoopMode =
@"OFSCTPSocketConnectRunLoopMode";
|
︙ | | | ︙ | |
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
errNo: (int *)errNo
{
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
if ((_socket = socket(
((struct sockaddr *)&address->sockaddr)->sa_family,
SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_SCTP)) ==
OFInvalidSocketHandle) {
*errNo = OFSocketErrNo();
return false;
|
|
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
errNo: (int *)errNo
{
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyOpenException exceptionWithObject: self];
if ((_socket = socket(
((struct sockaddr *)&address->sockaddr)->sa_family,
SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_SCTP)) ==
OFInvalidSocketHandle) {
*errNo = OFSocketErrNo();
return false;
|
︙ | | | ︙ | |
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
{
void *pool = objc_autoreleasePoolPush();
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
[[[[OFAsyncIPSocketConnector alloc]
initWithSocket: self
host: host
port: port
delegate: _delegate
block: NULL
|
|
|
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
{
void *pool = objc_autoreleasePoolPush();
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyOpenException exceptionWithObject: self];
[[[[OFAsyncIPSocketConnector alloc]
initWithSocket: self
host: host
port: port
delegate: _delegate
block: NULL
|
︙ | | | ︙ | |
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSCTPSocketAsyncConnectBlock)block
{
void *pool = objc_autoreleasePoolPush();
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
[[[[OFAsyncIPSocketConnector alloc]
initWithSocket: self
host: host
port: port
delegate: nil
block: block] autorelease]
|
|
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSCTPSocketAsyncConnectBlock)block
{
void *pool = objc_autoreleasePoolPush();
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyOpenException exceptionWithObject: self];
[[[[OFAsyncIPSocketConnector alloc]
initWithSocket: self
host: host
port: port
delegate: nil
block: block] autorelease]
|
︙ | | | ︙ | |
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
OFData *socketAddresses;
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
socketAddresses = [[OFThread DNSResolver]
resolveAddressesForHost: host
addressFamily: OFSocketAddressFamilyAny];
address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0];
OFSocketAddressSetIPPort(&address, port);
|
|
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
OFData *socketAddresses;
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyOpenException exceptionWithObject: self];
socketAddresses = [[OFThread DNSResolver]
resolveAddressesForHost: host
addressFamily: OFSocketAddressFamilyAny];
address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0];
OFSocketAddressSetIPPort(&address, port);
|
︙ | | | ︙ | |