Created
November 17, 2017 13:04
-
-
Save High-Hill/a85b96a16cf8947d22184816edf1c05b to your computer and use it in GitHub Desktop.
TCP_NODELAYを1にするプログラム.できているのかは謎い.
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 <stdio.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <netinet/tcp.h> | |
int main() { | |
int sock; | |
int val, setval; | |
struct sockaddr_in addr; | |
char buf[2048]; | |
int len = sizeof(val); | |
int result; | |
setval = 1; | |
sock = socket(AF_INET, SOCK_STREAM, 0); | |
if(getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &val, &len) == -1 ){ | |
perror("failed to getsockopt"); | |
} | |
printf("Current TCP_NODELAY: %d\n",val); | |
val = 1; | |
if(setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &val, len) == -1 ){ | |
perror("failed to setsockopt"); | |
} | |
printf("Current TCP_NODELAY: %d\n",val); | |
close(sock); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I referred to the following URL to write this code. Thanks a lot.
下記のURLを参考させていただきました,ありがとうございます.
http://kazmax.zpp.jp/cmd/t/tcp.7.html
http://kazmax.zpp.jp/cmd/g/getsockopt.2.html
http://nxmnpg.lemoda.net/ja/2/setsockopt
http://d.hatena.ne.jp/odawara/20071116/1195190287
http://d.hatena.ne.jp/iww/20100409/1270823223
https://stackoverflow.com/questions/1045530/how-to-set-tcp-nodelay-on-bsd-socket-on-solaris
http://d.hatena.ne.jp/sleepy_yoshi/20111113/p1