Differences From Artifact [f7ce692f2d]:
- File src/OFSPXStreamSocket.m — part of check-in [1a86b8175b] at 2022-02-12 07:46:07 on branch trunk — Update copyright (user: js, size: 9564) [annotate] [blame] [check-ins using] [more...]
To Artifact [c6825a2515]:
- File
src/OFSPXStreamSocket.m
— part of check-in
[ccc6a77c55]
at
2022-08-06 14:43:01
on branch trunk
— Reorder node and network of IPX sockets
This is more standard, albeit -[connectToNetwork:node:port:] sounding a
little bit more like you connect to a network rather than a node. (user: js, size: 9548) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
43 44 45 46 47 48 49 | @end OF_DIRECT_MEMBERS @interface OFSPXStreamSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate> { OFSPXStreamSocket *_socket; | < > < > < > < > | 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 | @end OF_DIRECT_MEMBERS @interface OFSPXStreamSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate> { OFSPXStreamSocket *_socket; uint32_t _network; unsigned char _node[IPX_NODE_LEN]; uint16_t _port; #ifdef OF_HAVE_BLOCKS OFSPXStreamSocketAsyncConnectBlock _block; #endif } - (instancetype)initWithSocket: (OFSPXStreamSocket *)socket network: (uint32_t)network node: (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 port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; _network = network; memcpy(_node, node, IPX_NODE_LEN); _port = port; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
102 103 104 105 106 107 108 | [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = | | | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = OFSocketAddressMakeIPX(_network, _node, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; goto inform_delegate; } |
︙ | ︙ | |||
151 152 153 154 155 156 157 | #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(exception); else { #endif if ([delegate respondsToSelector: | | | | | | | | | | | | | 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 | #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(exception); else { #endif if ([delegate respondsToSelector: @selector(socket:didConnectToNetwork:node:port:exception:)]) [delegate socket: _socket didConnectToNetwork: _network node: _node port: _port exception: exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { return [OFConnectionFailedException exceptionWithNetwork: _network node: _node port: _port socket: _socket errNo: errNo]; } @end @implementation OFSPXStreamSocket @dynamic delegate; - (int)of_createSocketForAddress: (const OFSocketAddress *)address |
︙ | ︙ | |||
221 222 223 224 225 226 227 | - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } | > | < | | | | | | | | | | | | > | < | | | | | > | < | | < > > | < | | | | | | | > | < | | | < > | | 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 | - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull 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 exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; @throw [OFConnectionFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull 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 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 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 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 { 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); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self |
︙ | ︙ |