Comment: | Add OFSPXSocket |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
857f8edc09086abe9c8f74f7fb216e83 |
User & Date: | js on 2020-04-29 23:59:08 |
Other Links: | manifest | tags |
2020-05-01
| ||
11:09 | OFSPXSocketTests: Handle IPX but not SPX support check-in: 13de836451 user: js tags: trunk | |
2020-04-29
| ||
23:59 | Add OFSPXSocket check-in: 857f8edc09 user: js tags: trunk | |
2020-04-26
| ||
19:39 | Remove redundant arguments from blocks check-in: d7ddb3dbc7 user: js tags: trunk | |
Modified configure.ac from [8421da9224] to [cd621d1afb].
︙ | ︙ | |||
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 | #ifdef AF_IPX egrep_cpp_yes #endif ], [ AC_DEFINE(OF_HAVE_IPX, 1, [Whether we have IPX/SPX]) AC_SUBST(OFIPXSOCKET_M, OFIPXSocket.m) AC_SUBST(OFIPXSOCKETTESTS_M, OFIPXSocketTests.m) ]) ]) AC_CHECK_FUNCS(paccept accept4, break) AC_CHECK_FUNCS(kqueue1 kqueue, [ AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) | > > | 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 | #ifdef AF_IPX egrep_cpp_yes #endif ], [ AC_DEFINE(OF_HAVE_IPX, 1, [Whether we have IPX/SPX]) AC_SUBST(OFIPXSOCKET_M, OFIPXSocket.m) AC_SUBST(OFIPXSOCKETTESTS_M, OFIPXSocketTests.m) AC_SUBST(OFSPXSOCKET_M, OFSPXSocket.m) AC_SUBST(OFSPXSOCKETTESTS_M, OFSPXSocketTests.m) ]) ]) AC_CHECK_FUNCS(paccept accept4, break) AC_CHECK_FUNCS(kqueue1 kqueue, [ AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) |
︙ | ︙ |
Modified extra.mk.in from [d873097dd9] to [ceddd5b2ef].
︙ | ︙ | |||
62 63 64 65 66 67 68 69 70 71 72 73 74 75 | OFHTTPCLIENTTESTS_M = @OFHTTPCLIENTTESTS_M@ OFIPXSOCKETTESTS_M = @OFIPXSOCKETTESTS_M@ OFIPXSOCKET_M = @OFIPXSOCKET_M@ OFKQUEUEKERNELEVENTOBSERVER_M = @OFKQUEUEKERNELEVENTOBSERVER_M@ OFPOLLKERNELEVENTOBSERVER_M = @OFPOLLKERNELEVENTOBSERVER_M@ OFPROCESS_M = @OFPROCESS_M@ OFSELECTKERNELEVENTOBSERVER_M = @OFSELECTKERNELEVENTOBSERVER_M@ OFSTDIOSTREAM_WIN32CONSOLE_M = @OFSTDIOSTREAM_WIN32CONSOLE_M@ REEXPORT_RUNTIME = @REEXPORT_RUNTIME@ REEXPORT_RUNTIME_FRAMEWORK = @REEXPORT_RUNTIME_FRAMEWORK@ RUNTIME = @RUNTIME@ RUNTIME_FRAMEWORK_LIBS = @RUNTIME_FRAMEWORK_LIBS@ RUNTIME_LIBS = @RUNTIME_LIBS@ RUN_TESTS = @RUN_TESTS@ | > > | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | OFHTTPCLIENTTESTS_M = @OFHTTPCLIENTTESTS_M@ OFIPXSOCKETTESTS_M = @OFIPXSOCKETTESTS_M@ OFIPXSOCKET_M = @OFIPXSOCKET_M@ OFKQUEUEKERNELEVENTOBSERVER_M = @OFKQUEUEKERNELEVENTOBSERVER_M@ OFPOLLKERNELEVENTOBSERVER_M = @OFPOLLKERNELEVENTOBSERVER_M@ OFPROCESS_M = @OFPROCESS_M@ OFSELECTKERNELEVENTOBSERVER_M = @OFSELECTKERNELEVENTOBSERVER_M@ OFSPXSOCKETTESTS_M = @OFSPXSOCKETTESTS_M@ OFSPXSOCKET_M = @OFSPXSOCKET_M@ OFSTDIOSTREAM_WIN32CONSOLE_M = @OFSTDIOSTREAM_WIN32CONSOLE_M@ REEXPORT_RUNTIME = @REEXPORT_RUNTIME@ REEXPORT_RUNTIME_FRAMEWORK = @REEXPORT_RUNTIME_FRAMEWORK@ RUNTIME = @RUNTIME@ RUNTIME_FRAMEWORK_LIBS = @RUNTIME_FRAMEWORK_LIBS@ RUNTIME_LIBS = @RUNTIME_LIBS@ RUN_TESTS = @RUN_TESTS@ |
︙ | ︙ |
Modified src/Makefile from [ccd861e5df] to [d03b7e35ac].
︙ | ︙ | |||
142 143 144 145 146 147 148 149 150 151 152 153 154 155 | OFHTTPClient.m \ OFHTTPCookie.m \ OFHTTPCookieManager.m \ OFHTTPRequest.m \ OFHTTPResponse.m \ OFHTTPServer.m \ ${OFIPXSOCKET_M} \ OFSequencedPacketSocket.m \ OFStreamSocket.m \ OFTCPSocket.m \ OFUDPSocket.m \ socket.m SRCS_THREADS = OFCondition.m \ OFMutex.m \ | > | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | OFHTTPClient.m \ OFHTTPCookie.m \ OFHTTPCookieManager.m \ OFHTTPRequest.m \ OFHTTPResponse.m \ OFHTTPServer.m \ ${OFIPXSOCKET_M} \ ${OFSPXSOCKET_M} \ OFSequencedPacketSocket.m \ OFStreamSocket.m \ OFTCPSocket.m \ OFUDPSocket.m \ socket.m SRCS_THREADS = OFCondition.m \ OFMutex.m \ |
︙ | ︙ |
Modified src/OFIPXSocket.h from [4f6d73d640] to [28e1d8cb6f].
︙ | ︙ | |||
60 61 62 63 64 65 66 | * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFIPXSocketDelegate> delegate; /*! | | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @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 port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached */ - (of_socket_address_t)bindToPort: (uint16_t)port packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END |
Modified src/OFRunLoop+Private.h from [72e897ec44] to [f46c29fa91].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | OF_ASSUME_NONNULL_BEGIN #ifdef OF_HAVE_SOCKETS @protocol OFRunLoopConnectDelegate <OFObject> - (void)of_socketDidConnect: (id)socket exception: (nullable id)exception; @end #endif @interface OFRunLoop () + (void)of_setMainRunLoop: (OFRunLoop *)runLoop; #ifdef OF_HAVE_SOCKETS + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *) | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | OF_ASSUME_NONNULL_BEGIN #ifdef OF_HAVE_SOCKETS @protocol OFRunLoopConnectDelegate <OFObject> - (void)of_socketDidConnect: (id)socket exception: (nullable id)exception; - (id)of_connectionFailedExceptionForErrNo: (int)errNo; @end #endif @interface OFRunLoop () + (void)of_setMainRunLoop: (OFRunLoop *)runLoop; #ifdef OF_HAVE_SOCKETS + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *) |
︙ | ︙ |
Modified src/OFRunLoop.m from [964085efa2] to [8701d2b9f0].
︙ | ︙ | |||
40 41 42 43 44 45 46 | #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" | < < < | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" of_run_loop_mode_t of_run_loop_mode_default = @"of_run_loop_mode_default"; static OFRunLoop *mainRunLoop = nil; @interface OFRunLoopState: OFObject #ifdef OF_HAVE_SOCKETS <OFKernelEventObserverDelegate> |
︙ | ︙ | |||
716 717 718 719 720 721 722 | @implementation OFRunLoopConnectQueueItem - (bool)handleObject: (id)object { id exception = nil; int errNo; if ((errNo = [object of_socketError]) != 0) | < | < < | | 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | @implementation OFRunLoopConnectQueueItem - (bool)handleObject: (id)object { id exception = nil; int errNo; if ((errNo = [object of_socketError]) != 0) exception = [_delegate of_connectionFailedExceptionForErrNo: errNo]; if ([_delegate respondsToSelector: @selector(of_socketDidConnect:exception:)]) { /* * Make sure we only call the delegate once we removed the * socket from the kernel event observer. This is necessary as * otherwise we could try to connect to the next address and it |
︙ | ︙ |
Added src/OFSPXSocket.h version [514525c494].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018, 2019, 2020 * 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 "OFSequencedPacketSocket.h" #import "OFRunLoop.h" #import "socket.h" OF_ASSUME_NONNULL_BEGIN /*! @file */ @class OFSPXSocket; @class OFString; #ifdef OF_HAVE_BLOCKS /*! * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^of_spx_socket_async_connect_block_t)(id _Nullable exception); #endif /*! * @protocol OFSPXSocketDelegate OFSPXSocket.h ObjFW/OFSPXSocket.h * * A delegate for OFSPXSocket. */ @protocol OFSPXSocketDelegate <OFSequencedPacketSocketDelegate> @optional /*! * @brief A method which is called when a socket connected. * * @param socket The socket which connected * @param node The node the socket connected to * @param network The network of 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 didConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port exception: (nullable id)exception; @end /*! * @class OFSPXSocket OFSPXSocket.h ObjFW/OFSPXSocket.h * * @brief A class which provides methods to create and use SPX sockets. * * To connect to a server, create a socket and connect it. * To create a server, create a socket, bind it and listen on it. */ @interface OFSPXSocket: OFSequencedPacketSocket { OF_RESERVE_IVARS(4) } /*! * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFSPXSocketDelegate> delegate; /*! * @brief 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 */ - (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port; /*! * @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 */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port; /*! * @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 */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (of_run_loop_mode_t)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)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port block: (of_spx_socket_async_connect_block_t)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)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (of_run_loop_mode_t)runLoopMode block: (of_spx_socket_async_connect_block_t)block; #endif /*! * @brief Bind the socket to the specified network, node and port with the * specified packet type. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached */ - (of_socket_address_t)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Added src/OFSPXSocket.m version [0d3987e8b0].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 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 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018, 2019, 2020 * 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> #import "OFSPXSocket.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" #import "OFConnectionFailedException.h" #import "socket.h" #import "socket_helpers.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 #endif #define SPX_PACKET_TYPE 5 @interface OFSPXSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate> { OFSPXSocket *_socket; unsigned char _node[IPX_NODE_LEN]; uint32_t _network; uint16_t _port; #ifdef OF_HAVE_BLOCKS of_spx_socket_async_connect_block_t _block; #endif } - (instancetype)initWithSocket: (OFSPXSocket *)socket node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (of_spx_socket_async_connect_block_t)block #endif ; - (void)startWithRunLoopMode: (of_run_loop_mode_t)runLoopMode; @end @implementation OFSPXSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXSocket *)sock node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (of_spx_socket_async_connect_block_t)block #endif { self = [super init]; @try { _socket = [sock retain]; memcpy(_node, node, IPX_NODE_LEN); _network = network; _port = port; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_socket release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } - (void)startWithRunLoopMode: (of_run_loop_mode_t)runLoopMode { id exception = nil; _socket.blocking = false; @try { [_socket connectToNode: _node network: _network port: _port]; } @catch (OFConnectionFailedException *e) { if (e.errNo == EINPROGRESS) { [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } exception = e; } [self performSelector: @selector(of_socketDidConnect:exception:) withObject: _socket withObject: exception afterDelay: 0]; } - (void)of_socketDidConnect: (id)sock exception: (id)exception { id <OFSPXSocketDelegate> delegate = ((OFSPXSocket *)sock).delegate; if (exception == nil) ((OFSPXSocket *)sock).blocking = true; #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(exception); else { #endif if ([delegate respondsToSelector: @selector(socket:didConnectToNode:network:port:exception:)]) [delegate socket: _socket didConnectToNode: _node network: _network port: _port exception: exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { return [OFConnectionFailedException exceptionWithNode: _node network: _network port: _port socket: _socket errNo: errNo]; } @end @implementation OFSPXSocket @dynamic delegate; - (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { of_socket_address_t address = of_socket_address_ipx(network, node, port); #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET) @throw [OFConnectionFailedException exceptionWithNode: node network: network port: port socket: self errNo: of_socket_errno()]; #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, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = of_socket_errno(); closesocket(_socket); @throw [OFConnectionFailedException exceptionWithNode: node network: network port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { [self asyncConnectToNode: node network: network port: port runLoopMode: of_run_loop_mode_default]; } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (of_run_loop_mode_t)runLoopMode { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self node: node network: network port: port #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port block: (of_spx_socket_async_connect_block_t)block { [self asyncConnectToNode: node network: network port: port runLoopMode: of_run_loop_mode_default block: block]; } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (of_run_loop_mode_t)runLoopMode block: (of_spx_socket_async_connect_block_t)block { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self node: node network: network port: port block: block ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif - (of_socket_address_t)bindToPort: (uint16_t)port { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; of_socket_address_t address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; address = of_socket_address_ipx(0, zeroNode, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithPort: port packetType: SPX_PACKET_TYPE socket: self errNo: of_socket_errno()]; _blocking = 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, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = of_socket_errno(); if (errNo != EINPROGRESS) { closesocket(_socket); _socket = INVALID_SOCKET; } @throw [OFBindFailedException exceptionWithPort: port packetType: SPX_PACKET_TYPE socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OF_SOCKET_ADDRESS_FAMILY_IPX; address.length = (socklen_t)sizeof(address.sockaddr); if (of_getsockname(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = of_socket_errno(); closesocket(_socket); _socket = INVALID_SOCKET; @throw [OFBindFailedException exceptionWithPort: port packetType: SPX_PACKET_TYPE socket: self errNo: errNo]; } if (address.sockaddr.sockaddr.sa_family != AF_IPX) { closesocket(_socket); _socket = INVALID_SOCKET; @throw [OFBindFailedException exceptionWithPort: port packetType: SPX_PACKET_TYPE socket: self errNo: EAFNOSUPPORT]; } return address; } @end |
Modified src/OFStream.h from [854f995c5b] to [849d120fde].
︙ | ︙ | |||
188 189 190 191 192 193 194 | * override these methods without the `lowlevel` prefix, you *will* break * caching and get broken results! */ @interface OFStream: OFObject <OFCopying> { bool _blocking; id _Nullable _delegate; | | | 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | * override these methods without the `lowlevel` prefix, you *will* break * caching and get broken results! */ @interface OFStream: OFObject <OFCopying> { bool _blocking; id _Nullable _delegate; #ifndef OF_SEEKABLE_STREAM_M @private #endif char *_Nullable _readBuffer, *_Nullable _readBufferMemory; char *_Nullable _writeBuffer; size_t _readBufferLength, _writeBufferLength; bool _writeBuffered, _waitingForDelimiter; OF_RESERVE_IVARS(4) |
︙ | ︙ |
Modified src/OFTCPSocket.m from [36820b9499] to [ef285e844b].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * * 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. */ | < | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * 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. */ #define __NO_EXT_QNX #include "config.h" #include <assert.h> #include <errno.h> #include <stdio.h> |
︙ | ︙ | |||
99 100 101 102 103 104 105 | } - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port SOCKS5Host: (OFString *)SOCKS5Host SOCKS5Port: (uint16_t)SOCKS5Port | | < < < < < | > | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | } - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port SOCKS5Host: (OFString *)SOCKS5Host SOCKS5Port: (uint16_t)SOCKS5Port delegate: (id <OFTCPSocketDelegate>)delegate #ifdef OF_HAVE_BLOCKS block: (of_tcp_socket_async_connect_block_t)block #endif ; - (void)didConnect; - (void)tryNextAddressWithRunLoopMode: (of_run_loop_mode_t)runLoopMode; - (void)startWithRunLoopMode: (of_run_loop_mode_t)runLoopMode; - (void)sendSOCKS5Request; @end @interface OFTCPSocketConnectDelegate: OFObject <OFTCPSocketDelegate> |
︙ | ︙ | |||
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 | @implementation OFTCPSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port SOCKS5Host: (OFString *)SOCKS5Host SOCKS5Port: (uint16_t)SOCKS5Port delegate: (id <OFTCPSocketDelegate>)delegate { self = [super init]; @try { _socket = [sock retain]; _host = [host copy]; _port = port; _SOCKS5Host = [SOCKS5Host copy]; _SOCKS5Port = SOCKS5Port; _delegate = [delegate retain]; _socket.delegate = self; } @catch (id e) { [self release]; @throw e; } return self; } | > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 | @implementation OFTCPSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port SOCKS5Host: (OFString *)SOCKS5Host SOCKS5Port: (uint16_t)SOCKS5Port delegate: (id <OFTCPSocketDelegate>)delegate #ifdef OF_HAVE_BLOCKS block: (of_tcp_socket_async_connect_block_t)block #endif { self = [super init]; @try { _socket = [sock retain]; _host = [host copy]; _port = port; _SOCKS5Host = [SOCKS5Host copy]; _SOCKS5Port = SOCKS5Port; _delegate = [delegate retain]; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif _socket.delegate = self; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { #ifdef OF_HAVE_BLOCKS if (_block == NULL) #endif if (_socket.delegate == self) _socket.delegate = _delegate; |
︙ | ︙ | |||
263 264 265 266 267 268 269 270 271 272 273 274 275 276 | } if (_SOCKS5Host != nil) [self sendSOCKS5Request]; else [self didConnect]; } - (void)tryNextAddressWithRunLoopMode: (of_run_loop_mode_t)runLoopMode { of_socket_address_t address = *(const of_socket_address_t *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; int errNo; | > > > > > > > > | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | } if (_SOCKS5Host != nil) [self sendSOCKS5Request]; else [self didConnect]; } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { return [OFConnectionFailedException exceptionWithHost: _host port: _port socket: _socket errNo: errNo]; } - (void)tryNextAddressWithRunLoopMode: (of_run_loop_mode_t)runLoopMode { of_socket_address_t address = *(const of_socket_address_t *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; int errNo; |
︙ | ︙ | |||
699 700 701 702 703 704 705 | - (bool)of_connectSocketToAddress: (const of_socket_address_t *)address errNo: (int *)errNo { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; | | | 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | - (bool)of_connectSocketToAddress: (const of_socket_address_t *)address errNo: (int *)errNo { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; if (connect(_socket, &address->sockaddr.sockaddr, address->length) != 0) { *errNo = of_socket_errno(); return false; } return true; } |
︙ | ︙ | |||
764 765 766 767 768 769 770 | [[[[OFTCPSocketAsyncConnectDelegate alloc] initWithSocket: self host: host port: port SOCKS5Host: _SOCKS5Host SOCKS5Port: _SOCKS5Port | | > > > | | 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | [[[[OFTCPSocketAsyncConnectDelegate alloc] initWithSocket: self host: host port: port SOCKS5Host: _SOCKS5Host SOCKS5Port: _SOCKS5Port delegate: _delegate #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port |
︙ | ︙ | |||
794 795 796 797 798 799 800 801 802 803 804 805 806 807 | [[[[OFTCPSocketAsyncConnectDelegate alloc] initWithSocket: self host: host port: port SOCKS5Host: _SOCKS5Host SOCKS5Port: _SOCKS5Port block: block] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif | > | 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 | [[[[OFTCPSocketAsyncConnectDelegate alloc] initWithSocket: self host: host port: port SOCKS5Host: _SOCKS5Host SOCKS5Port: _SOCKS5Port delegate: nil block: block] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif |
︙ | ︙ |
Modified src/ObjFW.h from [fc9f9015ac] to [923afa7ee5].
︙ | ︙ | |||
76 77 78 79 80 81 82 83 84 85 86 87 88 89 | # import "OFKernelEventObserver.h" # import "OFDNSQuery.h" # import "OFDNSResourceRecord.h" # import "OFDNSResponse.h" # import "OFDNSResolver.h" # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # endif #endif #ifdef OF_HAVE_SOCKETS # ifdef OF_HAVE_THREADS # import "OFHTTPClient.h" # endif # import "OFHTTPCookie.h" | > | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | # import "OFKernelEventObserver.h" # import "OFDNSQuery.h" # import "OFDNSResourceRecord.h" # import "OFDNSResponse.h" # import "OFDNSResolver.h" # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # import "OFSPXSocket.h" # endif #endif #ifdef OF_HAVE_SOCKETS # ifdef OF_HAVE_THREADS # import "OFHTTPClient.h" # endif # import "OFHTTPCookie.h" |
︙ | ︙ |
Modified src/exceptions/OFConnectionFailedException.h from [e2e47e53e8] to [cd5a362f90].
︙ | ︙ | |||
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 | */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN /*! * @class OFConnectionFailedException \ * OFConnectionFailedException.h ObjFW/OFConnectionFailedException.h * * @brief An exception indicating that a connection could not be established. */ @interface OFConnectionFailedException: OFException { id _socket; OFString *_host; uint16_t _port; int _errNo; } /*! * @brief The socket which could not connect. */ @property (readonly, nonatomic) id socket; /*! * @brief The host to which the connection failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; /*! * @brief The port on the host to which the connection failed. */ @property (readonly, nonatomic) uint16_t port; /*! * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; + (instancetype)exception OF_UNAVAILABLE; | > > > > > > > > > > > > > > | 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 | */ #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #import "socket.h" OF_ASSUME_NONNULL_BEGIN /*! * @class OFConnectionFailedException \ * OFConnectionFailedException.h ObjFW/OFConnectionFailedException.h * * @brief An exception indicating that a connection could not be established. */ @interface OFConnectionFailedException: OFException { id _socket; OFString *_host; uint16_t _port; unsigned char _node[IPX_NODE_LEN]; uint32_t _network; int _errNo; } /*! * @brief The socket which could not connect. */ @property (readonly, nonatomic) id socket; /*! * @brief The host to which the connection failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; /*! * @brief The port on the host to which the connection failed. */ @property (readonly, nonatomic) uint16_t port; /*! * @brief The IPX node to which the connection failed. */ @property (readonly, nonatomic) unsigned char *node; /*! * @brief The IPX network of the node to which the connection failed. */ @property (readonly, nonatomic) uint32_t network; /*! * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; + (instancetype)exception OF_UNAVAILABLE; |
︙ | ︙ | |||
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | * @return A new, autoreleased connection failed exception */ + (instancetype)exceptionWithHost: (nullable OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /*! * @brief Initializes an already allocated connection failed exception. * * @param host The host to which the connection failed * @param port The port on the host to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return An initialized connection failed exception */ - (instancetype)initWithHost: (nullable OFString *)host port: (uint16_t)port socket: (id)socket | > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > | 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 127 128 129 130 131 132 133 134 135 136 137 138 139 | * @return A new, autoreleased connection failed exception */ + (instancetype)exceptionWithHost: (nullable OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo; /*! * @brief Creates a new, autoreleased connection failed exception. * * @param node The node to which the connection failed * @param network The IPX network of the node to which the connection failed * @param port The port on the node to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return A new, autoreleased connection failed exception */ + (instancetype)exceptionWithNode: (unsigned char [_Nullable IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port socket: (id)socket errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /*! * @brief Initializes an already allocated connection failed exception. * * @param host The host to which the connection failed * @param port The port on the host to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return An initialized connection failed exception */ - (instancetype)initWithHost: (nullable OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo; /*! * @brief Initializes an already allocated connection failed exception. * * @param node The node to which the connection failed * @param network The IPX network of the node to which the connection failed * @param port The port on the node to which the connection failed * @param socket The socket which could not connect * @param errNo The errno of the error that occurred * @return An initialized connection failed exception */ - (instancetype)initWithNode: (unsigned char [_Nullable IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port socket: (id)socket errNo: (int)errNo; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFConnectionFailedException.m from [19c84f566e] to [d44715253f].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #include "config.h" #import "OFConnectionFailedException.h" #import "OFString.h" @implementation OFConnectionFailedException | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 127 128 129 130 131 132 133 134 135 136 | #include "config.h" #import "OFConnectionFailedException.h" #import "OFString.h" @implementation OFConnectionFailedException @synthesize host = _host, port = _port, network = _network, socket = _socket; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo { return [[[self alloc] initWithHost: host port: port socket: socket errNo: errNo] autorelease]; } + (instancetype)exceptionWithNode: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port socket: (id)socket errNo: (int)errNo { return [[[self alloc] initWithNode: node network: network port: port socket: socket errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithHost: (OFString *)host port: (uint16_t)port socket: (id)socket errNo: (int)errNo { self = [super init]; @try { _host = [host copy]; _port = port; _socket = [socket retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithNode: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port socket: (id)socket errNo: (int)errNo { self = [super init]; @try { memcpy(_node, node, IPX_NODE_LEN); _network = network; _port = port; _socket = [socket retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [_socket release]; [super dealloc]; } - (unsigned char *)node { return _node; } - (OFString *)description { if (_host != nil) return [OFString stringWithFormat: @"A connection to %@ on port %" @PRIu16 @" could not be " @"established in socket of type %@: %@", _host, _port, [_socket class], of_strerror(_errNo)]; else if (memcmp(_node, "\0\0\0\0\0", IPX_NODE_LEN) == 0) return [OFString stringWithFormat: @"A connection to %02X%02X%02X%02X%02X%02X port %" @PRIu16 @" on network %" @PRIX32 " could not be established in " @"socket of type %@: %@", _node[0], _node[1], _node[2], _node[3], _node[4], _node[5], _port, _network, [_socket class], of_strerror(_errNo)]; else return [OFString stringWithFormat: @"A connection could not be established in socket of " @"type %@: %@", [_socket class], of_strerror(_errNo)]; } @end |
Modified tests/Makefile from [9e51c1dedf] to [d08febc49c].
︙ | ︙ | |||
14 15 16 17 18 19 20 | OFASN1DERValueTests.m \ OFArrayTests.m \ ${OFBLOCKTESTS_M} \ OFCharacterSetTests.m \ OFDataTests.m \ OFDateTests.m \ OFDictionaryTests.m \ | < | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | OFASN1DERValueTests.m \ OFArrayTests.m \ ${OFBLOCKTESTS_M} \ OFCharacterSetTests.m \ OFDataTests.m \ OFDateTests.m \ OFDictionaryTests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFListTests.m \ OFLocaleTests.m \ OFMethodSignatureTests.m \ OFNumberTests.m \ OFObjectTests.m \ |
︙ | ︙ | |||
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | OFSHA384HashTests.m \ OFSHA512HashTests.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ ${OFHTTPCLIENTTESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ SocketTests.m SRCS_THREADS = OFThreadTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile | > > | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | OFSHA384HashTests.m \ OFSHA512HashTests.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ ${OFHTTPCLIENTTESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ ${OFIPXSOCKETTESTS_M} \ OFKernelEventObserverTests.m \ ${OFSPXSOCKETTESTS_M} \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ SocketTests.m SRCS_THREADS = OFThreadTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile |
︙ | ︙ |
Added tests/OFSPXSocketTests.m version [4b497d9d36].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018, 2019, 2020 * 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> #import "TestsAppDelegate.h" static OFString *module = @"OFSPXSocket"; @implementation TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests { void *pool = objc_autoreleasePoolPush(); OFSPXSocket *sockClient, *sockServer, *sockAccepted;; of_socket_address_t address1; const of_socket_address_t *address2; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; uint16_t port; char buffer[5]; TEST(@"+[socket]", (sockClient = [OFSPXSocket socket]) && (sockServer = [OFSPXSocket socket])) @try { TEST(@"-[bindToPort:]", R(address1 = [sockServer bindToPort: 0])) } @catch (OFBindFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [self outputString: @"[OFSPXSocket] -[bindToPort:]: " @"IPX unsupported, skipping tests\n" inColor: GREEN]; break; case EADDRNOTAVAIL: [self outputString: @"[OFSPXSocket] -[bindToPort:]: " @"IPX not configured, skipping " @"tests\n" inColor: GREEN]; break; default: @throw e; } objc_autoreleasePoolPop(pool); return; } of_socket_address_get_ipx_node(&address1, node); network = of_socket_address_get_ipx_network(&address1); port = of_socket_address_get_port(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNode:network:port:]", R([sockClient connectToNode: node network: network port: port])) TEST(@"-[accept]", (sockAccepted = [sockServer accept])) TEST(@"-[sendBuffer:length:]", R([sockAccepted sendBuffer: "Hello" length: 5])) TEST(@"-[receiveIntoBuffer:length:]", [sockClient receiveIntoBuffer: buffer length: 5] == 5 && memcmp(buffer, "Hello", 5) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && R(of_socket_address_get_ipx_node(address2, node2)) && memcmp(node, node2, IPX_NODE_LEN) == 0 && of_socket_address_get_ipx_network(address2) == network) objc_autoreleasePoolPop(pool); } @end |
Modified tests/TestsAppDelegate.h from [667b7617f0] to [3fbc6db155].
︙ | ︙ | |||
225 226 227 228 229 230 231 232 233 234 235 236 237 238 | @interface TestsAppDelegate (OFSHA384HashTests) - (void)SHA384HashTests; @end @interface TestsAppDelegate (OFSHA512HashTests) - (void)SHA512HashTests; @end @interface TestsAppDelegate (OFSystemInfoTests) - (void)systemInfoTests; @end @interface TestsAppDelegate (OFHMACTests) - (void)HMACTests; | > > > > | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | @interface TestsAppDelegate (OFSHA384HashTests) - (void)SHA384HashTests; @end @interface TestsAppDelegate (OFSHA512HashTests) - (void)SHA512HashTests; @end @interface TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests; @end @interface TestsAppDelegate (OFSystemInfoTests) - (void)systemInfoTests; @end @interface TestsAppDelegate (OFHMACTests) - (void)HMACTests; |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [6f16d81614] to [888148da42].
︙ | ︙ | |||
413 414 415 416 417 418 419 420 421 422 423 424 425 426 | #endif #ifdef OF_HAVE_SOCKETS [self socketTests]; [self TCPSocketTests]; [self UDPSocketTests]; # ifdef OF_HAVE_IPX [self IPXSocketTests]; # endif [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS [self threadTests]; #endif [self URLTests]; | > | 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | #endif #ifdef OF_HAVE_SOCKETS [self socketTests]; [self TCPSocketTests]; [self UDPSocketTests]; # ifdef OF_HAVE_IPX [self IPXSocketTests]; [self SPXSocketTests]; # endif [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS [self threadTests]; #endif [self URLTests]; |
︙ | ︙ |