Skip to content

Commit

Permalink
Interlieved data fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sebk2307 committed May 12, 2015
1 parent 0dbd18b commit 85bf698
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
64 changes: 49 additions & 15 deletions DXMPP/Network/AsyncTCPXMLClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ else std::cout
int NrSubRootTagNamesFound;

ExpatStructure( AsyncTCPXMLClient *Sender, XML_Parser Parser)
:
Sender(Sender),
:
Sender(Sender),
Parser(Parser)
{
RootTagName = "";
Expand Down Expand Up @@ -198,22 +198,22 @@ else std::cout
CurrentConnectionState = ConnectionState::Error;
ErrorCallback();
}

void SAXEndElementHandler(void* data, const XML_Char* el)
{
ExpatStructure *ES = static_cast<ExpatStructure*>(data);
if( ES->EndPosition > 0 )
return;

string StrEl(el);

if(StrEl == string("</stream:stream>"))
{
std::cerr << "Received end of stream" << std::endl;
ES->Sender->SignalError();
return;
}

if(StrEl != ES->RootTagName )
return;

Expand Down Expand Up @@ -306,16 +306,23 @@ else std::cout
}



void AsyncTCPXMLClient::WriteTextToSocket(const string &Data)
void AsyncTCPXMLClient::FlushOutgoingDataUnsafe()
{
if( CurrentConnectionState != ConnectionState::Connected )
if(OutgoingData.empty())
{
Flushing = false;
return;
}

boost::system::error_code ec;
Flushing = true;

std::shared_ptr<std::string> SharedData (new std::string(Data));
std::shared_ptr<std::string> SharedData = OutgoingData.front();
OutgoingData.pop();

if(OutgoingData.empty())
Flushing = false;

boost::system::error_code ec;
if(SSLConnection)
{
SynchronizationStrand.post([&,SharedData, this]
Expand All @@ -342,13 +349,9 @@ else std::cout
ErrorCallback();
}*/


}
else
{

std::shared_ptr<std::string> SharedData = std::make_shared<std::string>(Data);
boost::asio::async_write(*tcp_socket, boost::asio::buffer(*SharedData),
SynchronizationStrand.wrap(
boost::bind(&AsyncTCPXMLClient::HandleWrite,
Expand All @@ -375,7 +378,36 @@ else std::cout
LastWrite = boost::posix_time::microsec_clock::universal_time();

DebugOut(DebugOutputTreshold::Debug) << "Write text to socket:" <<
std::endl << Data << std::endl;
std::endl << "+++" << std::endl << *SharedData << std::endl << " --- " << std::endl;
}

void AsyncTCPXMLClient::FlushOutgoingData()
{
boost::unique_lock<boost::shared_mutex> WriteLock(OutgoingDataMutex);

if(Flushing)
return;

FlushOutgoingDataUnsafe();
}


void AsyncTCPXMLClient::WriteTextToSocket(const string &Data)
{
if( CurrentConnectionState != ConnectionState::Connected )
return;

{
boost::unique_lock<boost::shared_mutex> WriteLock(OutgoingDataMutex);
std::shared_ptr<std::string> SharedData (new std::string(Data));
OutgoingData.push( SharedData );

if(!Flushing)
FlushOutgoingDataUnsafe(); /* we have lock */
}


return;
}

bool AsyncTCPXMLClient::EnsureTCPKeepAlive()
Expand Down Expand Up @@ -531,6 +563,8 @@ else std::cout
return;
}

FlushOutgoingData();

//DebugOut(DebugOutputTreshold::Debug) << "Got ack for " << *Data << std::endl;
}

Expand Down
11 changes: 9 additions & 2 deletions DXMPP/Network/AsyncTCPXMLClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ namespace DXMPP

boost::shared_mutex IncomingDocumentsMutex;
std::queue<pugi::xml_document*> IncomingDocuments;



std::queue<std::shared_ptr<std::string>> OutgoingData;
boost::shared_mutex OutgoingDataMutex;
bool Flushing;

void FlushOutgoingDataUnsafe();

public:

void FlushOutgoingData();

void SignalError();
std::stringstream *ReadDataStream;
char * ReadDataBuffer;
Expand Down Expand Up @@ -164,6 +170,7 @@ namespace DXMPP
this->io_service = IOService;
this->Hostname = Hostname;
this->Portnumber = Portnumber;
Flushing = false;
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/EchoBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int main(int, const char **)
while(!Handler.Quit)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
}
}

return 0;
}
Empty file modified pugixml/CMakeLists.txt
100644 → 100755
Empty file.
Empty file modified pugixml/readme.txt
100644 → 100755
Empty file.

0 comments on commit 85bf698

Please sign in to comment.