Created
December 20, 2016 23:39
-
-
Save cablehead/9e49d968b33078faa26c2c1b5f254dca to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <assert.h> | |
#include <pthread.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include <netdb.h> | |
#include <string.h> | |
#include <errno.h> | |
int main() { | |
int i, rc, no, flags; | |
char node[] = "127.0.0.1"; | |
char service[] = "8080"; | |
struct addrinfo hints; | |
for (i=0; i<=10*1000; i++) { | |
memset (&hints, 0, sizeof (hints)); | |
hints.ai_family = AF_INET; | |
hints.ai_socktype = SOCK_STREAM; | |
struct addrinfo *info; | |
rc = getaddrinfo (node, service, &hints, &info); | |
assert(rc == 0); | |
assert(info->ai_family == AF_INET); | |
no = socket(info->ai_family, info->ai_socktype, info->ai_protocol); | |
assert(no > 0); | |
/* | |
flags = fcntl(no, F_GETFL); | |
flags |= O_NONBLOCK; | |
rc = fcntl(no, F_SETFL, flags); | |
assert(rc == 0); | |
*/ | |
rc = connect(no, info->ai_addr, info->ai_addrlen); | |
if(rc != 0) printf("RC .connect=%d %d\n", rc, i); | |
close(no); | |
freeaddrinfo(info); | |
if (rc != 0) break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment