mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-31 01:24:19 +02:00
Performance improvements for sockets.
This commit is contained in:
parent
d2332c8fd4
commit
e2253b8624
@ -40,7 +40,7 @@ JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
|||||||
*/
|
*/
|
||||||
void JsonRpcClient::SendMessage(const MessagePart& message)
|
void JsonRpcClient::SendMessage(const MessagePart& message)
|
||||||
{
|
{
|
||||||
Netstring::WriteStringToFIFO(GetSendQueue(), message.ToJsonString());
|
Netstring::WriteStringToSocket(GetSelf(), message.ToJsonString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,7 @@ void JsonRpcClient::DataAvailableHandler(void)
|
|||||||
string jsonString;
|
string jsonString;
|
||||||
MessagePart message;
|
MessagePart message;
|
||||||
|
|
||||||
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
|
if (!Netstring::ReadStringFromSocket(GetSelf(), &jsonString))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
message = MessagePart(jsonString);
|
message = MessagePart(jsonString);
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads data from a FIFO in netstring format.
|
* Reads data from a TCP client in netstring format.
|
||||||
*
|
*
|
||||||
* @param fifo The FIFO to read from.
|
* @param fifo The FIFO to read from.
|
||||||
* @param[out] str The string that has been read from the FIFO.
|
* @param[out] str The string that has been read from the FIFO.
|
||||||
@ -30,8 +30,9 @@ using namespace icinga;
|
|||||||
* @exception InvalidNetstringException The input stream is invalid.
|
* @exception InvalidNetstringException The input stream is invalid.
|
||||||
* @see https://github.com/PeterScott/netstring-c/blob/master/netstring.c
|
* @see https://github.com/PeterScott/netstring-c/blob/master/netstring.c
|
||||||
*/
|
*/
|
||||||
bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str)
|
bool Netstring::ReadStringFromSocket(const TcpClient::Ptr& client, string *str)
|
||||||
{
|
{
|
||||||
|
FIFO::Ptr fifo = client->GetRecvQueue();
|
||||||
size_t buffer_length = fifo->GetSize();
|
size_t buffer_length = fifo->GetSize();
|
||||||
char *buffer = (char *)fifo->GetReadBuffer();
|
char *buffer = (char *)fifo->GetReadBuffer();
|
||||||
|
|
||||||
@ -75,13 +76,15 @@ bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes data into a FIFO using the netstring format.
|
* Writes data into a TCP client's send buffer using the netstring format.
|
||||||
*
|
*
|
||||||
* @param fifo The FIFO.
|
* @param fifo The FIFO.
|
||||||
* @param str The string that is to be written.
|
* @param str The string that is to be written.
|
||||||
*/
|
*/
|
||||||
void Netstring::WriteStringToFIFO(FIFO::Ptr fifo, const string& str)
|
void Netstring::WriteStringToSocket(const TcpClient::Ptr& client, const string& str)
|
||||||
{
|
{
|
||||||
|
FIFO::Ptr fifo = client->GetSendQueue();
|
||||||
|
|
||||||
stringstream prefixbuf;
|
stringstream prefixbuf;
|
||||||
prefixbuf << str.size() << ":";
|
prefixbuf << str.size() << ":";
|
||||||
|
|
||||||
@ -90,4 +93,6 @@ void Netstring::WriteStringToFIFO(FIFO::Ptr fifo, const string& str)
|
|||||||
fifo->Write(str.c_str(), str.size());
|
fifo->Write(str.c_str(), str.size());
|
||||||
|
|
||||||
fifo->Write(",", 1);
|
fifo->Write(",", 1);
|
||||||
|
|
||||||
|
client->Flush();
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,8 @@ namespace icinga
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when an invalid netstring was encountered while reading from a FIFO.
|
* Thrown when an invalid netstring was encountered while reading from a
|
||||||
|
* TCP client.
|
||||||
*
|
*
|
||||||
* @ingroup jsonrpc
|
* @ingroup jsonrpc
|
||||||
*/
|
*/
|
||||||
@ -40,8 +41,8 @@ DEFINE_EXCEPTION_CLASS(InvalidNetstringException);
|
|||||||
class I2_JSONRPC_API Netstring
|
class I2_JSONRPC_API Netstring
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool ReadStringFromFIFO(FIFO::Ptr fifo, string *message);
|
static bool ReadStringFromSocket(const TcpClient::Ptr& client, string *message);
|
||||||
static void WriteStringToFIFO(FIFO::Ptr fifo, const string& message);
|
static void WriteStringToSocket(const TcpClient::Ptr& client, const string& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Netstring(void);
|
Netstring(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user