From e56f13b1232d345c8d87d04d10e92905483e51b3 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 21 Oct 2014 14:17:52 -0400 Subject: [PATCH 1/4] Set SO_NOSIGPIPE on Darwin to stop from breaking into the debugger every time a connection closes --- limelight-common/Platform.h | 3 +++ limelight-common/PlatformSockets.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/limelight-common/Platform.h b/limelight-common/Platform.h index f4cf1a9..9a966f0 100644 --- a/limelight-common/Platform.h +++ b/limelight-common/Platform.h @@ -21,6 +21,9 @@ # endif #else # define LC_POSIX +# if defined(__APPLE__) +# define LC_DARWIN +# endif #endif #include diff --git a/limelight-common/PlatformSockets.c b/limelight-common/PlatformSockets.c index 55be75c..bc0e8bb 100644 --- a/limelight-common/PlatformSockets.c +++ b/limelight-common/PlatformSockets.c @@ -20,7 +20,14 @@ SOCKET bindUdpSocket(void) { SetLastSocketError(err); return INVALID_SOCKET; } + +#ifdef LC_DARWIN + // Disable SIGPIPE on iOS + val = 1; + setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char* )&val, sizeof(val)); +#endif + // Set the receive buffer to 64KB by default val = 65536; setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*) &val, sizeof(val)); @@ -31,11 +38,20 @@ SOCKET connectTcpSocket(IP_ADDRESS dstaddr, unsigned short port) { SOCKET s; struct sockaddr_in addr; int err; +#ifdef LC_DARWIN + int val; +#endif s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == INVALID_SOCKET) { return INVALID_SOCKET; } + +#ifdef LC_DARWIN + // Disable SIGPIPE on iOS + val = 1; + setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char* )&val, sizeof(val)); +#endif memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; From 0f9442ff9c230cfa025779bcca2bc49a31235524 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Tue, 21 Oct 2014 16:02:41 -0400 Subject: [PATCH 2/4] prepped for deployment --- limelight-common.xcodeproj/project.pbxproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/limelight-common.xcodeproj/project.pbxproj b/limelight-common.xcodeproj/project.pbxproj index 0570424..f5b2491 100644 --- a/limelight-common.xcodeproj/project.pbxproj +++ b/limelight-common.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ FB290E5F19B37A8B004C83CF /* Input.h in Headers */ = {isa = PBXBuildFile; fileRef = FB290E3B19B37A8B004C83CF /* Input.h */; }; FB290E6019B37A8B004C83CF /* InputStream.c in Sources */ = {isa = PBXBuildFile; fileRef = FB290E3C19B37A8B004C83CF /* InputStream.c */; }; FB290E6119B37A8B004C83CF /* Limelight-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = FB290E3F19B37A8B004C83CF /* Limelight-internal.h */; }; - FB290E6219B37A8B004C83CF /* Limelight.h in Headers */ = {isa = PBXBuildFile; fileRef = FB290E4019B37A8B004C83CF /* Limelight.h */; settings = {ATTRIBUTES = (Public, ); }; }; + FB290E6219B37A8B004C83CF /* Limelight.h in Headers */ = {isa = PBXBuildFile; fileRef = FB290E4019B37A8B004C83CF /* Limelight.h */; }; FB290E6319B37A8B004C83CF /* LinkedBlockingQueue.c in Sources */ = {isa = PBXBuildFile; fileRef = FB290E4119B37A8B004C83CF /* LinkedBlockingQueue.c */; }; FB290E6419B37A8B004C83CF /* LinkedBlockingQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = FB290E4219B37A8B004C83CF /* LinkedBlockingQueue.h */; }; FB290E6519B37A8B004C83CF /* oaes_base64.c in Sources */ = {isa = PBXBuildFile; fileRef = FB290E4519B37A8B004C83CF /* oaes_base64.c */; }; @@ -283,6 +283,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; + SKIP_INSTALL = YES; }; name = Debug; }; @@ -302,6 +303,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Distribution: Diego Waxemberg (DM46QST4M7)"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; @@ -314,7 +316,9 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; + PROVISIONING_PROFILE = "d8351c44-2c9d-4b3a-bc67-ea963350dcbe"; SDKROOT = macosx; + SKIP_INSTALL = YES; }; name = Release; }; From bc8275474f8195208f46a4d134e6858933ee5148 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Tue, 21 Oct 2014 16:17:34 -0400 Subject: [PATCH 3/4] removed my code signing ids --- limelight-common.xcodeproj/project.pbxproj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/limelight-common.xcodeproj/project.pbxproj b/limelight-common.xcodeproj/project.pbxproj index f5b2491..a751078 100644 --- a/limelight-common.xcodeproj/project.pbxproj +++ b/limelight-common.xcodeproj/project.pbxproj @@ -264,6 +264,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "Mac Developer"; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -303,7 +304,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "iPhone Distribution: Diego Waxemberg (DM46QST4M7)"; + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; @@ -316,7 +317,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; - PROVISIONING_PROFILE = "d8351c44-2c9d-4b3a-bc67-ea963350dcbe"; + PROVISIONING_PROFILE = ""; SDKROOT = macosx; SKIP_INSTALL = YES; }; @@ -325,6 +326,7 @@ FB290E3319B37A4E004C83CF /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Developer"; EXECUTABLE_PREFIX = lib; ONLY_ACTIVE_ARCH = NO; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -336,6 +338,7 @@ FB290E3419B37A4E004C83CF /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Distribution"; EXECUTABLE_PREFIX = lib; ONLY_ACTIVE_ARCH = NO; PRODUCT_NAME = "$(TARGET_NAME)"; From 47820c35bdb50e6092fd061b0eb38db648c0e8f7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 22 Oct 2014 21:48:52 -0400 Subject: [PATCH 4/4] Send TCP messages in a single call to send() because GFE can't handle receiving messages in fragments --- limelight-common/ControlStream.c | 24 +++++++++++++----------- limelight-common/InputStream.c | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/limelight-common/ControlStream.c b/limelight-common/ControlStream.c index 87131bf..9b6f369 100644 --- a/limelight-common/ControlStream.c +++ b/limelight-common/ControlStream.c @@ -88,7 +88,7 @@ static PNVCTL_PACKET_HEADER readNvctlPacket(void) { memcpy(fullPacket, &staticHeader, sizeof(staticHeader)); if (staticHeader.payloadLength != 0) { - err = recv(ctlSock, (char*) (fullPacket + 1), staticHeader.payloadLength, 0); + err = recv(ctlSock, (char*) (fullPacket + 1), staticHeader.payloadLength, 0); if (err != staticHeader.payloadLength) { free(fullPacket); return NULL; @@ -99,21 +99,23 @@ static PNVCTL_PACKET_HEADER readNvctlPacket(void) { } static int sendMessageAndForget(short ptype, short paylen, const void* payload) { - NVCTL_PACKET_HEADER header; + PNVCTL_PACKET_HEADER packet; SOCK_RET err; - header.type = ptype; - header.payloadLength = paylen; - err = send(ctlSock, (char*) &header, sizeof(header), 0); - if (err != sizeof(header)) { + packet = malloc(sizeof(*packet) + paylen); + if (packet == NULL) { return 0; } - if (payload != NULL) { - err = send(ctlSock, payload, paylen, 0); - if (err != paylen) { - return 0; - } + packet->type = ptype; + packet->payloadLength = paylen; + memcpy(&packet[1], payload, paylen); + + err = send(ctlSock, (char*) packet, sizeof(*packet) + paylen, 0); + free(packet); + + if (err != sizeof(*packet)) { + return 0; } return 1; diff --git a/limelight-common/InputStream.c b/limelight-common/InputStream.c index 49517ee..f36f69d 100644 --- a/limelight-common/InputStream.c +++ b/limelight-common/InputStream.c @@ -87,6 +87,7 @@ void destroyInputStream(void) { initialized = 0; } +#define OAES_DATA_OFFSET 32 static void inputSendThreadProc(void* context) { SOCK_RET err; PPACKET_HOLDER holder; @@ -114,21 +115,20 @@ static void inputSendThreadProc(void* context) { } // The first 32-bytes of the output are internal OAES stuff that we want to ignore - encryptedSize -= 32; + encryptedSize -= OAES_DATA_OFFSET; - // Send the encrypted length first + // Overwrite the last 4 bytes before the encrypted data with the length so + // we can send the message all at once. GFE can choke if it gets the header + // before the rest of the message. encryptedLengthPrefix = htonl((unsigned long) encryptedSize); - err = send(inputSock, (const char*) &encryptedLengthPrefix, sizeof(encryptedLengthPrefix), 0); - if (err <= 0) { - Limelog("Input thread terminating #3\n"); - listenerCallbacks->connectionTerminated(err); - return; - } + memcpy(&encryptedBuffer[OAES_DATA_OFFSET - sizeof(encryptedLengthPrefix)], + &encryptedLengthPrefix, sizeof(encryptedLengthPrefix)); // Send the encrypted payload - err = send(inputSock, (const char*) &encryptedBuffer[32], encryptedSize, 0); + err = send(inputSock, (const char*) &encryptedBuffer[OAES_DATA_OFFSET - sizeof(encryptedLengthPrefix)], + encryptedSize + sizeof(encryptedLengthPrefix), 0); if (err <= 0) { - Limelog("Input thread terminating #4\n"); + Limelog("Input thread terminating #3\n"); listenerCallbacks->connectionTerminated(err); return; }