diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2018-01-05 09:34:56 -0500 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2018-01-05 09:34:56 -0500 |
commit | a03434ff055a40dd696fcde83d24901799bdd268 (patch) | |
tree | f286f22f76e908fa85a7397e1018bffb20124d5d | |
parent | 5f8d711c7070204e7bf731a3ab76be6b9f9bbe71 (diff) | |
parent | b7c427d8ed32bc0cfc37c84fc8f852a577a598d3 (diff) | |
download | sdl_ios-a03434ff055a40dd696fcde83d24901799bdd268.tar.gz |
Merge branch 'develop' into feature/issue_794_CarWindow
-rw-r--r-- | SmartDeviceLink/SDLIAPSession.m | 12 | ||||
-rw-r--r-- | SmartDeviceLink/SDLTCPTransport.m | 30 |
2 files changed, 26 insertions, 16 deletions
diff --git a/SmartDeviceLink/SDLIAPSession.m b/SmartDeviceLink/SDLIAPSession.m index db64bf678..33a7cf1f1 100644 --- a/SmartDeviceLink/SDLIAPSession.m +++ b/SmartDeviceLink/SDLIAPSession.m @@ -81,8 +81,16 @@ NSTimeInterval const StreamThreadWaitSecs = 1.0; - (void)stop { // This method must be called on the main thread - NSAssert([NSThread isMainThread], @"stop must be called on the main thread"); - + if ([NSThread isMainThread]) { + [self sdl_stop]; + } else { + dispatch_sync(dispatch_get_main_queue(), ^{ + [self sdl_stop]; + }); + } +} + +- (void)sdl_stop { if (self.isDataSession) { [self.ioStreamThread cancel]; diff --git a/SmartDeviceLink/SDLTCPTransport.m b/SmartDeviceLink/SDLTCPTransport.m index fd37ae153..99e46074c 100644 --- a/SmartDeviceLink/SDLTCPTransport.m +++ b/SmartDeviceLink/SDLTCPTransport.m @@ -46,20 +46,22 @@ static void TCPCallback(CFSocketRef socket, CFSocketCallBackType type, CFDataRef } - (void)connect { - SDLLogD(@"Attemping to connect"); - - int sock_fd = call_socket([self.hostName UTF8String], [self.portNumber UTF8String]); - if (sock_fd < 0) { - SDLLogE(@"Server not ready, connection failed"); - return; - } - - CFSocketContext socketCtxt = {0, (__bridge void *)(self), NULL, NULL, NULL}; - socket = CFSocketCreateWithNative(kCFAllocatorDefault, sock_fd, kCFSocketDataCallBack | kCFSocketConnectCallBack, (CFSocketCallBack)&TCPCallback, &socketCtxt); - CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, socket, 0); - CFRunLoopRef loop = CFRunLoopGetCurrent(); - CFRunLoopAddSource(loop, source, kCFRunLoopDefaultMode); - CFRelease(source); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + SDLLogD(@"Attemping to connect"); + + int sock_fd = call_socket([self.hostName UTF8String], [self.portNumber UTF8String]); + if (sock_fd < 0) { + SDLLogE(@"Server not ready, connection failed"); + return; + } + + CFSocketContext socketCtxt = {0, (__bridge void *)(self), NULL, NULL, NULL}; + socket = CFSocketCreateWithNative(kCFAllocatorDefault, sock_fd, kCFSocketDataCallBack | kCFSocketConnectCallBack, (CFSocketCallBack)&TCPCallback, &socketCtxt); + CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, socket, 0); + CFRunLoopRef loop = CFRunLoopGetCurrent(); + CFRunLoopAddSource(loop, source, kCFRunLoopDefaultMode); + CFRelease(source); + }]; } - (void)sendData:(NSData *)msgBytes { |