summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorsiqi <me@siqi.fr>2013-07-15 12:04:17 +0200
committersiqi <me@siqi.fr>2013-07-15 12:04:17 +0200
commit062de1e49312fda5e184d12576d37a569769bb86 (patch)
tree9739d4406ce0b4a27c2d5ec56fa3f3f4b6049a6b /ios
parent138ecf78253dd9116c96f27b4e0b78be322c6dd3 (diff)
improved thread safety during disconnection
Diffstat (limited to 'ios')
-rw-r--r--ios/iosremote/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--ios/iosremote/ic_launcher.pngbin5612 -> 6581 bytes
-rw-r--r--ios/iosremote/ic_launcher@2x.pngbin10224 -> 12380 bytes
-rw-r--r--ios/iosremote/ic_launcher@2x.psdbin58981 -> 83340 bytes
-rw-r--r--ios/iosremote/iosremote/.DS_Storebin6148 -> 12292 bytes
-rw-r--r--ios/iosremote/iosremote/Communication/Client.m54
-rw-r--r--ios/iosremote/iosremote/Communication/CommunicationManager.m15
-rw-r--r--ios/iosremote/iosremote/Communication/pinValidation_vc.m1
8 files changed, 41 insertions, 29 deletions
diff --git a/ios/iosremote/.DS_Store b/ios/iosremote/.DS_Store
index eb479088abb0..493f09446040 100644
--- a/ios/iosremote/.DS_Store
+++ b/ios/iosremote/.DS_Store
Binary files differ
diff --git a/ios/iosremote/ic_launcher.png b/ios/iosremote/ic_launcher.png
index f81bf7a9a886..508d9475f98c 100644
--- a/ios/iosremote/ic_launcher.png
+++ b/ios/iosremote/ic_launcher.png
Binary files differ
diff --git a/ios/iosremote/ic_launcher@2x.png b/ios/iosremote/ic_launcher@2x.png
index 333330893e51..6febfad1df0b 100644
--- a/ios/iosremote/ic_launcher@2x.png
+++ b/ios/iosremote/ic_launcher@2x.png
Binary files differ
diff --git a/ios/iosremote/ic_launcher@2x.psd b/ios/iosremote/ic_launcher@2x.psd
index 2b8023b7943e..7b50ef96a575 100644
--- a/ios/iosremote/ic_launcher@2x.psd
+++ b/ios/iosremote/ic_launcher@2x.psd
Binary files differ
diff --git a/ios/iosremote/iosremote/.DS_Store b/ios/iosremote/iosremote/.DS_Store
index 5008ddfcf53c..ef99c3a95a49 100644
--- a/ios/iosremote/iosremote/.DS_Store
+++ b/ios/iosremote/iosremote/.DS_Store
Binary files differ
diff --git a/ios/iosremote/iosremote/Communication/Client.m b/ios/iosremote/iosremote/Communication/Client.m
index 1320de1a2d27..a17f097a9057 100644
--- a/ios/iosremote/iosremote/Communication/Client.m
+++ b/ios/iosremote/iosremote/Communication/Client.m
@@ -42,12 +42,14 @@
dispatch_queue_t backgroundQueue;
+NSLock *streamStatusLock;
- (id) initWithServer:(Server*)server
managedBy:(CommunicationManager*)manager
interpretedBy:(CommandInterpreter*)receiver
{
self = [self init];
+ streamStatusLock = [[NSLock alloc] init];
if (self)
{
self.connected = NO;
@@ -65,7 +67,7 @@ dispatch_queue_t backgroundQueue;
- (void)startConnectionTimeoutTimerwithInterval:(double) interval
{
[self stopConnectionTimeoutTimer]; // Or make sure any existing timer is stopped before this method is called
-
+
self.connectionTimeoutTimer = [NSTimer scheduledTimerWithTimeInterval:interval
target:self
selector:@selector(handleConnectionTimeout)
@@ -101,17 +103,17 @@ dispatch_queue_t backgroundQueue;
{
// Look up if there is already a pin code for this client.
NSUserDefaults * userDefaluts = [NSUserDefaults standardUserDefaults];
-
+
if(!userDefaluts)
NSLog(@"userDefaults nil");
NSInteger newPin = [userDefaluts integerForKey:self.name];
-
+
// If not, generate one.
if (!newPin) {
newPin = arc4random() % 9999;
[userDefaluts setInteger:newPin forKey:self.name];
}
-
+
return newPin;
}
@@ -121,12 +123,12 @@ dispatch_queue_t backgroundQueue;
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)ip, portNumber, &readStream, &writeStream);
-
+
if(readStream && writeStream)
{
CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
-
+
//Setup mInputStream
self.inputStream = (__bridge NSInputStream *)readStream;
[self.inputStream setDelegate:self];
@@ -134,7 +136,7 @@ dispatch_queue_t backgroundQueue;
[self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
});
[self.inputStream open];
-
+
//Setup outputstream
self.outputStream = (__bridge NSOutputStream *)writeStream;
[self.outputStream setDelegate:self];
@@ -142,10 +144,10 @@ dispatch_queue_t backgroundQueue;
[self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
});
[self.outputStream open];
-
+
NSArray *temp = [[NSArray alloc]initWithObjects:@"LO_SERVER_CLIENT_PAIR\n", self.name, @"\n", self.pin, @"\n\n", nil];
NSString *command = [temp componentsJoinedByString:@""];
-
+
[self sendCommand:command];
}
}
@@ -155,7 +157,7 @@ dispatch_queue_t backgroundQueue;
NSLog(@"Sending command %@", aCommand);
// UTF-8 as speficied in specification
NSData * data = [aCommand dataUsingEncoding:NSUTF8StringEncoding];
-
+
[self.outputStream write:(uint8_t *)[data bytes] maxLength:[data length]];
}
@@ -169,10 +171,13 @@ int count = 0;
}
break;
case NSStreamEventErrorOccurred:{
- [self stopConnectionTimeoutTimer];
- [self disconnect];
- NSLog(@"Connection error occured");
- [[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.disconnected" object:nil];
+ @synchronized(self){
+ [self disconnect];
+ NSLog(@"Connection error occured");
+ if (!self.inputStream && !self.outputStream) {
+ [[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.disconnected" object:nil];
+ }
+ }
}
break;
case NSStreamEventHasBytesAvailable:
@@ -197,7 +202,7 @@ int count = 0;
}
}
}
-// NSLog(@"Command:%@", str);
+ // NSLog(@"Command:%@", str);
NSArray *commands = [str componentsSeparatedByString:@"\n"];
[self.receiver parse:commands];
data = nil;
@@ -205,9 +210,9 @@ int count = 0;
} break;
default:
{
-
+
}
-
+
}
}
@@ -215,10 +220,17 @@ int count = 0;
{
if(self.inputStream == nil && self.outputStream == nil)
return;
- [self.inputStream close];
- [self.outputStream close];
- [self.inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- [self.outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+ [self stopConnectionTimeoutTimer];
+ NSLog(@"stream status i:%u o:%u", self.inputStream.streamStatus, self.outputStream.streamStatus);
+ if ([self.inputStream streamStatus] != NSStreamStatusClosed && [self.inputStream streamStatus] != NSStreamStatusError) {
+// NSLog(@"ci");
+ [self.inputStream close];
+ }
+
+ if ([self.outputStream streamStatus] != NSStreamStatusClosed && [self.outputStream streamStatus] != NSStreamStatusError) {
+// NSLog(@"co");
+ [self.outputStream close];
+ }
self.inputStream = nil;
self.outputStream = nil;
self.connected = NO;
diff --git a/ios/iosremote/iosremote/Communication/CommunicationManager.m b/ios/iosremote/iosremote/Communication/CommunicationManager.m
index 683f1f7f3e5b..306b6c9ce46c 100644
--- a/ios/iosremote/iosremote/Communication/CommunicationManager.m
+++ b/ios/iosremote/iosremote/Communication/CommunicationManager.m
@@ -59,13 +59,14 @@
if (self.state != DISCONNECTED) {
NSLog(@"Connection Failed");
self.state = DISCONNECTED;
- [self.client disconnect];
- UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Failed to reach server"
- message:@"Please verify the IP address and try again later"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:@"Help", nil];
- [message show];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Failed to reach server"
+ message:@"Please verify the IP address and try again later"
+ delegate:nil
+ cancelButtonTitle:@"OK"
+ otherButtonTitles:@"Help", nil];
+ [message show];
+ });
}
}
}
diff --git a/ios/iosremote/iosremote/Communication/pinValidation_vc.m b/ios/iosremote/iosremote/Communication/pinValidation_vc.m
index 2d9d3c3a3c46..5956d41a978a 100644
--- a/ios/iosremote/iosremote/Communication/pinValidation_vc.m
+++ b/ios/iosremote/iosremote/Communication/pinValidation_vc.m
@@ -7,7 +7,6 @@
*/
#import "pinValidation_vc.h"
-#import "slideShowPreview_vc.h"
#import "SlideShow.h"
#import "CommandInterpreter.h"
#import "CommunicationManager.h"