Last active
April 11, 2017 09:26
-
-
Save SLonger/b9e7493665e7a24a26080ba23b895f6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the function the follow utility: | |
1. inquire socket buffer before set socket buffer | |
2. set socket buffer | |
3. get the info after set buffer | |
conclusion: a. the get value of socket buffer is double of the set value. | |
b. if set value > the max of os max value , the value we get is double *maxsocketbuffer of os | |
for example | |
if max of os socket buffer is 200000 bytes and we set value is 3000000 , | |
then we get the value is 400000 not 600000. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/socket.h> | |
#include <stdio.h> | |
int main(int argc, char **argv) | |
{ | |
int sockfd, sendbuff; | |
socklen_t optlen; | |
sockfd = socket(AF_INET, SOCK_DGRAM, 0); | |
if(sockfd == -1) | |
printf("Error"); | |
int res = 0; | |
// Get buffer size | |
optlen = sizeof(sendbuff); | |
res = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sendbuff, &optlen); | |
if(res == -1) | |
printf("Error getsockopt one"); | |
else | |
printf("send buffer size = %d\n", sendbuff); | |
// Set buffer size | |
sendbuff = 98304; | |
printf("sets the send buffer to %d\n", sendbuff); | |
res = setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sendbuff, sizeof(sendbuff)); | |
if(res == -1) | |
printf("Error setsockopt"); | |
// Get buffer size | |
optlen = sizeof(sendbuff); | |
res = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sendbuff, &optlen); | |
if(res == -1) | |
printf("Error getsockopt two"); | |
else | |
printf("send buffer size = %d\n", sendbuff); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment