summaryrefslogtreecommitdiff
path: root/tools/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/socket.c')
-rw-r--r--tools/socket.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/tools/socket.c b/tools/socket.c
index 8bb7359..5e5c505 100644
--- a/tools/socket.c
+++ b/tools/socket.c
@@ -8,7 +8,8 @@
#include <errno.h>
#include <fcntl.h>
-#define UDP_TX_BUF_SIZE ((188*7+3)*20)
+#define UDP_TX_BUF_SIZE (188*348)
+//#define TCP_TX_BUF_SIZE (1024 * 30)
cTBSocket::cTBSocket(int Type) {
memset(&m_LocalAddr, 0, sizeof(m_LocalAddr));
@@ -21,7 +22,7 @@ cTBSocket::~cTBSocket() {
}
bool cTBSocket::OpenUDP(const std::string &Host, unsigned int Port) {
- int socket, tmp;
+ int socket;
struct sockaddr_in my_addr;
if (IsOpen()) Close();
@@ -36,16 +37,18 @@ bool cTBSocket::OpenUDP(const std::string &Host, unsigned int Port) {
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(Port);
my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
-
-/* tmp = 1;
- if (setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char*)&tmp, sizeof(tmp)) < 0)
- goto closefd;*/
-
+
/* limit the tx buf size to limit latency */
- tmp = UDP_TX_BUF_SIZE;
+#ifdef UDP_TX_BUF_SIZE
+ int tmp = UDP_TX_BUF_SIZE;
if (setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (char*)&tmp, sizeof(tmp)) < 0)
goto closefd;
+#endif
+/* tmp = 1;
+ if (setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char*)&tmp, sizeof(tmp)) < 0)
+ goto closefd;*/
+
/* the bind is needed to give a port to the socket now */
/* if (bind(socket,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0)
goto closefd;*/
@@ -108,6 +111,13 @@ bool cTBSocket::Listen(const std::string &Ip, unsigned int Port, int BackLog) {
if ((socket = ::socket(PF_INET, m_Type, IPPROTO_IP)) == -1)
return false;
+ /* limit the tx buf size to limit latency */
+#ifdef TCP_TX_BUF_SIZE
+ int tmp = TCP_TX_BUF_SIZE;
+ if (setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (char*)&tmp, sizeof(tmp)) < 0)
+ goto closefd;
+#endif
+
val = 1;
if (::setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) == -1)
goto closefd; //return false;