From d84fd79d14a8d9e59821e954ad0727d901b80292 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Fri, 1 Mar 2013 12:22:41 +0200 Subject: [PATCH] Reverted the CURL locking changes and updated some word wrapping. --- protocolcurl.c | 4 ++-- protocolhttp.c | 5 +++-- socket.c | 14 ++++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/protocolcurl.c b/protocolcurl.c index 4801fa9..16178f6 100644 --- a/protocolcurl.c +++ b/protocolcurl.c @@ -420,7 +420,6 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP) int len = 0; if (ringBufferM) { // Fill up the buffer - mutexM.Lock(); if (handleM && multiM) { switch (modeM) { case eModeRtsp: @@ -444,12 +443,14 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP) } while (res == CURLM_CALL_MULTI_PERFORM); // Shall we continue filling up the buffer? + mutexM.Lock(); if (pausedM && (ringBufferM->Free() > ringBufferM->Available())) { debug("cIptvProtocolCurl::%s(continue): free=%d available=%d", __FUNCTION__, ringBufferM->Free(), ringBufferM->Available()); pausedM = false; curl_easy_pause(handleM, CURLPAUSE_CONT); } + mutexM.Unlock(); // Check if end of file if (running_handles == 0) { @@ -470,7 +471,6 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP) break; } } - mutexM.Unlock(); // ... and try to empty it unsigned char *p = GetData(&bufferLenP); diff --git a/protocolhttp.c b/protocolhttp.c index 9365f23..995109f 100644 --- a/protocolhttp.c +++ b/protocolhttp.c @@ -55,8 +55,9 @@ bool cIptvProtocolHttp::Connect(void) "Connection: Close\r\n" "\r\n", streamPathM, streamAddrM, PLUGIN_NAME_I18N, VERSION); - debug("cIptvProtocolHttp::%s(): requesting: %s", __FUNCTION__, *buffer); - if (!Write(*buffer, (unsigned int)strlen(*buffer))) { + unsigned int len = strlen(*buffer); + debug("cIptvProtocolHttp::%s(): requesting %d: %s", __FUNCTION__, len, *buffer); + if (!Write(*buffer, len)) { CloseSocket(); return false; } diff --git a/socket.c b/socket.c index e0b74ef..6d65b84 100644 --- a/socket.c +++ b/socket.c @@ -56,12 +56,12 @@ bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP) ERROR_IF_FUNC(fcntl(socketDescM, F_SETFL, O_NONBLOCK), "fcntl(O_NONBLOCK)", CloseSocket(), return false); // Allow multiple sockets to use the same PORT number - ERROR_IF_FUNC(setsockopt(socketDescM, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0, "setsockopt(SO_REUSEADDR)", - CloseSocket(), return false); + ERROR_IF_FUNC(setsockopt(socketDescM, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0, + "setsockopt(SO_REUSEADDR)", CloseSocket(), return false); #ifndef __FreeBSD__ // Allow packet information to be fetched - ERROR_IF_FUNC(setsockopt(socketDescM, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0, "setsockopt(IP_PKTINFO)", - CloseSocket(), return false); + ERROR_IF_FUNC(setsockopt(socketDescM, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0, + "setsockopt(IP_PKTINFO)", CloseSocket(), return false); #endif // __FreeBSD__ // Bind socket memset(&sockAddrM, 0, sizeof(sockAddrM)); @@ -69,7 +69,8 @@ bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP) sockAddrM.sin_port = htons((uint16_t)(portP & 0xFFFF)); sockAddrM.sin_addr.s_addr = htonl(INADDR_ANY); if (isUdpP) - ERROR_IF_FUNC(bind(socketDescM, (struct sockaddr *)&sockAddrM, sizeof(sockAddrM)) < 0, "bind()", CloseSocket(), return false); + ERROR_IF_FUNC(bind(socketDescM, (struct sockaddr *)&sockAddrM, sizeof(sockAddrM)) < 0, + "bind()", CloseSocket(), return false); // Update socket port socketPortM = portP; } @@ -99,7 +100,8 @@ bool cIptvSocket::CheckAddress(const char *addrP, in_addr_t *inAddrP) struct hostent *host = gethostbyname(addrP); if (!host) { char tmp[64]; - error("gethostbyname() failed: %s is not valid address: %s", addrP, strerror_r(h_errno, tmp, sizeof(tmp))); + error("gethostbyname() failed: %s is not valid address: %s", addrP, + strerror_r(h_errno, tmp, sizeof(tmp))); return false; } *inAddrP = htonl(inet_addr(*host->h_addr_list));