Merge pull request #140 from hussainnaqvee/patch-1
[awesomized/libmemcached] / test / timeout.c
1 #include "mem_config.h"
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <memory.h>
6 #if HAVE_ARPA_INET_H
7 # include <arpa/inet.h>
8 #endif
9 #if HAVE_SYS_SOCKET_H
10 # include <sys/socket.h>
11 #endif
12 #if HAVE_NETINET_IN_H
13 # include <netinet/in.h>
14 #endif
15
16 // $0 -u nobody -p <port>
17 int main(int argc, char **argv) {
18 short port = argc == 5 ? atoi(argv[4]) : 11211;
19 struct sockaddr_in servaddr;
20 memset(&servaddr, 0, sizeof(struct sockaddr_in));
21
22 servaddr.sin_family = AF_INET;
23 servaddr.sin_addr.s_addr = htons(INADDR_ANY);
24 servaddr.sin_port = htons(port);
25
26 int listen_fd = socket(AF_INET, SOCK_STREAM, 0);
27 bind(listen_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));
28 listen(listen_fd, 10);
29 printf("Listening (%d) on port %d\n", listen_fd, port);
30
31 int comm_fd = accept(listen_fd, NULL, NULL);
32 printf("Connection (%d) accepted, now do nothing...\n", comm_fd);
33
34 pause();
35 }