Skip to content

Commit

Permalink
Fixed: TCP Server should also be able to clump batches
Browse files Browse the repository at this point in the history
  • Loading branch information
topfs2 committed Jan 26, 2011
1 parent c7a66f9 commit 605dbbc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
41 changes: 30 additions & 11 deletions xbmc/network/TCPServer.cpp
Expand Up @@ -247,6 +247,8 @@ CTCPServer::CTCPClient::CTCPClient()
m_socket = -1;
m_beginBrackets = 0;
m_endBrackets = 0;
m_beginChar = 0;
m_endChar = 0;

m_addrlen = sizeof(struct sockaddr);
}
Expand Down Expand Up @@ -283,18 +285,33 @@ void CTCPServer::CTCPClient::PushBuffer(CTCPServer *host, const char *buffer, in
for (int i = 0; i < length; i++)
{
char c = buffer[i];
m_buffer.push_back(c);
if (c == '{')
m_beginBrackets++;
else if (c == '}')
m_endBrackets++;
if (m_beginBrackets > 0 && m_endBrackets > 0 && m_beginBrackets == m_endBrackets)

if (m_beginChar == 0 && c == '{')
{
m_beginChar = '{';
m_endChar = '}';
}
else if (m_beginChar == 0 && c == '[')
{
m_beginChar = '[';
m_endChar = ']';
}

if (m_beginChar != 0)
{
std::string line = CJSONRPC::MethodCall(m_buffer, host, this);
CSingleLock lock (m_critSection);
send(m_socket, line.c_str(), line.size(), 0);
m_beginBrackets = m_endBrackets = 0;
m_buffer.clear();
m_buffer.push_back(c);
if (c == m_beginChar)
m_beginBrackets++;
else if (c == m_endChar)
m_endBrackets++;
if (m_beginBrackets > 0 && m_endBrackets > 0 && m_beginBrackets == m_endBrackets)
{
std::string line = CJSONRPC::MethodCall(m_buffer, host, this);
CSingleLock lock (m_critSection);
send(m_socket, line.c_str(), line.size(), 0);
m_beginChar = m_beginBrackets = m_endBrackets = 0;
m_buffer.clear();
}
}
}
}
Expand All @@ -318,6 +335,8 @@ void CTCPServer::CTCPClient::Copy(const CTCPClient& client)
m_announcementflags = client.m_announcementflags;
m_beginBrackets = client.m_beginBrackets;
m_endBrackets = client.m_endBrackets;
m_beginChar = client.m_beginChar;
m_endChar = client.m_endChar;
m_buffer = client.m_buffer;
}

1 change: 1 addition & 0 deletions xbmc/network/TCPServer.h
Expand Up @@ -57,6 +57,7 @@ namespace JSONRPC
void Copy(const CTCPClient& client);
int m_announcementflags;
int m_beginBrackets, m_endBrackets;
char m_beginChar, m_endChar;
std::string m_buffer;
};

Expand Down

0 comments on commit 605dbbc

Please sign in to comment.