ext/iCuke/sdk4.0/iCukeHTTPServer.m in iCuke-0.6.2 vs ext/iCuke/sdk4.0/iCukeHTTPServer.m in iCuke-0.6.3
- old
+ new
@@ -141,10 +141,12 @@
//
// Creates the socket and starts listening for connections on it.
//
- (void)start
{
+ NSLog(@"[iCuke] server starting up");
+
self.lastError = nil;
self.state = SERVER_STATE_STARTING;
socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM,
IPPROTO_TCP, 0, NULL, NULL);
@@ -189,12 +191,25 @@
name:NSFileHandleConnectionAcceptedNotification
object:nil];
[listeningHandle acceptConnectionInBackgroundAndNotify];
self.state = SERVER_STATE_RUNNING;
+
+ if (UIApplicationDidEnterBackgroundNotification != NULL) {
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(applicationDidEnterBackground:)
+ name:UIApplicationDidEnterBackgroundNotification
+ object:nil];
+ }
}
+- (void)applicationDidEnterBackground:(NSNotification *)note;
+{
+ [self stop];
+}
+
//
// stopReceivingForFileHandle:close:
//
// If a file handle is accumulating the header for a new connection, this
// method will close the handle, stop listening to it and release the
@@ -225,10 +240,12 @@
//
// Stops the server.
//
- (void)stop
{
+ NSLog(@"[iCuke] server shutting down");
+
self.state = SERVER_STATE_STOPPING;
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:NSFileHandleConnectionAcceptedNotification
@@ -252,9 +269,16 @@
CFRelease(socket);
socket = nil;
}
self.state = SERVER_STATE_IDLE;
+
+ if (UIApplicationDidEnterBackgroundNotification != NULL) {
+ [[NSNotificationCenter defaultCenter]
+ removeObserver:self
+ name:UIApplicationDidEnterBackgroundNotification
+ object:nil];
+ }
}
//
// receiveIncomingConnectionNotification:
//