mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2026-03-22 04:50:04 +00:00
Set TCP_NODELAY on clients
This commit is contained in:
@@ -365,14 +365,8 @@ void CNServer::init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attach socket to the port
|
// attach socket to the port
|
||||||
int opt = 1;
|
if (!setSocketOption(sock, SOL_SOCKET, SO_REUSEADDR, 1)) {
|
||||||
#ifdef _WIN32
|
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(opt)) != 0) {
|
|
||||||
#else
|
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) != 0) {
|
|
||||||
#endif
|
|
||||||
std::cerr << "[FATAL] OpenFusion: setsockopt failed" << std::endl;
|
std::cerr << "[FATAL] OpenFusion: setsockopt failed" << std::endl;
|
||||||
printSocketError("setsockopt");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
address.sin_family = AF_INET;
|
address.sin_family = AF_INET;
|
||||||
@@ -414,6 +408,18 @@ void CNServer::init() {
|
|||||||
CNServer::CNServer() {};
|
CNServer::CNServer() {};
|
||||||
CNServer::CNServer(uint16_t p): port(p) {}
|
CNServer::CNServer(uint16_t p): port(p) {}
|
||||||
|
|
||||||
|
bool CNServer::setSocketOption(SOCKET s, int level, int option, int value) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (setsockopt(s, level, option, (const char*)&value, sizeof(value)) != 0) {
|
||||||
|
#else
|
||||||
|
if (setsockopt(s, level, option, &value, sizeof(value)) != 0) {
|
||||||
|
#endif
|
||||||
|
printSocketError("setsockopt");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CNServer::addPollFD(SOCKET s) {
|
void CNServer::addPollFD(SOCKET s) {
|
||||||
fds.push_back({s, POLLIN});
|
fds.push_back({s, POLLIN});
|
||||||
}
|
}
|
||||||
@@ -462,6 +468,9 @@ void CNServer::start() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!setSocketOption(newConnectionSocket, IPPROTO_TCP, TCP_NODELAY, 1))
|
||||||
|
std::cout << "[WARN] OpenFusion: failed to set TCP_NODELAY on new connection" << std::endl;
|
||||||
|
|
||||||
if (!setSockNonblocking(sock, newConnectionSocket))
|
if (!setSockNonblocking(sock, newConnectionSocket))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
// posix platform
|
// posix platform
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -239,6 +240,7 @@ protected:
|
|||||||
|
|
||||||
bool active = true;
|
bool active = true;
|
||||||
|
|
||||||
|
bool setSocketOption(SOCKET s, int level, int option, int value);
|
||||||
void addPollFD(SOCKET s);
|
void addPollFD(SOCKET s);
|
||||||
void removePollFD(int i);
|
void removePollFD(int i);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user