mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-29 08:56:18 +02:00
timeout
git-svn-id: svn://elaine/murooma/trunk@314 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
b06a685c0c
commit
d8a02e5e73
2 changed files with 13 additions and 3 deletions
|
@ -10,7 +10,7 @@
|
|||
using namespace std;
|
||||
|
||||
|
||||
ClientConnection::ClientConnection(MessageReceiver* _receiver, const std::string& _ip, size_t _port) : active_(false), connected_(false), messageReceiver(_receiver), reqId(1), ip(_ip), port(_port), readerThread(NULL)
|
||||
ClientConnection::ClientConnection(MessageReceiver* _receiver, const std::string& _ip, size_t _port) : active_(false), connected_(false), messageReceiver(_receiver), reqId(1), ip(_ip), port(_port), readerThread(NULL), timeouts(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -113,9 +113,10 @@ bool ClientConnection::send(BaseMessage* message)
|
|||
shared_ptr<SerializedMessage> ClientConnection::sendRequest(BaseMessage* message, size_t timeout)
|
||||
{
|
||||
shared_ptr<SerializedMessage> response(NULL);
|
||||
if (++reqId == 10000)
|
||||
if (++reqId == 100)
|
||||
reqId = 1;
|
||||
message->id = reqId;
|
||||
cout << "Req: " << reqId << "\n";
|
||||
shared_ptr<PendingRequest> pendingRequest(new PendingRequest(reqId));
|
||||
|
||||
{
|
||||
|
@ -128,10 +129,18 @@ shared_ptr<SerializedMessage> ClientConnection::sendRequest(BaseMessage* message
|
|||
if (pendingRequest->cv.wait_for(lck,std::chrono::milliseconds(timeout)) == std::cv_status::no_timeout)
|
||||
{
|
||||
response = pendingRequest->response;
|
||||
timeouts = 0;
|
||||
cout << "Resp: " << pendingRequest->id << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "timeout while waiting for response to: " << reqId << "\n";
|
||||
++timeouts;
|
||||
cout << "timeout while waiting for response to: " << reqId << ", timeout " << timeouts << "\n";
|
||||
if (timeouts > 2*60)
|
||||
{
|
||||
std::exception e;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
|
|
|
@ -88,6 +88,7 @@ protected:
|
|||
std::string ip;
|
||||
size_t port;
|
||||
std::thread* readerThread;
|
||||
int timeouts;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue