summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-12-14 10:02:57 -0500
committerGitHub <noreply@github.com>2017-12-14 10:02:57 -0500
commit7ed4cd7d1a8dac432e98df6f1eb76ea82111f947 (patch)
treec9b0d5e1bcb6d5d6cfe1e38d7c214ca9ed373b79
parentdbe8e637d736eab90bcc0b18bf80b36a6797e618 (diff)
parentf7b03cb6df8ab5e014f84756e51ac8aad738f24c (diff)
downloadsdl_ios-7ed4cd7d1a8dac432e98df6f1eb76ea82111f947.tar.gz
Merge pull request #818 from Toyota-BSalahat/hotfix/tcpBackgroundConnection
Wrap TCP transport connect logic inside of an operation queue
-rw-r--r--SmartDeviceLink/SDLTCPTransport.m30
1 files changed, 16 insertions, 14 deletions
diff --git a/SmartDeviceLink/SDLTCPTransport.m b/SmartDeviceLink/SDLTCPTransport.m
index 91e693c8b..298ea70c7 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 {