Overview
Comment: | Initial support for async connect without threads |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
1e79c0a969f43e7eee64587d865aa6b7 |
User & Date: | js on 2018-08-26 12:46:43 |
Other Links: | manifest | tags |
Context
2018-08-26
| ||
17:40 | configure: Clean up flags for objfw-config check-in: 3155de66ff user: js tags: trunk | |
12:46 | Initial support for async connect without threads check-in: 1e79c0a969 user: js tags: trunk | |
2018-08-25
| ||
19:09 | tests: Use the same path tests on Wii as on 3DS check-in: e649da7412 user: js tags: trunk | |
Changes
Modified src/OFRunLoop+Private.h from [20f75e8e1d] to [d19edf241a].
︙ | |||
49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | + + + + | + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *) stream buffer: (const void *)buffer length: (size_t)length target: (id)target selector: (SEL)selector context: (nullable id)context; + (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)socket target: (id)target selector: (SEL)selector context: (nullable id)context; + (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)socket target: (id)target selector: (SEL)selector context: (nullable id)context; + (void)of_addAsyncReceiveForUDPSocket: (OFUDPSocket *)socket buffer: (void *)buffer length: (size_t)length |
︙ |
Modified src/OFRunLoop.m from [900992f7d6] to [f211a21b64].
︙ | |||
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 | 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 | + + + + + | #include <errno.h> #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFKernelEventObserver.h" # import "OFTCPSocket.h" # import "OFTCPSocket+Private.h" #endif #import "OFThread.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" # import "OFCondition.h" #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" #ifdef OF_HAVE_SOCKETS # import "OFConnectionFailedException.h" #endif static OFRunLoop *mainRunLoop = nil; #ifdef OF_HAVE_SOCKETS @interface OFRunLoop_QueueItem: OFObject { @public |
︙ | |||
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | + + + | # ifdef OF_HAVE_BLOCKS of_stream_async_write_block_t _block; # endif const void *_buffer; size_t _length, _writtenLength; } @end @interface OFRunLoop_ConnectQueueItem: OFRunLoop_QueueItem @end @interface OFRunLoop_AcceptQueueItem: OFRunLoop_QueueItem { @public # ifdef OF_HAVE_BLOCKS of_tcp_socket_async_accept_block_t _block; # endif |
︙ | |||
330 331 332 333 334 335 336 337 338 339 340 341 342 343 | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | + + + + + + + + + + + + + + + + + + + + + + | { [_block release]; [super dealloc]; } # endif @end @implementation OFRunLoop_ConnectQueueItem - (bool)handleObject: (id)object { id exception = nil; int errNo; void (*func)(id, SEL, OFTCPSocket *, id, id); if ((errNo = [object of_socketError]) != 0) exception = [OFConnectionFailedException exceptionWithHost: nil port: 0 socket: object errNo: errNo]; func = (void (*)(id, SEL, OFTCPSocket *, id, id)) [_target methodForSelector: _selector]; func(_target, _selector, object, _context, exception); return false; } @end @implementation OFRunLoop_AcceptQueueItem - (bool)handleObject: (id)object { OFTCPSocket *newSocket; id exception = nil; |
︙ | |||
591 592 593 594 595 596 597 598 599 600 601 602 603 604 | 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | + + + + + + + + + + + + | queueItem->_target = [target retain]; queueItem->_selector = selector; queueItem->_context = [context retain]; queueItem->_buffer = buffer; queueItem->_length = length; }) } + (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)stream target: (id)target selector: (SEL)selector context: (id)context { ADD_WRITE(OFRunLoop_ConnectQueueItem, stream, { queueItem->_target = [target retain]; queueItem->_selector = selector; queueItem->_context = [context retain]; }) } + (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)stream target: (id)target selector: (SEL)selector context: (id)context { ADD_READ(OFRunLoop_AcceptQueueItem, stream, { |
︙ |
Modified src/OFStream.h from [99b8fab82d] to [cfbdba3736].
︙ | |||
135 136 137 138 139 140 141 | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | - + | /*! * @brief Whether the stream is in blocking mode. * * By default, a stream is in blocking mode. * On Win32, setting this currently only works for sockets! */ |
︙ |
Added src/OFTCPSocket+Private.h version [8b5d611a82].
|
Modified src/OFTCPSocket.m from [b15819e802] to [aaa2b87b7c].
︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | + | #include <string.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFTCPSocket.h" #import "OFTCPSocket+Private.h" #import "OFTCPSocket+SOCKS5.h" #import "OFString.h" #import "OFThread.h" #import "OFTimer.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" |
︙ | |||
250 251 252 253 254 255 256 257 258 259 260 261 262 263 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | - (void)dealloc { [_SOCKS5Host release]; [super dealloc]; } - (bool)of_createSocketForAddress: (const of_socket_address_t *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if ((_socket = socket(address->sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == INVALID_SOCKET) { *errNo = of_socket_errno(); return false; } #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 return true; } - (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; } - (void)of_closeSocket { closesocket(_socket); _socket = INVALID_SOCKET; } - (int)of_socketError { int errNo; socklen_t len = sizeof(errNo); if (getsockopt(_socket, SOL_SOCKET, SO_ERROR, &errNo, &len) != 0) return of_socket_errno(); return errNo; } - (void)connectToHost: (OFString *)host port: (uint16_t)port { OFString *destinationHost = host; uint16_t destinationPort = port; of_resolver_result_t **results, **iter; |
︙ | |||
272 273 274 275 276 277 278 | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | - - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - + - - - - + - - - + | port = _SOCKS5Port; } results = of_resolve_host(host, port, SOCK_STREAM); for (iter = results; *iter != NULL; iter++) { of_resolver_result_t *result = *iter; |
︙ |
Modified src/exceptions/OFConnectionFailedException.h from [465ef9b3d2] to [256212dee6].
︙ | |||
41 42 43 44 45 46 47 | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | - + | * @brief The socket which could not connect. */ @property (readonly, nonatomic) id socket; /*! * @brief The host to which the connection failed. */ |
︙ | |||
64 65 66 67 68 69 70 | 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 | - + - + | * * @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 A new, autoreleased connection failed exception */ |
Modified src/exceptions/OFConnectionFailedException.m from [67236a818b] to [3dbed8589a].
︙ | |||
70 71 72 73 74 75 76 | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | + - - - - + + + + + + + + + | [_socket release]; [super dealloc]; } - (OFString *)description { if (_host != nil) |
Modified src/exceptions/OFWriteFailedException.m from [21c2818dc0] to [f767e7aca4].
︙ | |||
63 64 65 66 67 68 69 | 63 64 65 66 67 68 69 70 71 72 73 74 75 | - + | return self; } - (OFString *)description { return [OFString stringWithFormat: |