diff --git a/limelight-common.xcodeproj/project.pbxproj b/limelight-common.xcodeproj/project.pbxproj index 0570424..a751078 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 */; }; @@ -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; @@ -283,6 +284,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; + SKIP_INSTALL = YES; }; name = Debug; }; @@ -302,6 +304,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; @@ -314,13 +317,16 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; + PROVISIONING_PROFILE = ""; SDKROOT = macosx; + SKIP_INSTALL = YES; }; name = Release; }; FB290E3319B37A4E004C83CF /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Developer"; EXECUTABLE_PREFIX = lib; ONLY_ACTIVE_ARCH = NO; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -332,6 +338,7 @@ FB290E3419B37A4E004C83CF /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Distribution"; EXECUTABLE_PREFIX = lib; ONLY_ACTIVE_ARCH = NO; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/limelight-common/ControlStream.c b/limelight-common/ControlStream.c index 6a76e1a..f3f5887 100644 --- a/limelight-common/ControlStream.c +++ b/limelight-common/ControlStream.c @@ -96,7 +96,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; @@ -107,21 +107,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 c69537c..dee03f1 100644 --- a/limelight-common/InputStream.c +++ b/limelight-common/InputStream.c @@ -90,6 +90,8 @@ void destroyInputStream(void) { initialized = 0; } +#define OAES_DATA_OFFSET 32 + /* Input thread proc */ static void inputSendThreadProc(void* context) { SOCK_RET err; @@ -118,21 +120,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; } 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;