return rc;
}
-void TcpClient::Flush(void)
-{
- /* try to speculatively flush the buffer if there's a reasonable amount
- * of data, this may fail, e.g. when the socket cannot immediately
- * send this much data - the event loop will take care of this later on */
- if (GetSendQueue()->GetSize() > 128 * 1024)
- FlushSendQueue();
-}
-
/**
* Processes data that is available for this socket.
*/
FIFO::Ptr GetSendQueue(void);
FIFO::Ptr GetRecvQueue(void);
- void Flush(void);
-
virtual bool WantsToRead(void) const;
virtual bool WantsToWrite(void) const;
{
long wakeup = 30;
+ time_t st;
+ time(&st);
+
Timer::CollectionType::iterator prev, i;
for (i = Timers.begin(); i != Timers.end(); ) {
Timer::Ptr timer = i->lock();
assert(wakeup > 0);
+ time_t et;
+ time(&et);
+
+ stringstream msgbuf;
+ msgbuf << "Timers took " << et - st << " seconds";
+ Application::Log(LogDebug, "base", msgbuf.str());
+
return wakeup;
}
Application::Log(LogDebug, "delegation", "Trying to delegate service '" + service.GetName() + "'");
- GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, checker, request,
- boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _2, _5));
-}
-
-void DelegationComponent::AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut)
-{
- /* ignore the message if it's not from the designated checker for this service */
- if (sender && service.GetChecker() != sender->GetIdentity())
- return;
-
- if (timedOut) {
- Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' timed out.");
- service.SetChecker("");
- }
+ GetEndpointManager()->SendUnicastMessage(m_DelegationEndpoint, checker, request);
}
void DelegationComponent::ClearServices(const Endpoint::Ptr& checker)
void NewEndpointHandler(const Endpoint::Ptr& endpoint);
void SessionEstablishedHandler(const Endpoint::Ptr& endpoint);
- void AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
-
void DelegationTimerHandler(void);
vector<Endpoint::Ptr> GetCheckerCandidates(const Service& service) const;
*/
void JsonRpcClient::SendMessage(const MessagePart& message)
{
- Netstring::WriteStringToSocket(GetSelf(), message.ToJsonString());
+ Netstring::WriteStringToFIFO(GetSendQueue(), message.ToJsonString());
}
/**
string jsonString;
MessagePart message;
- if (!Netstring::ReadStringFromSocket(GetSelf(), &jsonString))
+ if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
return;
message = MessagePart(jsonString);
using namespace icinga;
/**
- * Reads data from a TCP client in netstring format.
+ * Reads data from a FIFO in netstring format.
*
* @param fifo The FIFO to read from.
* @param[out] str The string that has been read from the FIFO.
* @exception InvalidNetstringException The input stream is invalid.
* @see https://github.com/PeterScott/netstring-c/blob/master/netstring.c
*/
-bool Netstring::ReadStringFromSocket(const TcpClient::Ptr& client, string *str)
+bool Netstring::ReadStringFromFIFO(const FIFO::Ptr& fifo, string *str)
{
- FIFO::Ptr fifo = client->GetRecvQueue();
size_t buffer_length = fifo->GetSize();
char *buffer = (char *)fifo->GetReadBuffer();
}
/**
- * Writes data into a TCP client's send buffer using the netstring format.
+ * Writes data into a FIFO using the netstring format.
*
* @param fifo The FIFO.
* @param str The string that is to be written.
*/
-void Netstring::WriteStringToSocket(const TcpClient::Ptr& client, const string& str)
+void Netstring::WriteStringToFIFO(const FIFO::Ptr& fifo, const string& str)
{
- FIFO::Ptr fifo = client->GetSendQueue();
-
stringstream prefixbuf;
prefixbuf << str.size() << ":";
fifo->Write(str.c_str(), str.size());
fifo->Write(",", 1);
-
- client->Flush();
}
{
/**
- * Thrown when an invalid netstring was encountered while reading from a
- * TCP client.
+ * Thrown when an invalid netstring was encountered while reading from a FIFO.
*
* @ingroup jsonrpc
*/
class I2_JSONRPC_API Netstring
{
public:
- static bool ReadStringFromSocket(const TcpClient::Ptr& client, string *message);
- static void WriteStringToSocket(const TcpClient::Ptr& client, const string& message);
+ static bool ReadStringFromFIFO(const FIFO::Ptr& fifo, string *message);
+ static void WriteStringToFIFO(const FIFO::Ptr& fifo, const string& message);
private:
Netstring(void);