cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject cordova-plugins git commit: CB-9096 - local-webserver plugin rejects requests after iOS app is backgrounded
Date Sat, 30 May 2015 00:02:54 GMT
Repository: cordova-plugins
Updated Branches:
  refs/heads/master bf4898899 -> 530c63b49


CB-9096 - local-webserver plugin rejects requests after iOS app is backgrounded


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/530c63b4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/530c63b4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/530c63b4

Branch: refs/heads/master
Commit: 530c63b49c587cf58479aebe871d3c590189f2f3
Parents: bf48988
Author: Shazron Abdullah <shazron@apache.org>
Authored: Fri May 29 17:04:18 2015 -0700
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Fri May 29 17:04:18 2015 -0700

----------------------------------------------------------------------
 local-webserver/src/ios/CDVLocalWebServer.m | 31 +++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/530c63b4/local-webserver/src/ios/CDVLocalWebServer.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalWebServer.m b/local-webserver/src/ios/CDVLocalWebServer.m
index 2f38fec..3d43389 100644
--- a/local-webserver/src/ios/CDVLocalWebServer.m
+++ b/local-webserver/src/ios/CDVLocalWebServer.m
@@ -24,6 +24,7 @@
 #import <AssetsLibrary/AssetsLibrary.h>
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <objc/message.h>
+#import <netinet/in.h>
 
 
 #define LOCAL_FILESYSTEM_PATH   @"local-filesystem"
@@ -71,6 +72,11 @@
         }
     }
 #endif
+    
+    if (port == 0) {
+        // CB-9096 - actually test for an available port, and set it explicitly
+        port = [self _availablePort];
+    }
 
     NSString* authToken = [NSString stringWithFormat:@"cdvToken=%@", [[NSProcessInfo processInfo]
globallyUniqueString]];
 
@@ -107,6 +113,29 @@
     }
 }
 
+- (NSUInteger) _availablePort
+{
+    struct sockaddr_in addr4;
+    bzero(&addr4, sizeof(addr4));
+    addr4.sin_len = sizeof(addr4);
+    addr4.sin_family = AF_INET;
+    addr4.sin_port = 0; // set to 0 and bind to find available port
+    addr4.sin_addr.s_addr = htonl(INADDR_ANY);
+
+    int listeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+    if (bind(listeningSocket, (const void*)&addr4, sizeof(addr4)) == 0) {
+        struct sockaddr addr;
+        socklen_t addrlen = sizeof(addr);
+        if (getsockname(listeningSocket, &addr, &addrlen) == 0) {
+            struct sockaddr_in* sockaddr = (struct sockaddr_in*)&addr;
+            close(listeningSocket);
+            return ntohs(sockaddr->sin_port);
+        }
+    }
+    
+    return 0;
+}
+
 - (BOOL) checkRequirements
 {
     NSString* runtimeVersion = @"8.0";
@@ -145,7 +174,7 @@
             
             NSURL* transformedUrl = urlToTransform;
 
-            NSString* localhostUrlString = [NSString stringWithFormat:@"http://localhost:%lu",
[localServerURL.port unsignedIntegerValue]];
+            NSString* localhostUrlString = [NSString stringWithFormat:@"http://localhost:%lu",
(unsigned long)[localServerURL.port unsignedIntegerValue]];
 
             if ([[urlToTransform scheme] isEqualToString:ASSETS_LIBRARY_PATH]) {
                 transformedUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/%@%@",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message