Modified src/OFDDPSocket.m
from [ff6c9b4b71]
to [d78813a978].
︙ | | |
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
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
|
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
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
|
-
+
-
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+
|
#endif
#import "OFDDPSocket.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFBindDDPSocketFailedException.h"
@implementation OFDDPSocket
@dynamic delegate;
- (OFSocketAddress)bindToPort: (uint8_t)port
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeAppleTalk(0, 0, port);
if ((_socket = socket(address.sockaddr.at.sat_family,
SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
@throw [OFBindFailedException
@throw [OFBindDDPSocketFailedException
exceptionWithPort: port
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindDDPSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
socket: self
errNo: errNo];
exceptionWithPort: port
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyAppleTalk;
address.length = (socklen_t)sizeof(address.sockaddr);
if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
&address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindDDPSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
socket: self
errNo: errNo];
exceptionWithPort: port
socket: self
errNo: errNo];
}
if (address.sockaddr.at.sat_family != AF_APPLETALK) {
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindDDPSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
socket: self
errNo: EAFNOSUPPORT];
exceptionWithPort: port
socket: self
errNo: EAFNOSUPPORT];
}
return address;
}
@end
|
Modified src/OFIPSocketAsyncConnector.m
from [e235fd33e4]
to [11edaa9dd3].
︙ | | |
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-
+
|
#import "OFIPSocketAsyncConnector.h"
#import "OFData.h"
#import "OFTCPSocket.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFConnectionFailedException.h"
#import "OFConnectIPSocketFailedException.h"
#import "OFInvalidFormatException.h"
@implementation OFIPSocketAsyncConnector
- (instancetype)initWithSocket: (id)sock
host: (OFString *)host
port: (uint16_t)port
delegate: (id)delegate
|
︙ | | |
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
|
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
|
-
-
-
-
+
+
+
+
-
+
|
}
[self didConnect];
}
- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
return [OFConnectionFailedException exceptionWithHost: _host
port: _port
socket: _socket
errNo: errNo];
return [OFConnectIPSocketFailedException exceptionWithHost: _host
port: _port
socket: _socket
errNo: errNo];
}
- (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
OFSocketAddress address = *(const OFSocketAddress *)
[_socketAddresses itemAtIndex: _socketAddressesIndex++];
int errNo;
OFSocketAddressSetPort(&address, _port);
if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
if (_socketAddressesIndex >= _socketAddresses.count) {
_exception = [[OFConnectionFailedException alloc]
_exception = [[OFConnectIPSocketFailedException alloc]
initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|
︙ | | |
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
-
+
|
delegate: self];
return;
} else {
#endif
[_socket of_closeSocket];
if (_socketAddressesIndex >= _socketAddresses.count) {
_exception = [[OFConnectionFailedException
_exception = [[OFConnectIPSocketFailedException
alloc] initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|
︙ | | |
Modified src/OFIPXSocket.h
from [270a469bc4]
to [9798b4504d].
︙ | | |
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
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
|
+
+
+
-
+
-
+
+
+
+
+
|
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
id <OFIPXSocketDelegate> delegate;
/**
* @brief Bind the socket to the specified network, node and port with the
* specified packet type.
*
* @param network The IPX network to bind to. 0 means the current network.
* @param node The IPX network to bind to. An all zero node means the
* computer's node.
* @param port The port (sometimes called socket number) to bind to. 0 means to
* pick one and return via the returned socket address.
* @param packetType The packet type to use on the socket
* @return The address on which this socket can be reached
* @throw OFBindFailedException Binding failed
* @throw OFBindIPXSocketFailedException Binding failed
* @throw OFAlreadyConnectedException The socket is already bound
*/
- (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType;
- (OFSocketAddress)
bindToNetwork: (uint32_t)network
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
packetType: (uint8_t)packetType;
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFIPXSocket.m
from [f0059481b5]
to [1dc137a6b3].
︙ | | |
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
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
|
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
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
|
-
+
+
+
+
-
+
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
|
#endif
#import "OFIPXSocket.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFBindIPXSocketFailedException.h"
@implementation OFIPXSocket
@dynamic delegate;
- (OFSocketAddress)bindToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
- (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType
packetType: (uint8_t)packetType
{
const unsigned char zeroNode[IPX_NODE_LEN] = { 0 };
OFSocketAddress address;
int protocol = 0;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeIPX(0, zeroNode, port);
address = OFSocketAddressMakeIPX(network, node, port);
#ifdef OF_WINDOWS
protocol = NSPROTO_IPX + packetType;
#else
_packetType = address.sockaddr.ipx.sipx_type = packetType;
#endif
if ((_socket = socket(address.sockaddr.ipx.sipx_family,
SOCK_DGRAM | SOCK_CLOEXEC, protocol)) == OFInvalidSocketHandle)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: packetType
socket: self
errNo: OFSocketErrNo()];
@throw [OFBindIPXSocketFailedException
exceptionWithNetwork: network
node: node
port: port
packetType: packetType
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: packetType
socket: self
errNo: errNo];
exceptionWithNetwork: network
node: node
port: port
packetType: packetType
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPX;
address.length = (socklen_t)sizeof(address.sockaddr);
if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
&address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: packetType
socket: self
errNo: errNo];
exceptionWithNetwork: network
node: node
port: port
packetType: packetType
socket: self
errNo: errNo];
}
if (address.sockaddr.ipx.sipx_family != AF_IPX) {
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: packetType
socket: self
errNo: EAFNOSUPPORT];
exceptionWithNetwork: network
node: node
port: port
packetType: packetType
socket: self
errNo: EAFNOSUPPORT];
}
return address;
}
#ifndef OF_WINDOWS
- (void)sendBuffer: (const void *)buffer
|
︙ | | |
Modified src/OFSPXSocket.h
from [40e34f28e7]
to [62171025db].
︙ | | |
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
-
+
|
* @param node The node the socket connected to
* @param port The port of the node to which the socket connected
* @param exception An exception that occurred while connecting, or nil on
* success
*/
- (void)socket: (OFSPXSocket *)socket
didConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
exception: (nullable id)exception;
@end
/**
* @class OFSPXSocket OFSPXSocket.h ObjFW/OFSPXSocket.h
*
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
-
+
-
+
+
+
+
|
/**
* @brief Connect the OFSPXSocket to the specified destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @throw OFConnectionFailedException Connecting failed
* @throw OFConnectSPXSocketFailedException Connecting failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (void)connectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port;
/**
* @brief Asynchronously connect the OFSPXSocket to the specified destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port;
/**
* @brief Asynchronously connect the OFSPXSocket to the specified destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @param runLoopMode The run loop mode in which to perform the async connect
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously connect the OFSPXSocket to the specified destination.
*
* @param node The node to connect to
* @param network The network on which the node to connect to is
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @param block The block to execute once the connection has been established
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
block: (OFSPXSocketAsyncConnectBlock)block;
/**
* @brief Asynchronously connect the OFSPXSocket to the specified destination.
*
* @param node The node to connect to
* @param network The network on which the node to connect to is
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @param runLoopMode The run loop mode in which to perform the async connect
* @param block The block to execute once the connection has been established
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSPXSocketAsyncConnectBlock)block;
#endif
/**
* @brief Bind the socket to the specified network, node and port.
*
* @param network The IPX network to bind to. 0 means the current network.
* @param node The IPX network to bind to. An all zero node means the
* computer's node.
* @param port The port (sometimes called socket number) to bind to. 0 means to
* pick one and return via the returned socket address.
* @return The address on which this socket can be reached
* @throw OFBindFailedException Binding failed
* @throw OFBindIPXSocketFailedException Binding failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (OFSocketAddress)bindToPort: (uint16_t)port;
- (OFSocketAddress)
bindToNetwork: (uint32_t)network
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port;
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFSPXSocket.m
from [63c27817f9]
to [4bb1b2f501].
︙ | | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
-
-
+
+
|
#import "OFSPXSocket.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFBindIPXSocketFailedException.h"
#import "OFConnectSPXSocketFailedException.h"
#import "OFNotOpenException.h"
#ifndef NSPROTO_SPX
# define NSPROTO_SPX 0
#endif
static const uint8_t SPXPacketType = 5;
|
︙ | | |
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
|
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
|
-
+
-
+
|
#ifdef OF_HAVE_BLOCKS
OFSPXSocketAsyncConnectBlock _block;
#endif
}
- (instancetype)initWithSocket: (OFSPXSocket *)socket
network: (uint32_t)network
node: (unsigned char [IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
block: (OFSPXSocketAsyncConnectBlock)block
#endif
;
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode;
@end
@implementation OFSPXSocketAsyncConnectDelegate
- (instancetype)initWithSocket: (OFSPXSocket *)sock
network: (uint32_t)network
node: (unsigned char [IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
block: (OFSPXSocketAsyncConnectBlock)block
#endif
{
self = [super init];
|
︙ | | |
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
-
-
-
-
-
+
+
+
+
+
|
#ifdef OF_HAVE_BLOCKS
}
#endif
}
- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
return [OFConnectionFailedException exceptionWithNetwork: _network
node: _node
port: _port
socket: _socket
errNo: errNo];
return [OFConnectSPXSocketFailedException exceptionWithNetwork: _network
node: _node
port: _port
socket: _socket
errNo: errNo];
}
@end
@implementation OFSPXSocket
@dynamic delegate;
- (int)of_createSocketForAddress: (const OFSocketAddress *)address
|
︙ | | |
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
|
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
388
389
390
391
392
393
394
395
396
397
398
399
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
|
- (void)of_closeSocket
{
closesocket(_socket);
_socket = OFInvalidSocketHandle;
}
- (void)connectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
{
OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port);
int errNo;
if (![self of_createSocketForAddress: &address errNo: &errNo])
@throw [OFConnectionFailedException
@throw [OFConnectSPXSocketFailedException
exceptionWithNetwork: network
node: node
port: port
socket: self
errNo: errNo];
if (![self of_connectSocketToAddress: &address errNo: &errNo]) {
[self of_closeSocket];
@throw [OFConnectionFailedException
@throw [OFConnectSPXSocketFailedException
exceptionWithNetwork: network
node: node
port: port
socket: self
errNo: errNo];
}
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
{
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: OFDefaultRunLoopMode];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
{
void *pool = objc_autoreleasePoolPush();
[[[[OFSPXSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
#ifdef OF_HAVE_BLOCKS
block: NULL
#endif
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
block: (OFSPXSocketAsyncConnectBlock)block
{
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: OFDefaultRunLoopMode
block: block];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSPXSocketAsyncConnectBlock)block
{
void *pool = objc_autoreleasePoolPush();
[[[[OFSPXSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
block: block
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFSocketAddress)bindToPort: (uint16_t)port
- (OFSocketAddress)bindToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
{
const unsigned char zeroNode[IPX_NODE_LEN] = { 0 };
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeIPX(0, zeroNode, port);
address = OFSocketAddressMakeIPX(network, node, port);
if ((_socket = socket(address.sockaddr.ipx.sipx_family,
SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) ==
OFInvalidSocketHandle)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: OFSocketErrNo()];
@throw [OFBindIPXSocketFailedException
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPX;
address.length = (socklen_t)sizeof(address.sockaddr);
if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
&address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
if (address.sockaddr.ipx.sipx_family != AF_IPX) {
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: EAFNOSUPPORT];
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: EAFNOSUPPORT];
}
return address;
}
@end
|
Modified src/OFSPXStreamSocket.h
from [d15837842c]
to [454aa9fc7f].
︙ | | |
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
-
+
|
* @param node The node the socket connected to
* @param port The port of the node to which the socket connected
* @param exception An exception that occurred while connecting, or nil on
* success
*/
- (void)socket: (OFSPXStreamSocket *)socket
didConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
exception: (nullable id)exception;
@end
/**
* @class OFSPXStreamSocket OFSPXStreamSocket.h ObjFW/OFSPXStreamSocket.h
*
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
-
+
-
+
+
+
+
|
/**
* @brief Connect the OFSPXStreamSocket to the specified destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @throw OFConnectionFailedException Connecting failed
* @throw OFConnectSPXSocketFailedException Connecting failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (void)connectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port;
/**
* @brief Asynchronously connect the OFSPXStreamSocket to the specified
* destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port;
/**
* @brief Asynchronously connect the OFSPXStreamSocket to the specified
* destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @param runLoopMode The run loop mode in which to perform the async connect
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously connect the OFSPXStreamSocket to the specified
* destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @param block The block to execute once the connection has been established
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
block: (OFSPXStreamSocketAsyncConnectBlock)block;
/**
* @brief Asynchronously connect the OFSPXStreamSocket to the specified
* destination.
*
* @param network The network on which the node to connect to is
* @param node The node to connect to
* @param port The port (sometimes also called socket number) on the node to
* connect to
* @param runLoopMode The run loop mode in which to perform the async connect
* @param block The block to execute once the connection has been established
*/
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSPXStreamSocketAsyncConnectBlock)block;
#endif
/**
* @brief Bind the socket to the specified network, node and port.
*
* @param network The IPX network to bind to. 0 means the current network.
* @param node The IPX network to bind to. An all zero node means the
* computer's node.
* @param port The port (sometimes called socket number) to bind to. 0 means to
* pick one and return via the returned socket address.
* @return The address on which this socket can be reached
* @throw OFConnectionFailedException Binding failed
* @throw OFBindIPXSocketFailedException Binding failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (OFSocketAddress)bindToPort: (uint16_t)port;
- (OFSocketAddress)
bindToNetwork: (uint32_t)network
node: (const unsigned char [_Nonnull IPX_NODE_LEN])node
port: (uint16_t)port;
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFSPXStreamSocket.m
from [a588145b61]
to [3d76de2dbb].
︙ | | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
-
-
+
+
|
#import "OFSPXStreamSocket.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFBindIPXSocketFailedException.h"
#import "OFConnectSPXSocketFailedException.h"
#import "OFNotOpenException.h"
#ifndef NSPROTO_SPX
# define NSPROTO_SPX 0
#endif
static const uint8_t SPXPacketType = 5;
|
︙ | | |
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
|
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
|
-
+
-
+
|
#ifdef OF_HAVE_BLOCKS
OFSPXStreamSocketAsyncConnectBlock _block;
#endif
}
- (instancetype)initWithSocket: (OFSPXStreamSocket *)socket
network: (uint32_t)network
node: (unsigned char [IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
block: (OFSPXStreamSocketAsyncConnectBlock)block
#endif
;
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode;
@end
@implementation OFSPXStreamSocketAsyncConnectDelegate
- (instancetype)initWithSocket: (OFSPXStreamSocket *)sock
network: (uint32_t)network
node: (unsigned char [IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
block: (OFSPXStreamSocketAsyncConnectBlock)block
#endif
{
self = [super init];
|
︙ | | |
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
-
-
-
-
-
+
+
+
+
+
|
#ifdef OF_HAVE_BLOCKS
}
#endif
}
- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
return [OFConnectionFailedException exceptionWithNetwork: _network
node: _node
port: _port
socket: _socket
errNo: errNo];
return [OFConnectSPXSocketFailedException exceptionWithNetwork: _network
node: _node
port: _port
socket: _socket
errNo: errNo];
}
@end
@implementation OFSPXStreamSocket
@dynamic delegate;
- (int)of_createSocketForAddress: (const OFSocketAddress *)address
|
︙ | | |
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
388
|
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
388
389
390
391
392
393
394
395
396
397
398
399
400
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
|
- (void)of_closeSocket
{
closesocket(_socket);
_socket = OFInvalidSocketHandle;
}
- (void)connectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
{
OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port);
int errNo;
if (![self of_createSocketForAddress: &address errNo: &errNo])
@throw [OFConnectionFailedException
@throw [OFConnectSPXSocketFailedException
exceptionWithNetwork: network
node: node
port: port
socket: self
errNo: errNo];
if (![self of_connectSocketToAddress: &address errNo: &errNo]) {
[self of_closeSocket];
@throw [OFConnectionFailedException
@throw [OFConnectSPXSocketFailedException
exceptionWithNetwork: network
node: node
port: port
socket: self
errNo: errNo];
}
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
{
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: OFDefaultRunLoopMode];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
{
void *pool = objc_autoreleasePoolPush();
[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
#ifdef OF_HAVE_BLOCKS
block: NULL
#endif
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
block: (OFSPXStreamSocketAsyncConnectBlock)block
{
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: OFDefaultRunLoopMode
block: block];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (unsigned char [_Nonnull IPX_NODE_LEN])node
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSPXStreamSocketAsyncConnectBlock)block
{
void *pool = objc_autoreleasePoolPush();
[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
block: block
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFSocketAddress)bindToPort: (uint16_t)port
- (OFSocketAddress)bindToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
{
const unsigned char zeroNode[IPX_NODE_LEN] = { 0 };
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeIPX(0, zeroNode, port);
address = OFSocketAddressMakeIPX(network, node, port);
if ((_socket = socket(address.sockaddr.ipx.sipx_family,
SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: OFSocketErrNo()];
@throw [OFBindIPXSocketFailedException
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPX;
address.length = (socklen_t)sizeof(address.sockaddr);
if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
&address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
if (address.sockaddr.ipx.sipx_family != AF_IPX) {
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: EAFNOSUPPORT];
exceptionWithNetwork: network
node: node
port: port
packetType: SPXPacketType
socket: self
errNo: EAFNOSUPPORT];
}
return address;
}
@end
|
Modified src/OFSequencedPacketSocket.h
from [b8e6a1fd31]
to [0f03522481].
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
block: (OFSequencedPacketSocketAsyncSendDataBlock)block;
#endif
/**
* @brief Listen on the socket.
*
* @param backlog Maximum length for the queue of pending connections.
* @throw OFListenFailedException Listening failed
* @throw OFListenOnSocketFailedException Listening failed
* @throw OFNotOpenException The socket is not open
*/
- (void)listenWithBacklog: (int)backlog;
/**
* @brief Listen on the socket.
*
* @throw OFListenFailedException Listening failed
* @throw OFListenOnSocketFailedException Listening failed
* @throw OFNotOpenException The socket is not open
*/
- (void)listen;
/**
* @brief Accept an incoming connection.
*
* @return An autoreleased sequenced packet socket for the accepted connection.
* @throw OFAcceptFailedException Accepting failed
* @throw OFAcceptSocketFailedException Accepting failed
* @throw OFNotOpenException The socket is not open
*/
- (instancetype)accept;
/**
* @brief Asynchronously accept an incoming connection.
*/
|
︙ | | |
Modified src/OFSequencedPacketSocket.m
from [a8c0e899a1]
to [0b38781929].
︙ | | |
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
-
+
-
+
|
#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 "OFAcceptSocketFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFListenFailedException.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
|
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
@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
|
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
|
-
+
-
+
-
+
|
(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
@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 [OFAcceptFailedException
@throw [OFAcceptSocketFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#else
if ((client->_socket = accept(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length)) == OFInvalidSocketHandle)
@throw [OFAcceptFailedException
@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
|
︙ | | |
Modified src/OFSocket.h
from [9f4f0632e4]
to [24521aefe5].
︙ | | |
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
-
+
|
/**
* @brief Gets the IPX node of the specified @ref OFSocketAddress.
*
* @param address The address on which to get the IPX node
* @param node A byte array to store the IPX node of the address
*/
extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address,
extern void OFSocketAddressGetIPXNode(const OFSocketAddress *_Nonnull address,
unsigned char node[_Nonnull IPX_NODE_LEN]);
/**
* @brief Sets the AppleTalk network of the specified @ref OFSocketAddress.
*
* @param address The address on which to set the AppleTalk network
* @param network The AppleTalk network to set on the address
|
︙ | | |
Modified src/OFSocket.m
from [713c3da7b8]
to [60f126f761].
︙ | | |
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
|
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
|
-
+
|
if (address->family != OFSocketAddressFamilyIPX)
@throw [OFInvalidArgumentException exception];
memcpy(address->sockaddr.ipx.sipx_node, node, IPX_NODE_LEN);
}
void
OFSocketAddressIPXNode(const OFSocketAddress *address,
OFSocketAddressGetIPXNode(const OFSocketAddress *address,
unsigned char node[IPX_NODE_LEN])
{
if (address->family != OFSocketAddressFamilyIPX)
@throw [OFInvalidArgumentException exception];
memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN);
}
|
︙ | | |
Modified src/OFStreamSocket.h
from [310cc8cd98]
to [700ee89673].
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
*/
+ (instancetype)socket;
/**
* @brief Listen on the socket.
*
* @param backlog Maximum length for the queue of pending connections.
* @throw OFListenFailedException Listening failed
* @throw OFListenOnSocketFailedException Listening failed
* @throw OFNotOpenException The socket is not open
*/
- (void)listenWithBacklog: (int)backlog;
/**
* @brief Listen on the socket.
*
* @throw OFListenFailedException Listening failed
* @throw OFListenOnSocketFailedException Listening failed
* @throw OFNotOpenException The socket is not open
*/
- (void)listen;
/**
* @brief Accept an incoming connection.
*
* @return An autoreleased OFStreamSocket for the accepted connection.
* @throw OFAcceptFailedException Accepting failed
* @throw OFAcceptSocketFailedException Accepting failed
* @throw OFNotOpenException The socket is not open
*/
- (instancetype)accept;
/**
* @brief Asynchronously accept an incoming connection.
*/
|
︙ | | |
Modified src/OFStreamSocket.m
from [6c817945cd]
to [efe4f02a49].
︙ | | |
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
-
+
-
+
|
#import "OFStreamSocket.h"
#import "OFStreamSocket+Private.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket+Private.h"
#import "OFAcceptFailedException.h"
#import "OFAcceptSocketFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFListenFailedException.h"
#import "OFListenOnSocketFailedException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"
|
︙ | | |
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
-
+
|
- (void)listenWithBacklog: (int)backlog
{
if (_socket == OFInvalidSocketHandle)
@throw [OFNotOpenException exceptionWithObject: self];
if (listen(_socket, backlog) == -1)
@throw [OFListenFailedException
@throw [OFListenOnSocketFailedException
exceptionWithSocket: self
backlog: backlog
errNo: OFSocketErrNo()];
_listening = true;
}
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
(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
@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 [OFAcceptFailedException
@throw [OFAcceptSocketFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#else
if ((client->_socket = accept(_socket,
(struct sockaddr *)&client->_remoteAddress.sockaddr,
&client->_remoteAddress.length)) == OFInvalidSocketHandle)
@throw [OFAcceptFailedException
@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
|
︙ | | |
Modified src/OFTCPSocket.h
from [13742bc171]
to [522e53453c].
︙ | | |
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
-
+
|
+ (uint16_t)SOCKS5Port;
/**
* @brief Connects the OFTCPSocket to the specified destination.
*
* @param host The host to connect to
* @param port The port on the host to connect to
* @throw OFConnectionFailedException Connecting failed
* @throw OFConnectIPSocketFailedException Connecting failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (void)connectToHost: (OFString *)host port: (uint16_t)port;
/**
* @brief Asynchronously connects the OFTCPSocket to the specified destination.
*
|
︙ | | |
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
-
+
|
* @brief Binds the socket to the specified host and port.
*
* @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for
* IPv6 to bind to all.
* @param port The port to bind to. If the port is 0, an unused port will be
* chosen, which can be obtained using the return value.
* @return The port the socket was bound to
* @throw OFBindFailedException Binding failed
* @throw OFBindIPSocketFailedException Binding failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port;
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFTCPSocket.m
from [3962a70e27]
to [e6378dfef4].
︙ | | |
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
-
+
|
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#import "OFTCPSocketSOCKS5Connector.h"
#import "OFThread.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFBindIPSocketFailedException.h"
#import "OFGetOptionFailedException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFSetOptionFailedException.h"
static const OFRunLoopMode connectRunLoopMode =
@"OFTCPSocketConnectRunLoopMode";
|
︙ | | |
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
-
+
|
address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0];
OFSocketAddressSetPort(&address, port);
if ((_socket = socket(
((struct sockaddr *)&address.sockaddr)->sa_family,
SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: host
port: port
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
|
︙ | | |
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
+
-
-
-
-
+
+
+
+
|
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPSocketFailedException
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: errNo];
exceptionWithHost: host
port: port
socket: self
errNo: errNo];
}
#if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS)
} else {
for (;;) {
uint16_t rnd = 0;
int ret;
|
︙ | | |
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
-
+
|
if (OFSocketErrNo() != EADDRINUSE) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: host
port: port
socket: self
errNo: errNo];
}
}
}
|
︙ | | |
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
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
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
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
437
|
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
|
if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
&address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: errNo];
@throw [OFBindIPSocketFailedException exceptionWithHost: host
port: port
socket: self
errNo: errNo];
}
switch (((struct sockaddr *)&address.sockaddr)->sa_family) {
case AF_INET:
return OFFromBigEndian16(address.sockaddr.in.sin_port);
# ifdef OF_HAVE_IPV6
case AF_INET6:
return OFFromBigEndian16(address.sockaddr.in6.sin6_port);
# endif
default:
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPSocketFailedException
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: EAFNOSUPPORT];
exceptionWithHost: host
port: port
socket: self
errNo: EAFNOSUPPORT];
}
#else
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: EADDRNOTAVAIL];
@throw [OFBindIPSocketFailedException exceptionWithHost: host
port: port
socket: self
errNo: EADDRNOTAVAIL];
#endif
}
#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
- (void)setSendsKeepAlives: (bool)sendsKeepAlives
{
int v = sendsKeepAlives;
|
︙ | | |
Modified src/OFTCPSocketSOCKS5Connector.m
from [5abece8458]
to [f6cfb53e62].
︙ | | |
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-
+
|
#include <errno.h>
#import "OFTCPSocketSOCKS5Connector.h"
#import "OFData.h"
#import "OFRunLoop.h"
#import "OFString.h"
#import "OFConnectionFailedException.h"
#import "OFConnectIPSocketFailedException.h"
enum {
stateSendAuthentication = 1,
stateReadVersion,
stateSendRequest,
stateReadResponse,
stateReadAddress,
|
︙ | | |
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
-
+
|
runLoopMode = [OFRunLoop currentRunLoop].currentMode;
switch (_SOCKS5State) {
case stateReadVersion:
SOCKSVersion = buffer;
if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) {
_exception = [[OFConnectionFailedException alloc]
_exception = [[OFConnectIPSocketFailedException alloc]
initWithHost: _host
port: _port
socket: self
errNo: EPROTONOSUPPORT];
[self didConnect];
return false;
}
|
︙ | | |
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
-
+
|
_SOCKS5State = stateSendRequest;
[_socket asyncWriteData: _request runLoopMode: runLoopMode];
return false;
case stateReadResponse:
response = buffer;
if (response[0] != 5 || response[2] != 0) {
_exception = [[OFConnectionFailedException alloc]
_exception = [[OFConnectIPSocketFailedException alloc]
initWithHost: _host
port: _port
socket: self
errNo: EPROTONOSUPPORT];
[self didConnect];
return false;
}
|
︙ | | |
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
-
+
|
errNo = EPROTO;
#else
errNo = 0;
#endif
break;
}
_exception = [[OFConnectionFailedException alloc]
_exception = [[OFConnectIPSocketFailedException alloc]
initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return false;
}
|
︙ | | |
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
-
+
|
case 4: /* IPv6 */
_SOCKS5State = stateReadAddress;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 16 + 2
runLoopMode: runLoopMode];
return false;
default:
_exception = [[OFConnectionFailedException alloc]
_exception = [[OFConnectIPSocketFailedException alloc]
initWithHost: _host
port: _port
socket: self
errNo: EPROTONOSUPPORT];
[self didConnect];
return false;
}
|
︙ | | |
Modified src/OFUDPSocket.h
from [e94e3865e1]
to [c4641067b3].
︙ | | |
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
-
+
|
* @brief Binds the socket to the specified host and port.
*
* @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for
* IPv6 to bind to all.
* @param port The port to bind to. If the port is 0, an unused port will be
* chosen, which can be obtained using the return value.
* @return The port the socket was bound to
* @throw OFBindFailedException Binding failed
* @throw OFBindIPSocketFailedException Binding failed
* @throw OFAlreadyConnectedException The socket is already bound
*/
- (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port;
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFUDPSocket.m
from [61fa5cfa02]
to [fd8f9dff29].
︙ | | |
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
|
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
|
-
+
-
+
|
#import "OFDNSResolver.h"
#import "OFData.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFThread.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFBindIPSocketFailedException.h"
@implementation OFUDPSocket
@dynamic delegate;
- (uint16_t)of_bindToAddress: (OFSocketAddress *)address
extraType: (int)extraType OF_DIRECT
{
void *pool = objc_autoreleasePoolPush();
uint16_t port;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if ((_socket = socket(
((struct sockaddr *)&address->sockaddr)->sa_family,
SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle)
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: OFSocketAddressString(address)
port: OFSocketAddressPort(address)
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
|
︙ | | |
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
-
+
|
if (bind(_socket, (struct sockaddr *)&address->sockaddr,
address->length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: OFSocketAddressString(address)
port: OFSocketAddressPort(address)
socket: self
errNo: errNo];
}
#if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS)
} else {
|
︙ | | |
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
-
+
|
int errNo = OFSocketErrNo();
OFString *host = OFSocketAddressString(address);
port = OFSocketAddressPort(address);
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: host
port: port
socket: self
errNo: errNo];
}
}
}
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
if (OFGetSockName(_socket, (struct sockaddr *)&address->sockaddr,
&address->length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: OFSocketAddressString(address)
port: OFSocketAddressPort(address)
socket: self
errNo: errNo];
}
switch (((struct sockaddr *)&address->sockaddr)->sa_family) {
case AF_INET:
return OFFromBigEndian16(address->sockaddr.in.sin_port);
# ifdef OF_HAVE_IPV6
case AF_INET6:
return OFFromBigEndian16(address->sockaddr.in6.sin6_port);
# endif
default:
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: OFSocketAddressString(address)
port: OFSocketAddressPort(address)
socket: self
errNo: EAFNOSUPPORT];
}
#else
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
@throw [OFBindIPSocketFailedException
exceptionWithHost: OFSocketAddressString(address)
port: OFSocketAddressPort(address)
socket: self
errNo: EADDRNOTAVAIL];
#endif
}
|
︙ | | |
Modified src/OFUNIXDatagramSocket.h
from [342ce1dbb2]
to [0a3ec7f2ad].
︙ | | |
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
-
+
|
id <OFUNIXDatagramSocketDelegate> delegate;
/**
* @brief Bind the socket to the specified path.
*
* @param path The path to bind to
* @return The address on which this socket can be reached
* @throw OFBindFailedException Binding failed
* @throw OFBindUNIXSocketFailedException Binding failed
* @throw OFAlreadyConnectedException The socket is already bound
*/
- (OFSocketAddress)bindToPath: (OFString *)path;
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFUNIXDatagramSocket.m
from [2b20715dbe]
to [7203060d9a].
︙ | | |
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
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
|
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
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
|
-
+
-
+
+
-
-
-
+
+
+
|
#import "OFUNIXDatagramSocket.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFBindUNIXSocketFailedException.h"
@implementation OFUNIXDatagramSocket
@dynamic delegate;
- (OFSocketAddress)bindToPath: (OFString *)path
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeUNIX(path);
if ((_socket = socket(address.sockaddr.un.sun_family,
SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
@throw [OFBindFailedException
@throw [OFBindUNIXSocketFailedException
exceptionWithPath: path
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindUNIXSocketFailedException
@throw [OFBindFailedException exceptionWithPath: path
socket: self
errNo: errNo];
exceptionWithPath: path
socket: self
errNo: errNo];
}
return address;
}
@end
|
Modified src/OFUNIXStreamSocket.h
from [8a5717e58d]
to [3d105f3c9b].
︙ | | |
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
-
+
-
+
|
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
id <OFUNIXStreamSocketDelegate> delegate;
/**
* @brief Connects the OFUNIXStreamSocket to the specified destination.
*
* @param path The path to connect to
* @throw OFConnectionFailedException Connecting failed
* @throw OFConnectUNIXSocketFailedException Connecting failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (void)connectToPath: (OFString *)path;
/**
* @brief Binds the socket to the specified host and port.
*
* @param path The path to bind to
* @throw OFBindFailedException Binding failed
* @throw OFBindUNIXSocketFailedException Binding failed
* @throw OFAlreadyConnectedException The socket is already connected or bound
*/
- (void)bindToPath: (OFString *)path;
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFUNIXStreamSocket.m
from [70b73d6c70]
to [ff26304fa1].
︙ | | |
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
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
|
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
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
|
-
-
+
+
-
+
+
-
-
-
+
+
+
-
+
+
-
-
-
+
+
+
|
#import "OFUNIXStreamSocket.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFString.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFBindUNIXSocketFailedException.h"
#import "OFConnectUNIXSocketFailedException.h"
@implementation OFUNIXStreamSocket
@dynamic delegate;
- (void)connectToPath: (OFString *)path
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeUNIX(path);
if ((_socket = socket(address.sockaddr.un.sun_family,
SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
@throw [OFConnectionFailedException
@throw [OFConnectUNIXSocketFailedException
exceptionWithPath: path
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (connect(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFConnectUNIXSocketFailedException
@throw [OFConnectionFailedException exceptionWithPath: path
socket: self
errNo: errNo];
exceptionWithPath: path
socket: self
errNo: errNo];
}
}
- (void)bindToPath: (OFString *)path
{
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != OFInvalidSocketHandle)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeUNIX(path);
if ((_socket = socket(address.sockaddr.un.sun_family,
SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
@throw [OFBindFailedException
@throw [OFBindUNIXSocketFailedException
exceptionWithPath: path
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindUNIXSocketFailedException
@throw [OFBindFailedException exceptionWithPath: path
socket: self
errNo: errNo];
exceptionWithPath: path
socket: self
errNo: errNo];
}
}
@end
|
Modified src/ObjFW.h
from [870006c5ed]
to [7f42df2531].
︙ | | |
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
|
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
|
-
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
|
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif
#import "OFAllocFailedException.h"
#import "OFException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFAcceptFailedException.h"
# import "OFAcceptSocketFailedException.h"
# import "OFAlreadyConnectedException.h"
# import "OFBindFailedException.h"
# import "OFBindSocketFailedException.h"
# import "OFBindIPSocketFailedException.h"
# ifdef OF_HAVE_UNIX_SOCKETS
# import "OFBindUNIXSocketFailedException.h"
# endif
# ifdef OF_HAVE_IPX
# import "OFBindIPXSocketFailedException.h"
# endif
# ifdef OF_HAVE_APPLETALK
# import "OFBindDDPSocketFailedException.h"
# endif
#endif
#import "OFChangeCurrentDirectoryFailedException.h"
#import "OFChecksumMismatchException.h"
#ifdef OF_HAVE_THREADS
# import "OFConditionBroadcastFailedException.h"
# import "OFConditionSignalFailedException.h"
# import "OFConditionStillWaitingException.h"
# import "OFConditionWaitFailedException.h"
#endif
#ifdef OF_HAVE_SOCKETS
# import "OFConnectionFailedException.h"
# import "OFConnectSocketFailedException.h"
# import "OFConnectIPSocketFailedException.h"
# ifdef OF_HAVE_UNIX_SOCKETS
# import "OFConnectUNIXSocketFailedException.h"
# endif
# ifdef OF_HAVE_IPX
# import "OFConnectSPXSocketFailedException.h"
# endif
#endif
#import "OFCopyItemFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFCreateSymbolicLinkFailedException.h"
#ifdef OF_WINDOWS
# import "OFCreateWindowsRegistryKeyFailedException.h"
#endif
|
︙ | | |
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
-
+
|
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidJSONException.h"
#import "OFInvalidServerResponseException.h"
#import "OFLinkItemFailedException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFListenFailedException.h"
# import "OFListenOnSocketFailedException.h"
#endif
#ifdef OF_HAVE_PLUGINS
# import "OFLoadPluginFailedException.h"
#endif
#import "OFLockFailedException.h"
#import "OFMalformedXMLException.h"
#import "OFMoveItemFailedException.h"
|
︙ | | |
Modified src/exceptions/Makefile
from [a8a6570db6]
to [63402987f2].
︙ | | |
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
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
|
-
+
-
-
+
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
|
${USE_SRCS_PLUGINS} \
${USE_SRCS_SOCKETS} \
${USE_SRCS_THREADS} \
${USE_SRCS_WINDOWS}
SRCS_FILES = OFChangeCurrentDirectoryFailedException.m \
OFGetCurrentDirectoryFailedException.m
SRCS_PLUGINS = OFLoadPluginFailedException.m
SRCS_SOCKETS = OFAcceptFailedException.m \
SRCS_SOCKETS = OFAcceptSocketFailedException.m \
OFAlreadyConnectedException.m \
OFBindFailedException.m \
OFConnectionFailedException.m \
OFBindIPSocketFailedException.m \
OFBindSocketFailedException.m \
OFConnectIPSocketFailedException.m \
OFConnectSocketFailedException.m \
OFDNSQueryFailedException.m \
OFHTTPRequestFailedException.m \
OFListenFailedException.m \
OFListenOnSocketFailedException.m \
OFObserveKernelEventsFailedException.m \
OFResolveHostFailedException.m \
OFTLSHandshakeFailedException.m
OFTLSHandshakeFailedException.m \
${USE_SRCS_APPLETALK} \
${USE_SRCS_IPX} \
${USE_SRCS_UNIX_SOCKETS}
SRCS_APPLETALK = OFBindDDPSocketFailedException.m
SRCS_IPX = OFBindIPXSocketFailedException.m \
OFConnectSPXSocketFailedException.m
SRCS_UNIX_SOCKETS = OFBindUNIXSocketFailedException.m \
OFConnectUNIXSocketFailedException.m
SRCS_THREADS = OFConditionBroadcastFailedException.m \
OFConditionSignalFailedException.m \
OFConditionStillWaitingException.m \
OFConditionWaitFailedException.m \
OFThreadJoinFailedException.m \
OFThreadStartFailedException.m \
OFThreadStillRunningException.m
|
︙ | | |
Renamed and modified
src/exceptions/OFAcceptFailedException.h
[af9482eaa0]
to src/exceptions/OFAcceptSocketFailedException.h
[e062558833].
︙ | | |
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
-
-
+
+
-
+
-
+
|
#ifndef OF_HAVE_SOCKETS
# error No sockets available!
#endif
OF_ASSUME_NONNULL_BEGIN
/**
* @class OFAcceptFailedException \
* OFAcceptFailedException.h ObjFW/OFAcceptFailedException.h
* @class OFAcceptSocketFailedException \
* OFAcceptSocketFailedException.h ObjFW/OFAcceptSocketFailedException.h
*
* @brief An exception indicating that accepting a connection failed.
*/
@interface OFAcceptFailedException: OFException
@interface OFAcceptSocketFailedException: OFException
{
id _socket;
int _errNo;
OF_RESERVE_IVARS(OFAcceptFailedException, 4)
OF_RESERVE_IVARS(OFAcceptSocketFailedException, 4)
}
/**
* @brief The socket which could not accept a connection.
*/
@property (readonly, nonatomic) id socket;
|
︙ | | |
Renamed and modified
src/exceptions/OFAcceptFailedException.m
[8a127340d9]
to src/exceptions/OFAcceptSocketFailedException.m
[701680e6d7].
︙ | | |
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
49
50
|
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
49
50
|
-
+
-
+
-
+
-
+
-
+
-
+
|
* 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"
#import "OFAcceptFailedException.h"
#import "OFAcceptSocketFailedException.h"
#import "OFString.h"
@implementation OFAcceptFailedException
@implementation OFAcceptSocketFailedException
@synthesize socket = _socket, errNo = _errNo;
+ (instancetype)exception
{
OF_UNRECOGNIZED_SELECTOR
}
+ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo
+ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo
{
return [[[self alloc] initWithSocket: socket errNo: errNo] autorelease];
return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithSocket: (id)socket errNo: (int)errNo
- (instancetype)initWithSocket: (id)sock errNo: (int)errNo
{
self = [super init];
_socket = [socket retain];
_socket = [sock retain];
_errNo = errNo;
return self;
}
- (void)dealloc
{
|
︙ | | |
Modified src/exceptions/OFAlreadyConnectedException.m
from [055eee0622]
to [9abd285501].
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
|
#import "OFAlreadyConnectedException.h"
#import "OFString.h"
@implementation OFAlreadyConnectedException
@synthesize socket = _socket;
+ (instancetype)exceptionWithSocket: (id)socket
+ (instancetype)exceptionWithSocket: (id)sock
{
return [[[self alloc] initWithSocket: socket] autorelease];
return [[[self alloc] initWithSocket: sock] autorelease];
}
- (instancetype)init
{
return [self initWithSocket: nil];
}
- (instancetype)initWithSocket: (id)socket
- (instancetype)initWithSocket: (id)sock
{
self = [super init];
_socket = [socket retain];
_socket = [sock retain];
return self;
}
- (void)dealloc
{
[_socket release];
|
︙ | | |
Added src/exceptions/OFBindDDPSocketFailedException.h version [7d1260c80c].
|
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/*
* 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.
*/
#import "OFBindSocketFailedException.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @class OFBindDDPSocketFailedException \
* OFBindDDPSocketFailedException.h \
* ObjFW/OFBindDDPSocketFailedException.h
*
* @brief An exception indicating that binding a DDP socket failed.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFBindDDPSocketFailedException: OFBindSocketFailedException
{
uint8_t _port;
}
/**
* @brief The DDP port on which binding failed.
*/
@property (readonly, nonatomic) uint8_t port;
/**
* @brief Creates a new, autoreleased bind DDP socket failed exception.
*
* @param port The DDP port to which binding failed
* @param socket The socket which could not be bound
* @param errNo The errno of the error that occurred
* @return A new, autoreleased bind DDP socket failed exception
*/
+ (instancetype)exceptionWithPort: (uint8_t)port
socket: (id)socket
errNo: (int)errNo;
+ (instancetype)exceptionWithSocket: (id)socket
errNo: (int)errNo OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated bind DDP socket failed exception.
*
* @param port The DDP port to which binding failed
* @param socket The socket which could not be bound
* @param errNo The errno of the error that occurred
* @return An initialized bind DDP socket failed exception
*/
- (instancetype)initWithPort: (uint8_t)port
socket: (id)socket
errNo: (int)errNo OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE;
@end
OF_ASSUME_NONNULL_END
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added src/exceptions/OFBindDDPSocketFailedException.m version [cebffb005f].
|
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/*
* 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"
#import "OFBindDDPSocketFailedException.h"
#import "OFData.h"
#import "OFString.h"
@implementation OFBindDDPSocketFailedException
@synthesize port = _port;
+ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo
{
OF_UNRECOGNIZED_SELECTOR
}
+ (instancetype)exceptionWithPort: (uint8_t)port
socket: (id)sock
errNo: (int)errNo
{
return [[[self alloc] initWithPort: port
socket: sock
errNo: errNo] autorelease];
}
- (instancetype)initWithSocket: (id)sock errNo: (int)errNo
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithPort: (uint8_t)port
socket: (id)sock
errNo: (int)errNo
{
self = [super initWithSocket: sock errNo: errNo];
@try {
_port = port;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (OFString *)description
{
return [OFString stringWithFormat:
@"Binding to port %" @PRIx8 @" failed in socket of type %@: %@",
_port, [_socket class], OFStrError(_errNo)];
}
@end
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added src/exceptions/OFBindIPSocketFailedException.h version [5e1e83771b].
|
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
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/*
* 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.
*/
#import "OFBindSocketFailedException.h"
#ifndef OF_HAVE_SOCKETS
# error No sockets available!
#endif
OF_ASSUME_NONNULL_BEGIN
/**
* @class OFBindIPSocketFailedException \
* OFBindIPSocketFailedException.h ObjFW/OFBindIPSocketFailedException.h
*
* @brief An exception indicating that binding an IP socket failed.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFBindIPSocketFailedException: OFBindSocketFailedException
{
OFString *_Nullable _host;
uint16_t _port;
}
/**
* @brief The host on which binding failed.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host;
/**
* @brief The port on which binding failed.
*/
@property (readonly, nonatomic) uint16_t port;
/**
* @brief Creates a new, autoreleased bind IP socket failed exception.
*
* @param host The host on which binding failed
* @param port The port on which binding failed
* @param socket The socket which could not be bound
* @param errNo The errno of the error that occurred
* @return A new, autoreleased bind IP socket failed exception
*/
+ (instancetype)exceptionWithHost: (OFString *)host
port: (uint16_t)port
socket: (id)socket
errNo: (int)errNo;
+ (instancetype)exceptionWithSocket: (id)socket
errNo: (int)errNo OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated bind IP socket failed exception.
*
* @param host The host on which binding failed
* @param port The port on which binding failed
* @param socket The socket which could not be bound
* @param errNo The errno of the error that occurred
* @return An initialized bind IP socket failed exception
*/
- (instancetype)initWithHost: (OFString *)host
port: (uint16_t)port
socket: (id)socket
errNo: (int)errNo OF_DESIGNATED_INITIALIZER;
- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE;
@end
OF_ASSUME_NONNULL_END
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added src/exceptions/OFBindIPSocketFailedException.m version [f9eddfdc09].
|
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
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/*
* 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"
#import "OFBindIPSocketFailedException.h"
#import "OFString.h"
@implementation OFBindIPSocketFailedException
@synthesize host = _host, port = _port;
+ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo
{
OF_UNRECOGNIZED_SELECTOR
}
+ (instancetype)exceptionWithHost: (OFString *)host
port: (uint16_t)port
socket: (id)sock
errNo: (int)errNo
{
return [[[self alloc] initWithHost: host
port: port
socket: sock
errNo: errNo] autorelease];
}
- (instancetype)initWithSocket: (id)sock errNo: (int)errNo
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithHost: (OFString *)host
port: (uint16_t)port
socket: (id)sock
errNo: (int)errNo
{
self = [super initWithSocket: sock errNo: errNo];
@try {
_host = [host copy];
_port = port;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_host release];
[super dealloc];
}
- (OFString *)description
{
return [OFString stringWithFormat:
@"Binding to port %" @PRIu16 @" on host %@ failed in socket of "
@"type %@: %@",
_port, _host, [_socket class], OFStrError(_errNo)];
}
@end
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added src/exceptions/OFBindIPXSocketFailedException.h version [348112e28c].