@@ -17,13 +17,10 @@ #include #import "OFIPSocketAsyncConnector.h" #import "OFData.h" -#ifdef OF_HAVE_SCTP -# import "OFSCTPSocket.h" -#endif #import "OFTCPSocket.h" #import "OFThread.h" #import "OFTimer.h" #import "OFConnectionFailedException.h" @@ -70,34 +67,27 @@ [_socket setCanBlock: true]; #ifdef OF_HAVE_BLOCKS if (_block != NULL) { if ([_socket isKindOfClass: [OFTCPSocket class]]) - ((of_tcp_socket_async_connect_block_t)_block)( - _exception); -# ifdef OF_HAVE_SCTP - else if ([_socket isKindOfClass: [OFSCTPSocket class]]) - ((of_sctp_socket_async_connect_block_t)_block)( - _exception); -# endif + ((OFTCPSocketAsyncConnectBlock)_block)(_exception); else - OF_ENSURE(0); + OFEnsure(0); } else { #endif if ([_delegate respondsToSelector: @selector(socket:didConnectToHost:port:exception:)]) - [_delegate socket: _socket + [_delegate socket: _socket didConnectToHost: _host port: _port exception: _exception]; #ifdef OF_HAVE_BLOCKS } #endif } -- (void)of_socketDidConnect: (id)sock - exception: (id)exception +- (void)of_socketDidConnect: (id)sock exception: (id)exception { if (exception != nil) { /* * self might be retained only by the pending async requests, * which we're about to cancel. @@ -123,12 +113,11 @@ timerWithTimeInterval: 0 target: self selector: selector object: runLoop.currentMode repeats: false]; - [runLoop addTimer: timer - forMode: runLoop.currentMode]; + [runLoop addTimer: timer forMode: runLoop.currentMode]; } return; } @@ -141,20 +130,19 @@ port: _port socket: _socket errNo: errNo]; } -- (void)tryNextAddressWithRunLoopMode: (of_run_loop_mode_t)runLoopMode +- (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode { - of_socket_address_t address = *(const of_socket_address_t *) + OFSocketAddress address = *(const OFSocketAddress *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; int errNo; - of_socket_address_set_port(&address, _port); + OFSocketAddressSetPort(&address, _port); - if (![_socket of_createSocketForAddress: &address - errNo: &errNo]) { + if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host port: _port socket: _socket @@ -181,14 +169,17 @@ [_socket setCanBlock: true]; #else [_socket setCanBlock: false]; #endif - if (![_socket of_connectSocketToAddress: &address - errNo: &errNo]) { + if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) { #if !defined(OF_NINTENDO_3DS) && !defined(OF_WII) +# ifdef OF_WINDOWS + if (errNo == EINPROGRESS || errNo == EWOULDBLOCK) { +# else if (errNo == EINPROGRESS) { +# endif [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } else { @@ -234,15 +225,14 @@ [self tryNextAddressWithRunLoopMode: [OFRunLoop currentRunLoop].currentMode]; } -- (void)startWithRunLoopMode: (of_run_loop_mode_t)runLoopMode +- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { @try { - of_socket_address_t address = - of_socket_address_parse_ip(_host, _port); + OFSocketAddress address = OFSocketAddressParseIP(_host, _port); _socketAddresses = [[OFData alloc] initWithItems: &address count: 1 itemSize: sizeof(address)]; @@ -252,10 +242,10 @@ } @catch (OFInvalidFormatException *e) { } [[OFThread DNSResolver] asyncResolveAddressesForHost: _host - addressFamily: OF_SOCKET_ADDRESS_FAMILY_ANY + addressFamily: OFSocketAddressFamilyAny runLoopMode: runLoopMode delegate: self]; } @end