Disable logging. Version uses TCP_CORK option
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "SynchronousSocket.h"
|
||||
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
@@ -162,8 +163,18 @@ void SynchronousSocket::SendMessage(const string & m)
|
||||
{
|
||||
len_s += (char)((len >> (8 * i)) & 0xFF);
|
||||
}
|
||||
int result = setsockopt(socket, IPPROTO_TCP, TCP_CORK, (char*)&YES, sizeof(int));
|
||||
if (result < 0)
|
||||
{
|
||||
throw (string)("Error setting socket option");
|
||||
}
|
||||
Send(len_s);
|
||||
Send(m);
|
||||
result = setsockopt(socket, IPPROTO_TCP, TCP_CORK, (char*)&NO, sizeof(int));
|
||||
if (result < 0)
|
||||
{
|
||||
throw (string)("Error setting socket option");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ class SynchronousSocket
|
||||
private:
|
||||
const int TIMEOUT = 10; // in seconds
|
||||
const int BUFFER_SIZE = 1048576;
|
||||
const int YES = 1;
|
||||
const int NO = 0;
|
||||
protected:
|
||||
// собственно сокет
|
||||
int socket;
|
||||
|
||||
@@ -6,6 +6,7 @@ using namespace std;
|
||||
|
||||
void LogTime(const string &message)
|
||||
{
|
||||
#ifdef LOGGING_ENABLED
|
||||
static auto start = chrono::high_resolution_clock::now();
|
||||
static auto prev = start;
|
||||
auto current = chrono::high_resolution_clock::now();
|
||||
@@ -13,4 +14,5 @@ void LogTime(const string &message)
|
||||
auto nsec_prev = chrono::duration_cast<chrono::nanoseconds>(current - prev).count();
|
||||
cerr << (nsec / 1000000.f) << " " << message << " delta " << (nsec_prev / 1000000.0f) << "\n";
|
||||
prev = current;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -97,12 +97,6 @@ void* IPSocketThread(void* arg)
|
||||
cerr << "Error accepting connection, errno = " << errno << "\n";
|
||||
continue;
|
||||
}
|
||||
int yes = 1;
|
||||
int result = setsockopt(recsock, IPPROTO_TCP, TCP_NODELAY, (char*)&yes, sizeof(int));
|
||||
if (result < 0)
|
||||
{
|
||||
cerr << "Error setting socket option, errno = " << errno << "\n";
|
||||
}
|
||||
cout << "Accepted connection from " << inet_ntoa(peeraddr.sin_addr) << ":" << ntohs(peeraddr.sin_port) << "\n";
|
||||
CreateThread(&ProcessRequests, &recsock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user