Skip to content

Instantly share code, notes, and snippets.

@High-Hill
Created November 17, 2017 13:04
Show Gist options
  • Save High-Hill/a85b96a16cf8947d22184816edf1c05b to your computer and use it in GitHub Desktop.
Save High-Hill/a85b96a16cf8947d22184816edf1c05b to your computer and use it in GitHub Desktop.
TCP_NODELAYを1にするプログラム.できているのかは謎い.
#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