Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1391,17 +1391,17 @@ AC_CHECK_HEADER(netinet/tcp.h, [ AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1, [Whether we have netinet/tcp.h]) ]) AC_CHECK_HEADERS([arpa/inet.h netdb.h]) + AC_CHECK_HEADER(sys/un.h, [ + AC_DEFINE(OF_HAVE_SYS_UN_H, 1, [Whether we have sys/un.h]) + ]) AC_CHECK_HEADER(netipx/ipx.h, [ AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1, [Whether we have netipx/ipx.h]) ]) - AC_CHECK_HEADER(sys/un.h, [ - AC_DEFINE(OF_HAVE_SYS_UN_H, 1, [Whether we have sys/un.h]) - ]) AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [ AC_EGREP_CPP(egrep_cpp_yes, [ #ifdef _WIN32 typedef int BOOL; @@ -1450,10 +1450,44 @@ # endif # include # include #endif ]) + + AC_CHECK_HEADERS(afunix.h, [ + AC_DEFINE(OF_HAVE_AFUNIX_H, 1, [Whether we have afunix.h]) + ], [], [ + #ifdef _WIN32 + # include + #endif + ]) + AC_CHECK_MEMBER(struct sockaddr_un.sun_path, [ + AC_DEFINE(OF_HAVE_UNIX_SOCKETS, 1, + [Whether we have UNIX sockets]) + AC_SUBST(USE_SRCS_UNIX_SOCKETS, '${SRCS_UNIX_SOCKETS}') + ], [], [ + #ifdef OF_HAVE_SYS_TYPES_H + # include + #endif + #ifdef OF_HAVE_SYS_UN_H + # include + #endif + #ifdef _WIN32 + # include + #endif + #ifdef HAVE_AFUNIX_H + # include + #endif + + #ifdef __morphos__ + # error MorphOS has the struct but does not support it + #endif + + #ifdef __MINT__ + # error Gives invalid argument at runtime + #endif + ]) AC_CHECK_MEMBER(struct sockaddr_ipx.sipx_network, [], [ AC_CHECK_MEMBER(struct sockaddr_ipx.sa_netnum, [], [], [ #ifdef _WIN32 typedef int BOOL; @@ -1523,44 +1557,10 @@ AC_DEFINE(OF_HAVE_IPX, 1, [Whether we have IPX/SPX]) AC_SUBST(USE_SRCS_IPX, '${SRCS_IPX}') ]) ]) - AC_CHECK_HEADERS(afunix.h, [ - AC_DEFINE(OF_HAVE_AFUNIX_H, 1, [Whether we have afunix.h]) - ], [], [ - #ifdef _WIN32 - # include - #endif - ]) - AC_CHECK_MEMBER(struct sockaddr_un.sun_path, [ - AC_DEFINE(OF_HAVE_UNIX_SOCKETS, 1, - [Whether we have UNIX sockets]) - AC_SUBST(USE_SRCS_UNIX_SOCKETS, '${SRCS_UNIX_SOCKETS}') - ], [], [ - #ifdef OF_HAVE_SYS_TYPES_H - # include - #endif - #ifdef OF_HAVE_SYS_UN_H - # include - #endif - #ifdef _WIN32 - # include - #endif - #ifdef HAVE_AFUNIX_H - # include - #endif - - #ifdef __morphos__ - # error MorphOS has the struct but does not support it - #endif - - #ifdef __MINT__ - # error Gives invalid argument at runtime - #endif - ]) - AC_CHECK_FUNCS(paccept accept4, break) AC_CHECK_FUNCS(kqueue1 kqueue, [ AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) AC_SUBST(OF_KQUEUE_KERNEL_EVENT_OBSERVER_M, Index: src/OFDatagramSocket.m ================================================================== --- src/OFDatagramSocket.m +++ src/OFDatagramSocket.m @@ -201,19 +201,19 @@ #ifdef OF_HAVE_IPV6 case AF_INET6: sender->family = OFSocketAddressFamilyIPv6; break; #endif -#ifdef OF_HAVE_IPX - case AF_IPX: - sender->family = OFSocketAddressFamilyIPX; - break; -#endif #ifdef OF_HAVE_UNIX_SOCKETS case AF_UNIX: sender->family = OFSocketAddressFamilyUNIX; break; +#endif +#ifdef OF_HAVE_IPX + case AF_IPX: + sender->family = OFSocketAddressFamilyIPX; + break; #endif default: sender->family = OFSocketAddressFamilyUnknown; break; } Index: src/OFIPXSocket.m ================================================================== --- src/OFIPXSocket.m +++ src/OFIPXSocket.m @@ -41,11 +41,11 @@ #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = OFSocketAddressMakeIPX(zeroNode, 0, port); + address = OFSocketAddressMakeIPX(0, zeroNode, port); #ifdef OF_WINDOWS protocol = NSPROTO_IPX + packetType; #else _packetType = address.sockaddr.ipx.sipx_type = packetType; Index: src/OFSPXSocket.h ================================================================== --- src/OFSPXSocket.h +++ src/OFSPXSocket.h @@ -42,21 +42,21 @@ @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 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 - didConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - exception: (nullable id)exception; +- (void)socket: (OFSPXSocket *)socket + didConnectToNetwork: (uint32_t)network + node: (unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + exception: (nullable id)exception; @end /** * @class OFSPXSocket OFSPXSocket.h ObjFW/OFSPXSocket.h * @@ -83,44 +83,44 @@ id 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: (OFRunLoopMode)runLoopMode; + * @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)connectToNetwork: (uint32_t)network + node: (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 + 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 + port: (uint16_t)port + runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * @@ -128,14 +128,14 @@ * @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: (OFSPXSocketAsyncConnectBlock)block; +- (void)asyncConnectToNetwork: (uint32_t)network + node: (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 @@ -143,15 +143,15 @@ * @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: (OFRunLoopMode)runLoopMode - block: (OFSPXSocketAsyncConnectBlock)block; +- (void)asyncConnectToNetwork: (uint32_t)network + node: (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. * Index: src/OFSPXSocket.m ================================================================== --- src/OFSPXSocket.m +++ src/OFSPXSocket.m @@ -44,21 +44,21 @@ OF_DIRECT_MEMBERS @interface OFSPXSocketAsyncConnectDelegate: OFObject { OFSPXSocket *_socket; - unsigned char _node[IPX_NODE_LEN]; uint32_t _network; + unsigned char _node[IPX_NODE_LEN]; uint16_t _port; #ifdef OF_HAVE_BLOCKS OFSPXSocketAsyncConnectBlock _block; #endif } - (instancetype)initWithSocket: (OFSPXSocket *)socket - node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif ; @@ -65,23 +65,23 @@ - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end @implementation OFSPXSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXSocket *)sock - node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; - memcpy(_node, node, IPX_NODE_LEN); _network = network; + memcpy(_node, node, IPX_NODE_LEN); _port = port; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif } @catch (id e) { @@ -103,11 +103,11 @@ } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = - OFSocketAddressMakeIPX(_node, _network, _port); + OFSocketAddressMakeIPX(_network, _node, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; @@ -151,28 +151,28 @@ 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]; + @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 exceptionWithNode: _node - network: _network - port: _port - socket: _socket - errNo: errNo]; + return [OFConnectionFailedException exceptionWithNetwork: _network + node: _node + port: _port + socket: _socket + errNo: errNo]; } @end @implementation OFSPXSocket @dynamic delegate; @@ -221,58 +221,58 @@ { closesocket(_socket); _socket = OFInvalidSocketHandle; } -- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port +- (void)connectToNetwork: (uint32_t)network + node: (unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port { - OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port); + OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectionFailedException - exceptionWithNode: node - network: network - port: port - socket: self - errNo: errNo]; + exceptionWithNetwork: network + node: node + port: port + socket: self + errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; @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: OFDefaultRunLoopMode]; -} - -- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - runLoopMode: (OFRunLoopMode)runLoopMode + 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(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self - node: node network: network + node: node port: port #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; @@ -279,34 +279,34 @@ 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: (OFSPXSocketAsyncConnectBlock)block -{ - [self asyncConnectToNode: node - network: network - port: port - runLoopMode: OFDefaultRunLoopMode - block: block]; -} - -- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSPXSocketAsyncConnectBlock)block +- (void)asyncConnectToNetwork: (uint32_t)network + node: (unsigned char [_Nonnull 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 + port: (uint16_t)port + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFSPXSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self - node: node network: network + node: node port: port block: block ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); @@ -322,11 +322,11 @@ #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = OFSocketAddressMakeIPX(zeroNode, 0, port); + address = OFSocketAddressMakeIPX(0, zeroNode, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) @throw [OFBindFailedException Index: src/OFSPXStreamSocket.h ================================================================== --- src/OFSPXStreamSocket.h +++ src/OFSPXStreamSocket.h @@ -43,21 +43,21 @@ @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 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 - didConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - exception: (nullable id)exception; +- (void)socket: (OFSPXStreamSocket *)socket + didConnectToNetwork: (uint32_t)network + node: (unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + exception: (nullable id)exception; @end /** * @class OFSPXStreamSocket OFSPXStreamSocket.h ObjFW/OFSPXStreamSocket.h * @@ -84,79 +84,79 @@ id delegate; /** * @brief Connect the OFSPXStreamSocket 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 OFSPXStreamSocket 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 OFSPXStreamSocket 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: (OFRunLoopMode)runLoopMode; + * @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)connectToNetwork: (uint32_t)network + node: (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 + 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 + port: (uint16_t)port + runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * - * @param node The node to connect to * @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)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - block: (OFSPXStreamSocketAsyncConnectBlock)block; +- (void)asyncConnectToNetwork: (uint32_t)network + node: (unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + block: (OFSPXStreamSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * - * @param node The node to connect to * @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)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSPXStreamSocketAsyncConnectBlock)block; +- (void)asyncConnectToNetwork: (uint32_t)network + node: (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. * Index: src/OFSPXStreamSocket.m ================================================================== --- src/OFSPXStreamSocket.m +++ src/OFSPXStreamSocket.m @@ -45,21 +45,21 @@ OF_DIRECT_MEMBERS @interface OFSPXStreamSocketAsyncConnectDelegate: OFObject { OFSPXStreamSocket *_socket; - unsigned char _node[IPX_NODE_LEN]; uint32_t _network; + unsigned char _node[IPX_NODE_LEN]; uint16_t _port; #ifdef OF_HAVE_BLOCKS OFSPXStreamSocketAsyncConnectBlock _block; #endif } - (instancetype)initWithSocket: (OFSPXStreamSocket *)socket - node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif ; @@ -66,23 +66,23 @@ - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end @implementation OFSPXStreamSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXStreamSocket *)sock - node: (unsigned char [IPX_NODE_LEN])node 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]; - memcpy(_node, node, IPX_NODE_LEN); _network = network; + memcpy(_node, node, IPX_NODE_LEN); _port = port; #ifdef OF_HAVE_BLOCKS _block = [block copy]; #endif } @catch (id e) { @@ -104,11 +104,11 @@ } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = - OFSocketAddressMakeIPX(_node, _network, _port); + OFSocketAddressMakeIPX(_network, _node, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; @@ -153,28 +153,28 @@ 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]; + @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 exceptionWithNode: _node - network: _network - port: _port - socket: _socket - errNo: errNo]; + return [OFConnectionFailedException exceptionWithNetwork: _network + node: _node + port: _port + socket: _socket + errNo: errNo]; } @end @implementation OFSPXStreamSocket @dynamic delegate; @@ -223,58 +223,58 @@ { closesocket(_socket); _socket = OFInvalidSocketHandle; } -- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port +- (void)connectToNetwork: (uint32_t)network + node: (unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port { - OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port); + OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectionFailedException - exceptionWithNode: node - network: network - port: port - socket: self - errNo: errNo]; + exceptionWithNetwork: network + node: node + port: port + socket: self + errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; @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: OFDefaultRunLoopMode]; -} - -- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - runLoopMode: (OFRunLoopMode)runLoopMode + 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 - node: node network: network + node: node port: port #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; @@ -281,34 +281,34 @@ 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: (OFSPXStreamSocketAsyncConnectBlock)block -{ - [self asyncConnectToNode: node - network: network - port: port - runLoopMode: OFDefaultRunLoopMode - block: block]; -} - -- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSPXStreamSocketAsyncConnectBlock)block +- (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 - node: node network: network + node: node port: port block: block ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); @@ -324,11 +324,11 @@ #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = OFSocketAddressMakeIPX(zeroNode, 0, port); + address = OFSocketAddressMakeIPX(0, zeroNode, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithPort: port Index: src/OFSocket.h ================================================================== --- src/OFSocket.h +++ src/OFSocket.h @@ -97,14 +97,14 @@ OFSocketAddressFamilyUnknown, /** IPv4 */ OFSocketAddressFamilyIPv4, /** IPv6 */ OFSocketAddressFamilyIPv6, + /** UNIX */ + OFSocketAddressFamilyUNIX, /** IPX */ OFSocketAddressFamilyIPX, - /** UNIX */ - OFSocketAddressFamilyUNIX, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 @@ -116,10 +116,17 @@ uint8_t s6_addr[16]; } sin6_addr; uint32_t sin6_scope_id; }; #endif + +#if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT) +struct sockaddr_un { + sa_family_t sun_family; + char sun_path[108]; +}; +#endif #ifndef OF_HAVE_IPX # define IPX_NODE_LEN 6 struct sockaddr_ipx { sa_family_t sipx_family; @@ -135,17 +142,10 @@ # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif -#if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT) -struct sockaddr_un { - sa_family_t sun_family; - char sun_path[108]; -}; -#endif - /** * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h * * @brief A struct which represents a host / port pair for a socket. */ @@ -160,12 +160,12 @@ OFSocketAddressFamily family; union { struct sockaddr sockaddr; struct sockaddr_in in; struct sockaddr_in6 in6; - struct sockaddr_ipx ipx; struct sockaddr_un un; + struct sockaddr_ipx ipx; } sockaddr; socklen_t length; } OFSocketAddress; #ifdef __cplusplus @@ -197,30 +197,29 @@ * @param port The port to use * @return The parsed IPv6 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); -/** - * @brief Creates an IPX address for the specified node, network and port. - * - * @param node The node in the IPX network - * @param network The IPX network - * @param port The IPX port (sometimes called socket number) on the node - * @return An IPX socket address with the specified node, network and port. - */ -extern OFSocketAddress OFSocketAddressMakeIPX( - const unsigned char node[_Nonnull IPX_NODE_LEN], uint32_t network, - uint16_t port); - /** * @brief Creates a UNIX socket address from the specified path. * * @param path The path of the UNIX socket * @return A UNIX socket address with the specified path */ extern OFSocketAddress OFSocketAddressMakeUNIX(OFString *path); +/** + * @brief Creates an IPX address for the specified node, network and port. + * + * @param network The IPX network + * @param node The node in the IPX network + * @param port The IPX port (sometimes called socket number) on the node + * @return An IPX socket address with the specified node, network and port. + */ +extern OFSocketAddress OFSocketAddressMakeIPX(uint32_t network, + const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port); + /** * @brief Compares two OFSocketAddress for equality. * * @param address1 The address to compare with the second address * @param address2 The second address @@ -264,10 +263,19 @@ * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address); +/** + * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress. + * + * @param address The address on which to get the UNIX socket path + * @return The UNIX socket path + */ +extern OFString *_Nullable OFSocketAddressUNIXPath( + const OFSocketAddress *_Nonnull address); + /** * @brief Sets the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX network * @param network The IPX network to set on the address @@ -300,19 +308,10 @@ * @param node A byte array to store the IPX node of the address */ extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); -/** - * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress. - * - * @param address The address on which to get the UNIX socket path - * @return The UNIX socket path - */ -extern OFString *_Nullable OFSocketAddressUNIXPath( - const OFSocketAddress *_Nonnull address); - extern bool OFSocketInit(void); #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern void OFSocketDeinit(void); #endif extern int OFSocketErrNo(void); Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -518,34 +518,10 @@ } return ret; } -OFSocketAddress -OFSocketAddressMakeIPX(const unsigned char node[IPX_NODE_LEN], uint32_t network, - uint16_t port) -{ - OFSocketAddress ret; - - memset(&ret, '\0', sizeof(ret)); - ret.family = OFSocketAddressFamilyIPX; - ret.length = sizeof(ret.sockaddr.ipx); - -#ifdef AF_IPX - ret.sockaddr.ipx.sipx_family = AF_IPX; -#else - ret.sockaddr.ipx.sipx_family = AF_UNSPEC; -#endif - memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); - network = OFToBigEndian32(network); - memcpy(&ret.sockaddr.ipx.sipx_network, &network, - sizeof(ret.sockaddr.ipx.sipx_network)); - ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port); - - return ret; -} - OFSocketAddress OFSocketAddressMakeUNIX(OFString *path) { void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding = [OFLocale encoding]; @@ -568,10 +544,34 @@ memcpy(ret.sockaddr.un.sun_path, [path cStringWithEncoding: encoding], length); objc_autoreleasePoolPop(pool); + return ret; +} + +OFSocketAddress +OFSocketAddressMakeIPX(uint32_t network, const unsigned char node[IPX_NODE_LEN], + uint16_t port) +{ + OFSocketAddress ret; + + memset(&ret, '\0', sizeof(ret)); + ret.family = OFSocketAddressFamilyIPX; + ret.length = sizeof(ret.sockaddr.ipx); + +#ifdef AF_IPX + ret.sockaddr.ipx.sipx_family = AF_IPX; +#else + ret.sockaddr.ipx.sipx_family = AF_UNSPEC; +#endif + network = OFToBigEndian32(network); + memcpy(&ret.sockaddr.ipx.sipx_network, &network, + sizeof(ret.sockaddr.ipx.sipx_network)); + memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); + ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port); + return ret; } bool OFSocketAddressEqual(const OFSocketAddress *address1, @@ -621,10 +621,27 @@ addrIn6_2->sin6_addr.s6_addr, sizeof(addrIn6_1->sin6_addr.s6_addr)) != 0) return false; return true; + case OFSocketAddressFamilyUNIX: + pool = objc_autoreleasePoolPush(); + + path1 = OFSocketAddressUNIXPath(address1); + path2 = OFSocketAddressUNIXPath(address2); + + if (path1 == nil || path2 == nil) { + objc_autoreleasePoolPop(pool); + + return false; + } + + ret = [path1 isEqual: path2]; + + objc_autoreleasePoolPop(pool); + + return ret; case OFSocketAddressFamilyIPX: if (address1->length < (socklen_t)sizeof(struct sockaddr_ipx) || address2->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; @@ -639,27 +656,10 @@ if (memcmp(addrIPX1->sipx_node, addrIPX2->sipx_node, IPX_NODE_LEN) != 0) return false; return true; - case OFSocketAddressFamilyUNIX: - pool = objc_autoreleasePoolPush(); - - path1 = OFSocketAddressUNIXPath(address1); - path2 = OFSocketAddressUNIXPath(address2); - - if (path1 == nil || path2 == nil) { - objc_autoreleasePoolPop(pool); - - return false; - } - - ret = [path1 isEqual: path2]; - - objc_autoreleasePoolPop(pool); - - return ret; default: @throw [OFInvalidArgumentException exception]; } } @@ -700,10 +700,19 @@ i < sizeof(address->sockaddr.in6.sin6_addr.s6_addr); i++) OFHashAdd(&hash, address->sockaddr.in6.sin6_addr.s6_addr[i]); break; + case OFSocketAddressFamilyUNIX:; + void *pool = objc_autoreleasePoolPush(); + OFString *path = OFSocketAddressUNIXPath(address); + + hash = path.hash; + + objc_autoreleasePoolPop(pool); + + return hash; case OFSocketAddressFamilyIPX:; unsigned char network[ sizeof(address->sockaddr.ipx.sipx_network)]; if (address->length < (socklen_t)sizeof(struct sockaddr_ipx)) @@ -720,19 +729,10 @@ for (size_t i = 0; i < IPX_NODE_LEN; i++) OFHashAdd(&hash, address->sockaddr.ipx.sipx_node[i]); break; - case OFSocketAddressFamilyUNIX:; - void *pool = objc_autoreleasePoolPush(); - OFString *path = OFSocketAddressUNIXPath(address); - - hash = path.hash; - - objc_autoreleasePoolPop(pool); - - return hash; default: @throw [OFInvalidArgumentException exception]; } OFHashFinalize(&hash); @@ -864,10 +864,32 @@ return OFFromBigEndian16(address->sockaddr.ipx.sipx_port); default: @throw [OFInvalidArgumentException exception]; } } + +OFString * +OFSocketAddressUNIXPath(const OFSocketAddress *_Nonnull address) +{ + socklen_t length; + + if (address->family != OFSocketAddressFamilyUNIX) + @throw [OFInvalidArgumentException exception]; + + length = address->length - offsetof(struct sockaddr_un, sun_path); + + for (socklen_t i = 0; i < length; i++) + if (address->sockaddr.un.sun_path[i] == 0) + length = i; + + if (length <= 0) + return nil; + + return [OFString stringWithCString: address->sockaddr.un.sun_path + encoding: [OFLocale encoding] + length: length]; +} void OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network) { if (address->family != OFSocketAddressFamilyIPX) @@ -908,27 +930,5 @@ if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN); } - -OFString * -OFSocketAddressUNIXPath(const OFSocketAddress *_Nonnull address) -{ - socklen_t length; - - if (address->family != OFSocketAddressFamilyUNIX) - @throw [OFInvalidArgumentException exception]; - - length = address->length - offsetof(struct sockaddr_un, sun_path); - - for (socklen_t i = 0; i < length; i++) - if (address->sockaddr.un.sun_path[i] == 0) - length = i; - - if (length <= 0) - return nil; - - return [OFString stringWithCString: address->sockaddr.un.sun_path - encoding: [OFLocale encoding] - length: length]; -} Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -293,19 +293,19 @@ #ifdef OF_HAVE_IPV6 case AF_INET6: client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif -#ifdef OF_HAVE_IPX - case AF_IPX: - client->_remoteAddress.family = OFSocketAddressFamilyIPX; - break; -#endif #ifdef OF_HAVE_UNIX_SOCKETS case AF_UNIX: client->_remoteAddress.family = OFSocketAddressFamilyUNIX; break; +#endif +#ifdef OF_HAVE_IPX + case AF_IPX: + client->_remoteAddress.family = OFSocketAddressFamilyIPX; + break; #endif default: client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } Index: src/exceptions/OFConnectionFailedException.h ================================================================== --- src/exceptions/OFConnectionFailedException.h +++ src/exceptions/OFConnectionFailedException.h @@ -31,13 +31,13 @@ */ @interface OFConnectionFailedException: OFException { OFString *_Nullable _host; uint16_t _port; - unsigned char _node[IPX_NODE_LEN]; + OFString *_Nullable _path; uint32_t _network; - OFString *_Nullable _path; + unsigned char _node[IPX_NODE_LEN]; id _socket; int _errNo; } /** @@ -49,23 +49,23 @@ * @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. + * @brief The path to which the connection failed. */ -@property (readonly, nonatomic) unsigned char *node; +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; /** * @brief The IPX network of the node to which the connection failed. */ @property (readonly, nonatomic) uint32_t network; /** - * @brief The path to which the connection failed. + * @brief The IPX node to which the connection failed. */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; +@property (readonly, nonatomic) unsigned char *node; /** * @brief The socket which could not connect. */ @property (readonly, nonatomic) id socket; @@ -90,35 +90,36 @@ 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; - -/** - * @brief Creates a new, autoreleased connection failed exception. - * * @param path The path 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)exceptionWithPath: (OFString *)path socket: (id)socket errNo: (int)errNo; +/** + * @brief Creates a new, autoreleased connection failed exception. + * + * @param network The IPX network of the node to which the connection failed + * @param node 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) + exceptionWithNetwork: (uint32_t)network + node: (unsigned char [_Nullable IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo; + + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated connection failed exception. * @@ -134,34 +135,34 @@ 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; - -/** - * @brief Initializes an already allocated connection failed exception. - * * @param path The path 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)initWithPath: (OFString *)path socket: (id)socket errNo: (int)errNo; +/** + * @brief Initializes an already allocated connection failed exception. + * + * @param network The IPX network of the node to which the connection failed + * @param node 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)initWithNetwork: (uint32_t)network + node: (unsigned char [_Nullable IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo; + - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END Index: src/exceptions/OFConnectionFailedException.m ================================================================== --- src/exceptions/OFConnectionFailedException.m +++ src/exceptions/OFConnectionFailedException.m @@ -17,11 +17,11 @@ #import "OFConnectionFailedException.h" #import "OFString.h" @implementation OFConnectionFailedException -@synthesize host = _host, port = _port, network = _network, path = _path; +@synthesize host = _host, port = _port, path = _path, network = _network; @synthesize socket = _socket, errNo = _errNo; + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock @@ -36,31 +36,31 @@ + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } -+ (instancetype)exceptionWithNode: (unsigned char [IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithNode: node - network: network - port: port - socket: sock - errNo: errNo] autorelease]; -} - + (instancetype)exceptionWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { return [[[self alloc] initWithPath: path socket: sock errNo: errNo] autorelease]; } + ++ (instancetype)exceptionWithNetwork: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithNetwork: network + node: node + port: port + socket: sock + errNo: errNo] autorelease]; +} - (instancetype)initWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock errNo: (int)errNo @@ -78,22 +78,18 @@ } return self; } -- (instancetype)initWithNode: (unsigned char [IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port +- (instancetype)initWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { self = [super init]; @try { - memcpy(_node, node, IPX_NODE_LEN); - _network = network; - _port = port; + _path = [path copy]; _socket = [sock retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; @@ -100,18 +96,22 @@ } return self; } -- (instancetype)initWithPath: (OFString *)path - socket: (id)sock - errNo: (int)errNo +- (instancetype)initWithNetwork: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo { self = [super init]; @try { - _path = [path copy]; + _network = network; + memcpy(_node, node, IPX_NODE_LEN); + _port = port; _socket = [sock retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; Index: tests/OFSPXSocketTests.m ================================================================== --- tests/OFSPXSocketTests.m +++ tests/OFSPXSocketTests.m @@ -48,22 +48,22 @@ [[OFRunLoop mainRunLoop] stop]; return false; } -- (void)socket: (OFSPXSocket *)sock - didConnectToNode: (unsigned char [IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - exception: (id)exception +- (void)socket: (OFSPXSocket *)sock + didConnectToNetwork: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && + network == _expectedNetwork && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && - network == _expectedNetwork && port == _expectedPort && - exception == nil); + port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end @@ -73,12 +73,12 @@ { void *pool = objc_autoreleasePoolPush(); OFSPXSocket *sockClient, *sockServer = nil, *sockAccepted; OFSocketAddress address1; const OFSocketAddress *address2; - unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; + unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint16_t port; char buffer[5]; SPXSocketDelegate *delegate; TEST(@"+[socket]", (sockClient = [OFSPXSocket socket]) && @@ -113,18 +113,18 @@ objc_autoreleasePoolPop(pool); return; } - OFSocketAddressIPXNode(&address1, node); network = OFSocketAddressIPXNetwork(&address1); + OFSocketAddressIPXNode(&address1, node); port = OFSocketAddressPort(&address1); TEST(@"-[listen]", R([sockServer listen])) - TEST(@"-[connectToNode:network:port:]", - R([sockClient connectToNode: node network: network port: port])) + TEST(@"-[connectToNetwork:node:port:]", + R([sockClient connectToNetwork: network node: node port: port])) TEST(@"-[accept]", (sockAccepted = [sockServer accept])) TEST(@"-[sendBuffer:length:]", R([sockAccepted sendBuffer: "Hello" length: 5])) @@ -133,13 +133,13 @@ [sockClient receiveIntoBuffer: buffer length: 5] == 5 && memcmp(buffer, "Hello", 5) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && + OFSocketAddressIPXNetwork(address2) == network && R(OFSocketAddressIPXNode(address2, node2)) && - memcmp(node, node2, IPX_NODE_LEN) == 0 && - OFSocketAddressIPXNetwork(address2) == network) + memcmp(node, node2, IPX_NODE_LEN) == 0) delegate = [[[SPXSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXSocket socket]; delegate->_expectedServerSocket = sockServer; @@ -151,33 +151,33 @@ address1 = [sockServer bindToPort: 0]; [sockServer listen]; [sockServer asyncAccept]; + delegate->_expectedNetwork = network = + OFSocketAddressIPXNetwork(&address1); OFSocketAddressIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); - delegate->_expectedNetwork = network = - OFSocketAddressIPXNetwork(&address1); delegate->_expectedPort = port = OFSocketAddressPort(&address1); @try { - [sockClient asyncConnectToNode: node - network: network - port: port]; + [sockClient asyncConnectToNetwork: network + node: node + port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; - TEST(@"-[asyncAccept] & -[asyncConnectToNode:network:port:]", + TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]", delegate->_accepted && delegate->_connected) } @catch (OFObserveFailedException *e) { switch (e.errNo) { case ENOTSOCK: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXSocket] -[asyncAccept] & " - @"-[asyncConnectToNode:network:port:]: select() " + @"-[asyncConnectToNetwork:node:port:]: select() " @"not supported for SPX, skipping test"]; break; default: @throw e; } Index: tests/OFSPXStreamSocketTests.m ================================================================== --- tests/OFSPXStreamSocketTests.m +++ tests/OFSPXStreamSocketTests.m @@ -24,12 +24,12 @@ @interface SPXStreamSocketDelegate: OFObject { @public OFStreamSocket *_expectedServerSocket; OFSPXStreamSocket *_expectedClientSocket; - unsigned char _expectedNode[IPX_NODE_LEN]; uint32_t _expectedNetwork; + unsigned char _expectedNode[IPX_NODE_LEN]; uint16_t _expectedPort; bool _accepted; bool _connected; } @end @@ -48,22 +48,22 @@ [[OFRunLoop mainRunLoop] stop]; return false; } -- (void)socket: (OFSPXStreamSocket *)sock - didConnectToNode: (unsigned char [IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port - exception: (id)exception +- (void)socket: (OFSPXStreamSocket *)sock + didConnectToNetwork: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && + network == _expectedNetwork && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && - network == _expectedNetwork && port == _expectedPort && - exception == nil); + port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end @@ -73,12 +73,12 @@ { void *pool = objc_autoreleasePoolPush(); OFSPXStreamSocket *sockClient, *sockServer = nil, *sockAccepted; OFSocketAddress address1; const OFSocketAddress *address2; - unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; + unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint16_t port; char buffer[5]; SPXStreamSocketDelegate *delegate; TEST(@"+[socket]", (sockClient = [OFSPXStreamSocket socket]) && @@ -113,18 +113,18 @@ objc_autoreleasePoolPop(pool); return; } - OFSocketAddressIPXNode(&address1, node); network = OFSocketAddressIPXNetwork(&address1); + OFSocketAddressIPXNode(&address1, node); port = OFSocketAddressPort(&address1); TEST(@"-[listen]", R([sockServer listen])) - TEST(@"-[connectToNode:network:port:]", - R([sockClient connectToNode: node network: network port: port])) + TEST(@"-[connectToNetwork:node:port:]", + R([sockClient connectToNetwork: network node: node port: port])) TEST(@"-[accept]", (sockAccepted = [sockServer accept])) /* Test reassembly (this would not work with OFSPXSocket) */ TEST(@"-[writeBuffer:length:]", @@ -136,13 +136,13 @@ [sockClient readIntoBuffer: buffer length: 3] == 3 && memcmp(buffer, "llo", 3) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && + OFSocketAddressIPXNetwork(address2) == network && R(OFSocketAddressIPXNode(address2, node2)) && - memcmp(node, node2, IPX_NODE_LEN) == 0 && - OFSocketAddressIPXNetwork(address2) == network) + memcmp(node, node2, IPX_NODE_LEN) == 0) delegate = [[[SPXStreamSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXStreamSocket socket]; delegate->_expectedServerSocket = sockServer; @@ -154,33 +154,33 @@ address1 = [sockServer bindToPort: 0]; [sockServer listen]; [sockServer asyncAccept]; + delegate->_expectedNetwork = network = + OFSocketAddressIPXNetwork(&address1); OFSocketAddressIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); - delegate->_expectedNetwork = network = - OFSocketAddressIPXNetwork(&address1); delegate->_expectedPort = port = OFSocketAddressPort(&address1); @try { - [sockClient asyncConnectToNode: node - network: network - port: port]; + [sockClient asyncConnectToNetwork: network + node: node + port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; - TEST(@"-[asyncAccept] & -[asyncConnectToNode:network:port:]", + TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]", delegate->_accepted && delegate->_connected) } @catch (OFObserveFailedException *e) { switch (e.errNo) { case ENOTSOCK: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[asyncAccept] & " - @"-[asyncConnectToNode:network:port:]: select() " + @"-[asyncConnectToNetwork:node:port:]: select() " @"not supported for SPX, skipping test"]; break; default: @throw e; }