Skip to content

Commit

Permalink
Tune performace of sockets on Unix/Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jun 3, 2014
1 parent 14d649b commit 946148d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
26 changes: 13 additions & 13 deletions HarmonyHubControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ int swapAuthorizationToken(csocket* authorizationcsocket, std::string& strAuthor
}

bool bIsDataReadable = false;
authorizationcsocket->canRead(&bIsDataReadable, 0.1);
authorizationcsocket->canRead(&bIsDataReadable, 0.3f);
if(!bIsDataReadable && strData == "<iq/>")
{
bIsDataReadable = true;
Expand All @@ -397,7 +397,7 @@ int swapAuthorizationToken(csocket* authorizationcsocket, std::string& strAuthor
memset(databuffer, 0, 1000000);
authorizationcsocket->read(databuffer, 1000000, false);
strData.append(databuffer);
authorizationcsocket->canRead(&bIsDataReadable, 0.1);
authorizationcsocket->canRead(&bIsDataReadable, 0.3f);
};

// Parse the session authorization token from the response
Expand Down Expand Up @@ -486,7 +486,7 @@ int submitCommand(csocket* commandcsocket, std::string& strAuthorizationToken, s
}

bool bIsDataReadable = false;
commandcsocket->canRead(&bIsDataReadable, 0.1);
commandcsocket->canRead(&bIsDataReadable, 0.6f);

if(bIsDataReadable == false && strData == "<iq/>")
{
Expand All @@ -495,14 +495,14 @@ int submitCommand(csocket* commandcsocket, std::string& strAuthorizationToken, s

if(strCommand != "issue_device_command")
{
while(bIsDataReadable)
{
memset(databuffer, 0, 1000000);
commandcsocket->read(databuffer, 1000000, false);
strData.append(databuffer);
commandcsocket->canRead(&bIsDataReadable, 0.1);
};
}
while(bIsDataReadable)
{
memset(databuffer, 0, 1000000);
commandcsocket->read(databuffer, 1000000, false);
strData.append(databuffer);
commandcsocket->canRead(&bIsDataReadable, 0.3f);
}
}

resultString = strData;

Expand All @@ -521,7 +521,7 @@ int submitCommand(csocket* commandcsocket, std::string& strAuthorizationToken, s
}
else if(strCommand == "get_config" || strCommand == "get_config_raw")
{
commandcsocket->canRead(&bIsDataReadable, 0.1);
commandcsocket->canRead(&bIsDataReadable, 0.3f);

#ifndef WIN32
bIsDataReadable = true;
Expand All @@ -532,7 +532,7 @@ int submitCommand(csocket* commandcsocket, std::string& strAuthorizationToken, s
memset(databuffer, 0, 1000000);
commandcsocket->read(databuffer, 1000000, false);
strData.append(databuffer);
commandcsocket->canRead(&bIsDataReadable, 0.1);
commandcsocket->canRead(&bIsDataReadable, 0.3f);
}


Expand Down
5 changes: 3 additions & 2 deletions csocket.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "csocket.h"


#ifdef WIN32
#include <io.h>
#else
Expand Down Expand Up @@ -206,11 +207,12 @@ int csocket::canRead( bool* readyToRead, float waitTime )
(waitTime - (float)timeout.tv_sec));
}


#ifdef WIN32
nfds = m_socket+1;
#endif
int n = select(nfds, &fds, NULL, NULL, &timeout);

int n = select(nfds, &fds, NULL, NULL, &timeout);
if ( n < 0 )
{
m_socketState = ERRORED;
Expand All @@ -220,7 +222,6 @@ int csocket::canRead( bool* readyToRead, float waitTime )
if (n == 1)
{
*readyToRead = true;

return SUCCESS;
}

Expand Down

0 comments on commit 946148d

Please sign in to comment.