Comment: | Add OFUNIXStreamSocket |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | unix-sockets |
Files: | files | file ages | folders |
SHA3-256: |
aaf477fc88e5566065e31aa7ad795a9b |
User & Date: | js on 2021-10-24 21:15:35 |
Other Links: | branch diff | manifest | tags |
2021-10-24
| ||
22:09 | Fix OFSocketAddressUNIXPath check-in: 24ffb76ae2 user: js tags: unix-sockets | |
21:15 | Add OFUNIXStreamSocket check-in: aaf477fc88 user: js tags: unix-sockets | |
18:11 | Enable UNIX sockets on Windows check-in: d5373ff70f user: js tags: unix-sockets | |
Modified src/Makefile from [651753ff6c] to [bcf342d5bf].
︙ | ︙ | |||
139 140 141 142 143 144 145 | OFTCPSocket.m \ OFUDPSocket.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_IPX = OFIPXSocket.m \ OFSPXSocket.m \ OFSPXStreamSocket.m | | > | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | OFTCPSocket.m \ OFUDPSocket.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_IPX = OFIPXSocket.m \ OFSPXSocket.m \ OFSPXStreamSocket.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocket.m \ OFUNIXStreamSocket.m SRCS_THREADS = OFCondition.m \ OFMutex.m \ OFPlainCondition.m \ OFPlainMutex.m \ OFPlainThread.m \ OFRecursiveMutex.m \ OFTLSKey.m \ |
︙ | ︙ |
Modified src/OFStreamSocket.m from [5b9cb9181f] to [79180ccd72].
︙ | ︙ | |||
295 296 297 298 299 300 301 302 303 304 305 306 307 308 | client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: client->_remoteAddress.family = OFSocketAddressFamilyIPX; break; #endif default: client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; | > > > > > | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | 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 default: client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; |
︙ | ︙ |
Modified src/OFTCPSocket.h from [9ae8ba1677] to [7942720881].
︙ | ︙ | |||
142 143 144 145 146 147 148 | * @brief Returns the port to use as a SOCKS5 proxy when creating a new socket * * @return The port to use as a SOCKS5 proxy when creating a new socket */ + (uint16_t)SOCKS5Port; /** | | | | | | | | 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 | * @brief Returns the port to use as a SOCKS5 proxy when creating a new socket * * @return The port to use as a SOCKS5 proxy when creating a new socket */ + (uint16_t)SOCKS5Port; /** * @brief Connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to */ - (void)connectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port block: (OFTCPSocketAsyncConnectBlock)block; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host 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)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFTCPSocketAsyncConnectBlock)block; #endif /** * @brief Binds the socket to the specified host and port. * * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to */ |
︙ | ︙ |
Modified src/OFUNIXDatagramSocket.m from [44180adae5] to [b4a4c54b03].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFUNIXDatagramSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" @implementation OFUNIXDatagramSocket @dynamic delegate; | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFUNIXDatagramSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" @implementation OFUNIXDatagramSocket @dynamic delegate; |
︙ | ︙ |
Added src/OFUNIXStreamSocket.h version [75f2f4081c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | /* * Copyright (c) 2008-2021 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 "OFStreamSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /** * @protocol OFUNIXStreamSocketDelegate OFUNIXStreamSocket.h \ * ObjFW/OFUNIXStreamSocket.h * * A delegate for OFUNIXStreamSocket. */ @protocol OFUNIXStreamSocketDelegate <OFStreamSocketDelegate> @end /** * @class OFUNIXStreamSocket OFUNIXStreamSocket.h ObjFW/OFUNIXStreamSocket.h * * @brief A class which provides methods to create and use UNIX stream 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 OFUNIXStreamSocket: OFStreamSocket { OF_RESERVE_IVARS(OFUNIXStreamSocket, 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 <OFUNIXStreamSocketDelegate> delegate; /** * @brief Connects the OFUNIXStreamSocket to the specified destination. * * @param path The path to connect to */ - (void)connectToPath: (OFString *)path; /** * @brief Binds the socket to the specified host and port. * * @param path The path to bind to */ - (void)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END |
Added src/OFUNIXStreamSocket.m version [14bddbd499].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008-2021 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> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFUNIXStreamSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" #import "OFConnectionFailedException.h" @implementation OFUNIXStreamSocket @dynamic delegate; - (void)connectToPath: (OFString *)path { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFConnectionFailedException exceptionWithPath: path socket: self errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (connect(_socket, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFConnectionFailedException exceptionWithPath: path socket: self errNo: errNo]; } } - (void)bindToPath: (OFString *)path { OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithPath: path socket: self errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPath: path socket: self errNo: errNo]; } } @end |
Modified src/ObjFW.h from [df01551874] to [d5ffd2bc28].
︙ | ︙ | |||
82 83 84 85 86 87 88 89 90 91 92 93 94 95 | # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # import "OFSPXSocket.h" # import "OFSPXStreamSocket.h" # endif # ifdef OF_HAVE_UNIX_SOCKETS # import "OFUNIXDatagramSocket.h" # endif #endif #ifdef OF_HAVE_SOCKETS # ifdef OF_HAVE_THREADS # import "OFHTTPClient.h" # endif # import "OFHTTPCookie.h" | > | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # import "OFSPXSocket.h" # import "OFSPXStreamSocket.h" # endif # ifdef OF_HAVE_UNIX_SOCKETS # import "OFUNIXDatagramSocket.h" # import "OFUNIXStreamSocket.h" # endif #endif #ifdef OF_HAVE_SOCKETS # ifdef OF_HAVE_THREADS # import "OFHTTPClient.h" # endif # import "OFHTTPCookie.h" |
︙ | ︙ |
Modified src/exceptions/OFConnectionFailedException.h from [0eaf506d9d] to [c3153f2e58].
︙ | ︙ | |||
27 28 29 30 31 32 33 | * @class OFConnectionFailedException \ * OFConnectionFailedException.h ObjFW/OFConnectionFailedException.h * * @brief An exception indicating that a connection could not be established. */ @interface OFConnectionFailedException: OFException { | < > > < < < < < > > > > > > > > > > | 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 | * @class OFConnectionFailedException \ * OFConnectionFailedException.h ObjFW/OFConnectionFailedException.h * * @brief An exception indicating that a connection could not be established. */ @interface OFConnectionFailedException: OFException { OFString *_host; uint16_t _port; unsigned char _node[IPX_NODE_LEN]; uint32_t _network; OFString *_Nullable _path; id _socket; int _errNo; } /** * @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 path to which the connection failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; /** * @brief The socket which could not connect. */ @property (readonly, nonatomic) id socket; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; + (instancetype)exception OF_UNAVAILABLE; |
︙ | ︙ | |||
97 98 99 100 101 102 103 104 105 106 107 108 109 110 | */ + (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 | > > > > > > > > > > > > | 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 | */ + (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; - (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 |
︙ | ︙ | |||
128 129 130 131 132 133 134 135 136 137 | * @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 | > > > > > > > > > > > > | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | * @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; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFConnectionFailedException.m from [847ad9798b] to [06fae122e8].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFConnectionFailedException.h" #import "OFString.h" @implementation OFConnectionFailedException | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include "config.h" #import "OFConnectionFailedException.h" #import "OFString.h" @implementation OFConnectionFailedException @synthesize host = _host, port = _port, network = _network, path = _path; @synthesize socket = _socket, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithHost: (OFString *)host |
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | { return [[[self alloc] initWithNode: node network: network port: port socket: sock errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithHost: (OFString *)host | > > > > > > > > > | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | { 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)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithHost: (OFString *)host |
︙ | ︙ | |||
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [_socket release]; [super dealloc]; } - (unsigned char *)node { return _node; } - (OFString *)description { | > > > > > > > > > > > > > > > > > > > > > > > > | | 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 | } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { self = [super init]; @try { _path = [path copy]; _socket = [sock retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [_path release]; [_socket release]; [super dealloc]; } - (unsigned char *)node { return _node; } - (OFString *)description { if (_path != nil) return [OFString stringWithFormat: @"A connection to %@ could not be established in socket of " @"type %@: %@", _path, [_socket class], OFStrError(_errNo)]; else if (_host != nil) return [OFString stringWithFormat: @"A connection to %@ on port %" @PRIu16 @" could not be " @"established in socket of type %@: %@", _host, _port, [_socket class], OFStrError(_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 |
︙ | ︙ |
Modified tests/Makefile from [97e65714fd] to [e55f50a669].
︙ | ︙ | |||
66 67 68 69 70 71 72 | OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m | | > | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ OFUNIXStreamSocketTests.m SRCS_THREADS = OFThreadTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk |
︙ | ︙ |
Modified tests/OFSPXSocketTests.m from [1c45b38ca1] to [ebf8aedc8d].
︙ | ︙ | |||
68 69 70 71 72 73 74 | } @end @implementation TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests { void *pool = objc_autoreleasePoolPush(); | | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | } @end @implementation TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests { void *pool = objc_autoreleasePoolPush(); OFSPXSocket *sockClient, *sockServer, *sockAccepted; OFSocketAddress address1; const OFSocketAddress *address2; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; uint16_t port; char buffer[5]; SPXSocketDelegate *delegate; |
︙ | ︙ |
Modified tests/OFSPXStreamSocketTests.m from [0326ef9bb8] to [72b39a0862].
︙ | ︙ | |||
68 69 70 71 72 73 74 | } @end @implementation TestsAppDelegate (OFSPXStreamSocketTests) - (void)SPXStreamSocketTests { void *pool = objc_autoreleasePoolPush(); | | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | } @end @implementation TestsAppDelegate (OFSPXStreamSocketTests) - (void)SPXStreamSocketTests { void *pool = objc_autoreleasePoolPush(); OFSPXStreamSocket *sockClient, *sockServer, *sockAccepted; OFSocketAddress address1; const OFSocketAddress *address2; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; uint16_t port; char buffer[5]; SPXStreamSocketDelegate *delegate; |
︙ | ︙ |
Added tests/OFUNIXStreamSocketTests.m version [d6bbb6e4b4].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008-2021 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 *const module = @"OFUNIXStreamSocket"; @implementation TestsAppDelegate (OFUNIXStreamSocketTests) - (void)UNIXStreamSocketTests { void *pool = objc_autoreleasePoolPush(); OFString *path; OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted; char buffer[5]; #ifdef OF_HAVE_FILES path = [[OFSystemInfo temporaryDirectoryPath] stringByAppendingPathComponent: [[OFUUID UUID] UUIDString]]; #else /* * We can have sockets, including UNIX sockets, while file support is * disabled. */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif TEST(@"+[socket]", (sockClient = [OFUNIXStreamSocket socket]) && (sockServer = [OFUNIXStreamSocket socket])) @try { TEST(@"-[bindToPath:]", R([sockServer bindToPath: path])) } @catch (OFBindFailedException *e) { if (e.errNo == EAFNOSUPPORT) { [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFUNIXStreamSocket] -[bindToPath:]: " @"UNIX stream sockets unsupported, skipping tests"]; objc_autoreleasePoolPop(pool); return; } else @throw e; } @try { TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToPath:]", R([sockClient connectToPath: path])) TEST(@"-[accept]", (sockAccepted = [sockServer accept])) TEST(@"-[writeBuffer:length:]", R([sockAccepted writeBuffer: "Hello" length: 5])) TEST(@"-[receiveIntoBuffer:length:]", [sockClient readIntoBuffer: buffer length: 5] == 5 && memcmp(buffer, "Hello", 5) == 0) TEST(@"-[remoteAddress]", OFSocketAddressUNIXPath(sockAccepted.remoteAddress) == nil) } @finally { #ifdef OF_HAVE_FILES [[OFFileManager defaultManager] removeItemAtPath: path]; #endif } objc_autoreleasePoolPop(pool); } @end |
Modified tests/TestsAppDelegate.h from [8a125e86de] to [2604a9aa38].
︙ | ︙ | |||
242 243 244 245 246 247 248 249 250 251 252 253 254 255 | @interface TestsAppDelegate (OFUDPSocketTests) - (void)UDPSocketTests; @end @interface TestsAppDelegate (OFUNIXDatagramSocketTests) - (void)UNIXDatagramSocketTests; @end @interface TestsAppDelegate (OFURLTests) - (void)URLTests; @end @interface TestsAppDelegate (OFValueTests) - (void)valueTests; | > > > > | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | @interface TestsAppDelegate (OFUDPSocketTests) - (void)UDPSocketTests; @end @interface TestsAppDelegate (OFUNIXDatagramSocketTests) - (void)UNIXDatagramSocketTests; @end @interface TestsAppDelegate (OFUNIXStreamSocketTests) - (void)UNIXStreamSocketTests; @end @interface TestsAppDelegate (OFURLTests) - (void)URLTests; @end @interface TestsAppDelegate (OFValueTests) - (void)valueTests; |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [9499e9e013] to [bd24271038].
︙ | ︙ | |||
353 354 355 356 357 358 359 360 361 362 363 364 365 366 | # ifdef OF_HAVE_IPX [self IPXSocketTests]; [self SPXSocketTests]; [self SPXStreamSocketTests]; # endif # ifdef OF_HAVE_UNIX_SOCKETS [self UNIXDatagramSocketTests]; # endif [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS [self threadTests]; #endif [self URLTests]; | > | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | # ifdef OF_HAVE_IPX [self IPXSocketTests]; [self SPXSocketTests]; [self SPXStreamSocketTests]; # endif # ifdef OF_HAVE_UNIX_SOCKETS [self UNIXDatagramSocketTests]; [self UNIXStreamSocketTests]; # endif [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS [self threadTests]; #endif [self URLTests]; |
︙ | ︙ |