Overview
Comment: | Change type for async exceptions to id |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f8498bb114d0a25a758235e5b511ceb7 |
User & Date: | js on 2017-09-24 11:24:34 |
Other Links: | manifest | tags |
Context
2017-09-24
| ||
12:24 | OFStream: Add support for async writes check-in: 481225349f user: js tags: trunk | |
11:24 | Change type for async exceptions to id check-in: f8498bb114 user: js tags: trunk | |
02:11 | OFObject: Add -[performSelector*] with 3 objects check-in: 9f1accca4e user: js tags: trunk | |
Changes
Modified src/OFHTTPClient.h from [c2310631fb] to [cce5af40ca].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); | < | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPResponse; @class OFTCPSocket; @class OFURL; /*! |
︙ | ︙ |
Modified src/OFHTTPClient.m from [e41f9ea835] to [038d53e9bb].
︙ | ︙ | |||
562 563 564 565 566 567 568 | selector: @selector(socket:didReadLine:context: exception:) context: nil]; } - (void)socketDidConnect: (OFTCPSocket *)socket context: (id)context | | | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | selector: @selector(socket:didReadLine:context: exception:) context: nil]; } - (void)socketDidConnect: (OFTCPSocket *)socket context: (id)context exception: (id)exception { if ([_client->_delegate respondsToSelector: @selector(client:didCreateSocket:forRequest:)]) [_client->_delegate client: _client didCreateSocket: socket forRequest: _request]; |
︙ | ︙ |
Modified src/OFHTTPServer.h from [d3a518f515] to [6c55e5b8df].
︙ | ︙ | |||
22 23 24 25 26 27 28 | OF_ASSUME_NONNULL_BEGIN @class OFHTTPServer; @class OFHTTPRequest; @class OFHTTPResponse; @class OFTCPSocket; | < | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | OF_ASSUME_NONNULL_BEGIN @class OFHTTPServer; @class OFHTTPRequest; @class OFHTTPResponse; @class OFTCPSocket; /*! * @protocol OFHTTPServerDelegate OFHTTPServer.h ObjFW/OFHTTPServer.h * * @brief A delegate for OFHTTPServer. */ @protocol OFHTTPServerDelegate <OFObject> |
︙ | ︙ | |||
55 56 57 58 59 60 61 | * @param exception The exception which occurred on the HTTP server's listening * socket * @return Whether to continue listening. If you return false, existing * connections will still be handled and you can start accepting new * connections again by calling @ref OFHTTPServer::start again. */ - (bool)server: (OFHTTPServer *)server | | | | 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 | * @param exception The exception which occurred on the HTTP server's listening * socket * @return Whether to continue listening. If you return false, existing * connections will still be handled and you can start accepting new * connections again by calling @ref OFHTTPServer::start again. */ - (bool)server: (OFHTTPServer *)server didReceiveExceptionOnListeningSocket: (id)exception; /*! * @brief This method is called when a client socket encountered an exception. * * This can happen when the OFHTTPServer tries to properly close the * connection. If no headers have been sent yet, it will send headers, and if * chunked transfer encoding was used, it will send a chunk of size 0. However, * if the other end already closed the connection before that, this will raise * an exception. * * @param server The HTTP server which encountered an exception * @param response The response for which the exception occurred * @param request The request for the response for which the exception occurred * @param exception The exception which occurred */ - (void)server: (OFHTTPServer *)server didReceiveExceptionForResponse: (OFHTTPResponse *)response request: (OFHTTPRequest *)request exception: (id)exception; @end /*! * @class OFHTTPServer OFHTTPServer.h ObjFW/OFHTTPServer.h * * @brief A class for creating a simple HTTP server inside of applications. */ |
︙ | ︙ |
Modified src/OFHTTPServer.m from [f88ae06cce] to [e701818685].
︙ | ︙ | |||
46 47 48 49 50 51 52 | * FIXME: Errors are not reported to the user. */ @interface OFHTTPServer () - (bool)of_socket: (OFTCPSocket *)socket didAcceptSocket: (OFTCPSocket *)clientSocket context: (id)context | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | * FIXME: Errors are not reported to the user. */ @interface OFHTTPServer () - (bool)of_socket: (OFTCPSocket *)socket didAcceptSocket: (OFTCPSocket *)clientSocket context: (id)context exception: (id)exception; @end static const char * statusCodeToString(short code) { switch (code) { case 100: |
︙ | ︙ | |||
340 341 342 343 344 345 346 | } - initWithSocket: (OFTCPSocket *)socket server: (OFHTTPServer *)server; - (bool)socket: (OFTCPSocket *)socket didReadLine: (OFString *)line context: (id)context | | | | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | } - initWithSocket: (OFTCPSocket *)socket server: (OFHTTPServer *)server; - (bool)socket: (OFTCPSocket *)socket didReadLine: (OFString *)line context: (id)context exception: (id)exception; - (bool)parseProlog: (OFString *)line; - (bool)parseHeaders: (OFString *)line; - (bool)socket: (OFTCPSocket *)socket didReadIntoBuffer: (char *)buffer length: (size_t)length context: (id)context exception: (id)exception; - (bool)sendErrorAndClose: (short)statusCode; - (void)createResponse; @end @implementation OFHTTPServer_Connection - initWithSocket: (OFTCPSocket *)socket server: (OFHTTPServer *)server |
︙ | ︙ | |||
395 396 397 398 399 400 401 | [super dealloc]; } - (bool)socket: (OFTCPSocket *)socket didReadLine: (OFString *)line context: (id)context | | | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | [super dealloc]; } - (bool)socket: (OFTCPSocket *)socket didReadLine: (OFString *)line context: (id)context exception: (id)exception { if (line == nil || exception != nil) return false; @try { switch (_state) { case AWAITING_PROLOG: |
︙ | ︙ | |||
575 576 577 578 579 580 581 | return true; } - (bool)socket: (OFTCPSocket *)socket didReadIntoBuffer: (char *)buffer length: (size_t)length context: (id)context | | | 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | return true; } - (bool)socket: (OFTCPSocket *)socket didReadIntoBuffer: (char *)buffer length: (size_t)length context: (id)context exception: (id)exception { if ([socket isAtEndOfStream] || exception != nil) return false; [_body addItems: buffer count: length]; |
︙ | ︙ | |||
740 741 742 743 744 745 746 | [_listeningSocket release]; _listeningSocket = nil; } - (bool)of_socket: (OFTCPSocket *)socket didAcceptSocket: (OFTCPSocket *)clientSocket context: (id)context | | | 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 | [_listeningSocket release]; _listeningSocket = nil; } - (bool)of_socket: (OFTCPSocket *)socket didAcceptSocket: (OFTCPSocket *)clientSocket context: (id)context exception: (id)exception { OFHTTPServer_Connection *connection; if (exception != nil) { if ([_delegate respondsToSelector: @selector(server:didReceiveExceptionOnListeningSocket:)]) return [_delegate server: self |
︙ | ︙ |
Modified src/OFRunLoop.m from [35d1810bb5] to [1a169f665d].
︙ | ︙ | |||
118 119 120 121 122 123 124 | } @end @implementation OFRunLoop_ReadQueueItem - (bool)handleForObject: (id)object { size_t length; | | | | | < | 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 | } @end @implementation OFRunLoop_ReadQueueItem - (bool)handleForObject: (id)object { size_t length; id exception = nil; @try { length = [object readIntoBuffer: _buffer length: _length]; } @catch (id e) { length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(object, _buffer, length, exception); else { # endif bool (*func)(id, SEL, OFStream *, void *, size_t, id, id) = (bool (*)(id, SEL, OFStream *, void *, size_t, id, id)) [_target methodForSelector: _selector]; return func(_target, _selector, object, _buffer, length, _context, exception); # ifdef OF_HAVE_BLOCKS } # endif |
︙ | ︙ | |||
159 160 161 162 163 164 165 | # endif @end @implementation OFRunLoop_ExactReadQueueItem - (bool)handleForObject: (id)object { size_t length; | | | | | < | 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 | # endif @end @implementation OFRunLoop_ExactReadQueueItem - (bool)handleForObject: (id)object { size_t length; id exception = nil; @try { length = [object readIntoBuffer: (char *)_buffer + _readLength length: _exactLength - _readLength]; } @catch (id e) { length = 0; exception = e; } _readLength += length; if (_readLength != _exactLength && ![object isAtEndOfStream] && exception == nil) return true; # ifdef OF_HAVE_BLOCKS if (_block != NULL) { if (!_block(object, _buffer, _readLength, exception)) return false; _readLength = 0; return true; } else { # endif bool (*func)(id, SEL, OFStream *, void *, size_t, id, id) = (bool (*)(id, SEL, OFStream *, void *, size_t, id, id)) [_target methodForSelector: _selector]; if (!func(_target, _selector, object, _buffer, _readLength, _context, exception)) return false; _readLength = 0; |
︙ | ︙ | |||
214 215 216 217 218 219 220 | # endif @end @implementation OFRunLoop_ReadLineQueueItem - (bool)handleForObject: (id)object { OFString *line; | | | | | | | 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 | # endif @end @implementation OFRunLoop_ReadLineQueueItem - (bool)handleForObject: (id)object { OFString *line; id exception = nil; @try { line = [object tryReadLineWithEncoding: _encoding]; } @catch (id e) { line = nil; exception = e; } if (line == nil && ![object isAtEndOfStream] && exception == nil) return true; # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(object, line, exception); else { # endif bool (*func)(id, SEL, OFStream *, OFString *, id, id) = (bool (*)(id, SEL, OFStream *, OFString *, id, id)) [_target methodForSelector: _selector]; return func(_target, _selector, object, line, _context, exception); # ifdef OF_HAVE_BLOCKS } # endif } |
︙ | ︙ | |||
256 257 258 259 260 261 262 | # endif @end @implementation OFRunLoop_AcceptQueueItem - (bool)handleForObject: (id)object { OFTCPSocket *newSocket; | | | | | < | 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 | # endif @end @implementation OFRunLoop_AcceptQueueItem - (bool)handleForObject: (id)object { OFTCPSocket *newSocket; id exception = nil; @try { newSocket = [object accept]; } @catch (id e) { newSocket = nil; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(object, newSocket, exception); else { # endif bool (*func)(id, SEL, OFTCPSocket *, OFTCPSocket *, id, id) = (bool (*)(id, SEL, OFTCPSocket *, OFTCPSocket *, id, id)) [_target methodForSelector: _selector]; return func(_target, _selector, object, newSocket, _context, exception); # ifdef OF_HAVE_BLOCKS } # endif |
︙ | ︙ | |||
297 298 299 300 301 302 303 | @end @implementation OFRunLoop_UDPReceiveQueueItem - (bool)handleForObject: (id)object { size_t length; of_udp_socket_address_t address; | | | | | | 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 | @end @implementation OFRunLoop_UDPReceiveQueueItem - (bool)handleForObject: (id)object { size_t length; of_udp_socket_address_t address; id exception = nil; @try { length = [object receiveIntoBuffer: _buffer length: _length sender: &address]; } @catch (id e) { length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(object, _buffer, length, address, exception); else { # endif bool (*func)(id, SEL, OFUDPSocket *, void *, size_t, of_udp_socket_address_t address, id, id) = (bool (*)(id, SEL, OFUDPSocket *, void *, size_t, of_udp_socket_address_t, id, id)) [_target methodForSelector: _selector]; return func(_target, _selector, object, _buffer, length, address, _context, exception); # ifdef OF_HAVE_BLOCKS } # endif |
︙ | ︙ |
Modified src/OFStream.h from [39526e7198] to [1ebe98026c].
︙ | ︙ | |||
31 32 33 34 35 36 37 | OF_ASSUME_NONNULL_BEGIN /*! @file */ @class OFStream; @class OFData; | < | | | 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 | OF_ASSUME_NONNULL_BEGIN /*! @file */ @class OFStream; @class OFData; #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_BLOCKS) /*! * @brief A block which is called when data was read from the stream. * * @param stream The stream on which data was read * @param buffer A buffer with the data that has been read * @param length The length of the data that has been read * @param exception An exception which occurred while reading or `nil` on * success * @return A bool whether the same block should be used for the next read */ typedef bool (^of_stream_async_read_block_t)(OFStream *stream, void *buffer, size_t length, id _Nullable exception); /*! * @brief A block which is called when a line was read from the stream. * * @param stream The stream on which a line was read * @param line The line which has been read or `nil` when the end of stream * occurred * @param exception An exception which occurred while reading or `nil` on * success * @return A bool whether the same block should be used for the next read */ typedef bool (^of_stream_async_read_line_block_t)(OFStream *stream, OFString *_Nullable line, id _Nullable exception); #endif /*! * @class OFStream OFStream.h ObjFW/OFStream.h * * @brief A base class for different types of streams. * |
︙ | ︙ | |||
165 166 167 168 169 170 171 | * data has been received. If the method returns true, it will be * called again with the same buffer and maximum length when more * data has been received. If you want the next method in the * queue to handle the data received next, you need to return * false from the method. * @param selector The selector to call on the target. The signature must be * `bool (OFStream *stream, void *buffer, size_t length, | | | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | * data has been received. If the method returns true, it will be * called again with the same buffer and maximum length when more * data has been received. If you want the next method in the * queue to handle the data received next, you need to return * false from the method. * @param selector The selector to call on the target. The signature must be * `bool (OFStream *stream, void *buffer, size_t length, * id context, id exception)`. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length target: (id)target selector: (SEL)selector context: (nullable id)context; |
︙ | ︙ | |||
196 197 198 199 200 201 202 | * data has been received. If the method returns true, it will be * called again with the same buffer and exact length when more * data has been received. If you want the next method in the * queue to handle the data received next, you need to return * false from the method. * @param selector The selector to call on the target. The signature must be * `bool (OFStream *stream, void *buffer, size_t size, | | | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | * data has been received. If the method returns true, it will be * called again with the same buffer and exact length when more * data has been received. If you want the next method in the * queue to handle the data received next, you need to return * false from the method. * @param selector The selector to call on the target. The signature must be * `bool (OFStream *stream, void *buffer, size_t size, * id context, id exception)`. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length target: (id)target selector: (SEL)selector context: (nullable id)context; |
︙ | ︙ | |||
620 621 622 623 624 625 626 | * @param target The target on which to call the selector when the data has * been received. If the method returns true, it will be called * again when the next line has been received. If you want the * next method in the queue to handle the next line, you need to * return false from the method * @param selector The selector to call on the target. The signature must be * `bool (OFStream *stream, OFString *line, id context, | | | | | 619 620 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 647 648 649 650 651 652 653 654 | * @param target The target on which to call the selector when the data has * been received. If the method returns true, it will be called * again when the next line has been received. If you want the * next method in the queue to handle the next line, you need to * return false from the method * @param selector The selector to call on the target. The signature must be * `bool (OFStream *stream, OFString *line, id context, * id exception)`. */ - (void)asyncReadLineWithTarget: (id)target selector: (SEL)selector context: (nullable id)context; /*! * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must implement @ref fileDescriptorForReading and return a * valid file descriptor in order for this to work! * * @param encoding The encoding used by the stream * @param target The target on which to call the selector when the data has * been received. If the method returns true, it will be called * again when the next line has been received. If you want the * next method in the queue to handle the next line, you need to * return false from the method * @param selector The selector to call on the target. The signature must be * `bool (OFStream *stream, OFString *line, id context, * id exception)`. */ - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding target: (id)target selector: (SEL)selector context: (nullable id)context; # ifdef OF_HAVE_BLOCKS |
︙ | ︙ | |||
771 772 773 774 775 776 777 | * @brief Writes everything in the write buffer to the stream. */ - (void)flushWriteBuffer; /*! * @brief Writes from a buffer into the stream. * | | | 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | * @brief Writes everything in the write buffer to the stream. */ - (void)flushWriteBuffer; /*! * @brief Writes from a buffer into the stream. * * @param buffer The buffer from which the data is written into the stream * @param length The length of the data that should be written */ - (void)writeBuffer: (const void *)buffer length: (size_t)length; /*! * @brief Writes a uint8_t into the stream. |
︙ | ︙ |
Modified src/OFTCPSocket.h from [d70cc2f958] to [79fa8a3d5c].
︙ | ︙ | |||
30 31 32 33 34 35 36 | * @brief A block which is called when the socket connected. * * @param socket The socket which connected * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^of_tcp_socket_async_connect_block_t)(OFTCPSocket *socket, | | | | 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 | * @brief A block which is called when the socket connected. * * @param socket The socket which connected * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^of_tcp_socket_async_connect_block_t)(OFTCPSocket *socket, id _Nullable exception); /*! * @brief A block which is called when the socket accepted a connection. * * @param socket The socket which accepted the connection * @param acceptedSocket The socket which has been accepted * @param exception An exception which occurred while accepting the socket or * `nil` on success * @return A bool whether the same block should be used for the next incoming * connection */ typedef bool (^of_tcp_socket_async_accept_block_t)(OFTCPSocket *socket, OFTCPSocket *acceptedSocket, id _Nullable exception); #endif /*! * @class OFTCPSocket OFTCPSocket.h ObjFW/OFTCPSocket.h * * @brief A class which provides methods to create and use TCP sockets. * |
︙ | ︙ | |||
123 124 125 126 127 128 129 | * @brief Asynchronously connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param target The target on which to call the selector once the connection * has been established * @param selector The selector to call on the target. The signature must be | | < | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | * @brief Asynchronously connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param target The target on which to call the selector once the connection * has been established * @param selector The selector to call on the target. The signature must be * `void (OFTCPSocket *socket, id context, id exception)`. */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port target: (id)target selector: (SEL)selector context: (nullable id)context; |
︙ | ︙ | |||
186 187 188 189 190 191 192 | * * @param target The target on which to execute the selector when a new * connection has been accepted. The method returns whether the * next incoming connection should be accepted by the specified * block as well. * @param selector The selector to call on the target. The signature must be * `bool (OFTCPSocket *socket, OFTCPSocket *acceptedSocket, | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | * * @param target The target on which to execute the selector when a new * connection has been accepted. The method returns whether the * next incoming connection should be accepted by the specified * block as well. * @param selector The selector to call on the target. The signature must be * `bool (OFTCPSocket *socket, OFTCPSocket *acceptedSocket, * id context, id exception)`. */ - (void)asyncAcceptWithTarget: (id)target selector: (SEL)selector context: (nullable id)context; #ifdef OF_HAVE_BLOCKS /*! |
︙ | ︙ |
Modified src/OFTCPSocket.m from [e7861c7baa] to [bfcab86676].
︙ | ︙ | |||
74 75 76 77 78 79 80 | uint16_t _port; id _target; SEL _selector; id _context; # ifdef OF_HAVE_BLOCKS of_tcp_socket_async_connect_block_t _block; # endif | | | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | uint16_t _port; id _target; SEL _selector; id _context; # ifdef OF_HAVE_BLOCKS of_tcp_socket_async_connect_block_t _block; # endif id _exception; } - initWithSourceThread: (OFThread *)sourceThread socket: (OFTCPSocket *)socket host: (OFString *)host port: (uint16_t)port target: (id)target |
︙ | ︙ | |||
168 169 170 171 172 173 174 | [self join]; # ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_socket, _exception); else { # endif | | | | | 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 | [self join]; # ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_socket, _exception); else { # endif void (*func)(id, SEL, OFTCPSocket *, id, id) = (void (*)(id, SEL, OFTCPSocket *, id, id)) [_target methodForSelector: _selector]; func(_target, _selector, _socket, _context, _exception); # ifdef OF_HAVE_BLOCKS } # endif } - (id)main { void *pool = objc_autoreleasePoolPush(); @try { [_socket connectToHost: _host port: _port]; } @catch (id e) { _exception = [e retain]; } [self performSelector: @selector(didConnect) onThread: _sourceThread waitUntilDone: false]; |
︙ | ︙ |
Modified src/OFUDPSocket.h from [dea0dfc05e] to [9375eeb6ac].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "socket.h" OF_ASSUME_NONNULL_BEGIN /*! @file */ @class OFUDPSocket; | < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "socket.h" OF_ASSUME_NONNULL_BEGIN /*! @file */ @class OFUDPSocket; /*! * @struct of_udp_socket_address_t OFUDPSocket.h ObjFW/OFUDPSocket.h * * @brief A struct which represents a host / port pair for a UDP socket. */ typedef struct { |
︙ | ︙ | |||
44 45 46 47 48 49 50 | * @param host The host that has been resolved * @param port The port of the host / port pair * @param address The address of the resolved host / port pair * @param exception An exception which occurred while resolving or `nil` on * success */ typedef void (^of_udp_socket_async_resolve_block_t)(OFString *host, | | < | | 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 | * @param host The host that has been resolved * @param port The port of the host / port pair * @param address The address of the resolved host / port pair * @param exception An exception which occurred while resolving or `nil` on * success */ typedef void (^of_udp_socket_async_resolve_block_t)(OFString *host, uint16_t port, of_udp_socket_address_t address, id _Nullable exception); /*! * @brief A block which is called when a packet has been received. * * @param socket The UDP which received a packet * @param buffer The buffer the packet has been written to * @param length The length of the packet * @param sender The address of the sender of the packet * @param exception An exception which occurred while receiving or `nil` on * success * @return A bool whether the same block should be used for the next receive */ typedef bool (^of_udp_socket_async_receive_block_t)(OFUDPSocket *socket, void *buffer, size_t length, of_udp_socket_address_t sender, id _Nullable exception); #endif /*! * @class OFUDPSocket OFUDPSocket.h ObjFW/OFUDPSocket.h * * @brief A class which provides methods to create and use UDP sockets. * |
︙ | ︙ | |||
123 124 125 126 127 128 129 | * * @param host The host to resolve * @param port The port for the resulting address * @param target The target on which to call the selector once the host has been * resolved * @param selector The selector to call on the target. The signature must be * `void (OFString *host, uint16_t port, | | < | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | * * @param host The host to resolve * @param port The port for the resulting address * @param target The target on which to call the selector once the host has been * resolved * @param selector The selector to call on the target. The signature must be * `void (OFString *host, uint16_t port, * of_udp_socket_address_t address, id context, id exception)`. */ + (void)asyncResolveAddressForHost: (OFString *)host port: (uint16_t)port target: (id)target selector: (SEL)selector context: (nullable id)context; |
︙ | ︙ | |||
203 204 205 206 207 208 209 | * datagram has been received. If the method returns true, it * will be called again with the same buffer and maximum length * when more datagrams have been received. If you want the next * method in the queue to handle the datagram received next, you * need to return false from the method. * @param selector The selector to call on the target. The signature must be * `bool (OFUDPSocket *socket, void *buffer, size_t length, | | < | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | * datagram has been received. If the method returns true, it * will be called again with the same buffer and maximum length * when more datagrams have been received. If you want the next * method in the queue to handle the datagram received next, you * need to return false from the method. * @param selector The selector to call on the target. The signature must be * `bool (OFUDPSocket *socket, void *buffer, size_t length, * of_udp_socket_address_t, id context, id exception)`. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length target: (id)target selector: (SEL)selector context: (nullable id)context; |
︙ | ︙ |
Modified src/OFUDPSocket.m from [c1cf4f8ea1] to [971c30a9d2].
︙ | ︙ | |||
52 53 54 55 56 57 58 | id _target; SEL _selector; id _context; # ifdef OF_HAVE_BLOCKS of_udp_socket_async_resolve_block_t _block; # endif of_udp_socket_address_t _address; | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | id _target; SEL _selector; id _context; # ifdef OF_HAVE_BLOCKS of_udp_socket_async_resolve_block_t _block; # endif of_udp_socket_address_t _address; id _exception; } - initWithSourceThread: (OFThread *)sourceThread host: (OFString *)host port: (uint16_t)port target: (id)target selector: (SEL)selector |
︙ | ︙ | |||
140 141 142 143 144 145 146 | # ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_host, _port, _address, _exception); else { # endif void (*func)(id, SEL, OFString *, uint16_t, | | | | | 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 | # ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_host, _port, _address, _exception); else { # endif void (*func)(id, SEL, OFString *, uint16_t, of_udp_socket_address_t, id, id) = (void (*)(id, SEL, OFString *, uint16_t, of_udp_socket_address_t, id, id)) [_target methodForSelector: _selector]; func(_target, _selector, _host, _port, _address, _context, _exception); # ifdef OF_HAVE_BLOCKS } # endif } - (id)main { void *pool = objc_autoreleasePoolPush(); @try { [OFUDPSocket resolveAddressForHost: _host port: _port address: &_address]; } @catch (id e) { _exception = e; } [self performSelector: @selector(didResolve) onThread: _sourceThread waitUntilDone: false]; |
︙ | ︙ |