Skip to content

Commit 843998c

Browse files
committed
use fixed socket options
1 parent ff5f7fa commit 843998c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

include/DMDUtil/DMD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <winsock2.h> // Windows byte-order functions
2020
#else
2121
#include <arpa/inet.h> // Linux/macOS byte-order functions
22+
#include <netinet/tcp.h>
2223
#endif
2324

2425
#include <atomic>

src/DMD.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,18 @@ class DMDServerConnector
5353
static DMDServerConnector* Create(const char* pAddress, int port)
5454
{
5555
sockpp::tcp_connector* pConnector = new sockpp::tcp_connector({pAddress, (in_port_t)port});
56-
return pConnector ? new DMDServerConnector(pConnector) : nullptr;
56+
if (pConnector)
57+
{
58+
int flag = 1;
59+
int mss = 1200; // Conservative size
60+
int bufsize = 65536;
61+
pConnector->set_option(IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
62+
pConnector->set_option(IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss));
63+
pConnector->set_option(SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize));
64+
pConnector->set_option(SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize));
65+
return new DMDServerConnector(pConnector);
66+
}
67+
return nullptr;
5768
}
5869

5970
ssize_t Write(const void* buf, size_t size) { return m_pConnector->write_n(buf, size); }

src/dmdServer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <winsock2.h> // Windows byte-order functions
33
#else
44
#include <arpa/inet.h> // Linux/macOS byte-order functions
5+
#include <netinet/tcp.h>
56
#endif
67

78
#include <algorithm>
@@ -367,6 +368,14 @@ int main(int argc, char* argv[])
367368
}
368369
else
369370
{
371+
int flag = 1;
372+
int mss = 1200; // Conservative size
373+
int bufsize = 65536;
374+
sock.set_option(IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
375+
sock.set_option(IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss));
376+
sock.set_option(SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize));
377+
sock.set_option(SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize));
378+
370379
threadMutex.lock();
371380
currentThreadId = ++threadId;
372381
threads.push_back(currentThreadId);

0 commit comments

Comments
 (0)