Skip to content

Commit

Permalink
Minimal socket buffer size set
Browse files Browse the repository at this point in the history
  • Loading branch information
ondracek-lukas committed Jan 19, 2021
1 parent 6e1c1c9 commit 8e3c71a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.h
Expand Up @@ -3,13 +3,15 @@
#define _GNU_SOURCE

#define PROT_VERSION 4
#define APP_VERSION 0.9
#define APP_VERSION 1.0
#define UDP_PORT 64199
#define NAME_LEN 10
#define MAX_CLIENTS 100
#define BLOCKS_PER_STAT 50
#define BLOCKS_PER_SRV_STAT 10000 // should be divisible by BLOCKS_PER_STAT

#define CLIENT_SOCK_BUF_SIZE 100000 // B

#define SAMPLE_RATE 48000
#define MONO_BLOCK_SIZE 128 // 2.667 ms
#define BUFFER_BLOCKS 4096 // 10.92 s, ~1 MB mono, ~2 MB stereo
Expand Down
16 changes: 16 additions & 0 deletions net.h
Expand Up @@ -187,6 +187,22 @@ int netOpenConn(char *addr, char *port) {
return -1;
}

{
uint32_t val;
socklen_t valsize = sizeof(val);
getsockopt(sfd, SOL_SOCKET, SO_SNDBUF, (char *)&val, &valsize);
if (val < CLIENT_SOCK_BUF_SIZE) {
val = CLIENT_SOCK_BUF_SIZE;
setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, (char *)&val, sizeof(val));
}
valsize = sizeof(val);
getsockopt(sfd, SOL_SOCKET, SO_RCVBUF, (char *)&val, &valsize);
if (val < CLIENT_SOCK_BUF_SIZE) {
val = CLIENT_SOCK_BUF_SIZE;
setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, (char *)&val, sizeof(val));
}
}

#ifdef __WIN32__
DWORD tv = 1000;
#else
Expand Down

0 comments on commit 8e3c71a

Please sign in to comment.