summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2017-10-03 10:17:46 -0400
committerNicoleYarroch <nicole@livio.io>2017-10-03 10:17:46 -0400
commit9f268f634ac684f3e0346d9051f94a12a4fd001a (patch)
tree0b4e7ee1a773e0366e2885edd83ca4acb369a6b5
parent75a31a3ab4166fa3f3321e7608839a3729360eae (diff)
parent511a08c31faba735802cc47a26ffe38c34724da0 (diff)
downloadsdl_ios-bugfix/issue_740_Accessory_connection_fails_app_in_background.tar.gz
Merge branch 'release/5.0.0' into bugfix/issue_740_Accessory_connection_fails_app_in_backgroundbugfix/issue_740_Accessory_connection_fails_app_in_background
-rw-r--r--SmartDeviceLink/SDLIAPSession.m25
1 files changed, 9 insertions, 16 deletions
diff --git a/SmartDeviceLink/SDLIAPSession.m b/SmartDeviceLink/SDLIAPSession.m
index 8e0df7f50..86132320c 100644
--- a/SmartDeviceLink/SDLIAPSession.m
+++ b/SmartDeviceLink/SDLIAPSession.m
@@ -111,29 +111,29 @@ NSTimeInterval const StreamThreadWaitSecs = 1.0;
- (void)sendData:(NSData *)data {
// Enqueue the data for transmission on the IO thread
[self.sendDataQueue enqueueBuffer:data.mutableCopy];
+
+ [self performSelector:@selector(sdl_dequeueAndWriteToOutputStream) onThread:self.ioStreamThread withObject:nil waitUntilDone:NO];
}
-- (BOOL)sdl_dequeueAndWriteToOutputStream:(NSError **)error {
+- (void)sdl_dequeueAndWriteToOutputStream {
NSOutputStream *ostream = self.easession.outputStream;
NSMutableData *remainder = [self.sendDataQueue frontBuffer];
- BOOL allDataWritten = NO;
- if (error != nil && remainder != nil && ostream.streamStatus == NSStreamStatusOpen) {
+ if (remainder != nil && ostream.streamStatus == NSStreamStatusOpen) {
NSInteger bytesRemaining = remainder.length;
NSInteger bytesWritten = [ostream write:remainder.bytes maxLength:bytesRemaining];
if (bytesWritten < 0) {
- *error = ostream.streamError;
+ if (ostream.streamError != nil) {
+ [self sdl_handleOutputStreamWriteError:ostream.streamError];
+ }
} else if (bytesWritten == bytesRemaining) {
// Remove the data from the queue
[self.sendDataQueue popBuffer];
- allDataWritten = YES;
} else {
// Cleave the sent bytes from the data, the remainder will sit at the head of the queue
[remainder replaceBytesInRange:NSMakeRange(0, bytesWritten) withBytes:NULL length:0];
}
}
-
- return allDataWritten;
}
- (void)sdl_handleOutputStreamWriteError:(NSError *)error {
@@ -163,10 +163,7 @@ NSTimeInterval const StreamThreadWaitSecs = 1.0;
SDLLogD(@"Starting the accessory event loop");
do {
if (self.sendDataQueue.count > 0 && !self.sendDataQueue.frontDequeued) {
- NSError *sendErr = nil;
- if (![self sdl_dequeueAndWriteToOutputStream:&sendErr] && sendErr != nil) {
- [self sdl_handleOutputStreamWriteError:sendErr];
- }
+ [self sdl_dequeueAndWriteToOutputStream];
}
// The principle here is to give the event loop enough time to process stream events while also allowing it to handle new enqueued data buffers in a timely manner. We're capping the run loop CPU time at 0.25s maximum before it will return control to the rest of the loop.
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25f]];
@@ -277,11 +274,7 @@ NSTimeInterval const StreamThreadWaitSecs = 1.0;
return;
}
- NSError *sendErr = nil;
-
- if (![strongSelf sdl_dequeueAndWriteToOutputStream:&sendErr] && sendErr != nil) {
- [strongSelf sdl_handleOutputStreamWriteError:sendErr];
- }
+ [strongSelf sdl_dequeueAndWriteToOutputStream];
};
}