[thrift] add setTcp{Send,Recv}Buffer to C++ TSocketServer
Summary: needs moar BDPs
Reviewed By: mcslee
Test Plan: now using in our service
Revert Plan: ok
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665579 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TServerSocket.cpp b/lib/cpp/src/transport/TServerSocket.cpp
index 69d35bf..38ca363 100644
--- a/lib/cpp/src/transport/TServerSocket.cpp
+++ b/lib/cpp/src/transport/TServerSocket.cpp
@@ -30,6 +30,8 @@
recvTimeout_(0),
retryLimit_(0),
retryDelay_(0),
+ tcpSendBuffer_(0),
+ tcpRecvBuffer_(0),
intSock1_(-1),
intSock2_(-1) {}
@@ -41,6 +43,8 @@
recvTimeout_(recvTimeout),
retryLimit_(0),
retryDelay_(0),
+ tcpSendBuffer_(0),
+ tcpRecvBuffer_(0),
intSock1_(-1),
intSock2_(-1) {}
@@ -64,6 +68,14 @@
retryDelay_ = retryDelay;
}
+void TServerSocket::setTcpSendBuffer(int tcpSendBuffer) {
+ tcpSendBuffer_ = tcpSendBuffer;
+}
+
+void TServerSocket::setTcpRecvBuffer(int tcpRecvBuffer) {
+ tcpRecvBuffer_ = tcpRecvBuffer;
+}
+
void TServerSocket::listen() {
int sv[2];
if (-1 == socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
@@ -115,6 +127,25 @@
throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_REUSEADDR");
}
+ // Set TCP buffer sizes
+ if (tcpSendBuffer_ > 0) {
+ if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_SNDBUF,
+ &tcpSendBuffer_, sizeof(tcpSendBuffer_))) {
+ GlobalOutput("TServerSocket::listen() SO_SNDBUF");
+ close();
+ throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_SNDBUF");
+ }
+ }
+
+ if (tcpRecvBuffer_ > 0) {
+ if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_RCVBUF,
+ &tcpRecvBuffer_, sizeof(tcpRecvBuffer_))) {
+ GlobalOutput("TServerSocket::listen() SO_RCVBUF");
+ close();
+ throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_RCVBUF");
+ }
+ }
+
// Defer accept
#ifdef TCP_DEFER_ACCEPT
if (-1 == setsockopt(serverSocket_, SOL_SOCKET, TCP_DEFER_ACCEPT,
diff --git a/lib/cpp/src/transport/TServerSocket.h b/lib/cpp/src/transport/TServerSocket.h
index 213d9d4..b6bafa0 100644
--- a/lib/cpp/src/transport/TServerSocket.h
+++ b/lib/cpp/src/transport/TServerSocket.h
@@ -33,6 +33,9 @@
void setRetryLimit(int retryLimit);
void setRetryDelay(int retryDelay);
+ void setTcpSendBuffer(int tcpSendBuffer);
+ void setTcpRecvBuffer(int tcpRecvBuffer);
+
void listen();
void close();
@@ -49,6 +52,8 @@
int recvTimeout_;
int retryLimit_;
int retryDelay_;
+ int tcpSendBuffer_;
+ int tcpRecvBuffer_;
int intSock1_;
int intSock2_;