-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtcp_getsockopt.c
72 lines (63 loc) · 1.77 KB
/
mtcp_getsockopt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* =====================================================================================
*
* Filename: getopt.c
*
* Description:
*
* Version: 1.0
* Created: 07/27/2016 10:12:23 AM
* Revision: none
* Compiler: gcc
*
* Author: Titan Bao (), leightonbao@gmail.com
* Company: Superlink
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <mtcp_api.h>
int
main(int argc , char **argv)
{
int sock, rc;
socklen_t optlen;
struct sockaddr_in server;
unsigned char optval;
struct mtcp_conf mcfg;
mctx_t mctx;
mtcp_getconf(&mcfg);
mcfg.num_cores = 1;
mtcp_setconf(&mcfg);
/* initialize the mtcp context */
if (mtcp_init("mtcp.conf")) {
fprintf(stderr, "Failed to initialize mtcp\n");
exit(0);
}
mtcp_getconf(&mcfg);
mcfg.max_concurrency = mcfg.max_num_buffers = 500000;
mtcp_setconf(&mcfg);
mctx = mtcp_create_context(0);
/* create socket */
sock = mtcp_socket(mctx,AF_INET , SOCK_STREAM , 0);
if (sock == -1) {
printf("Could not create socket");
exit(EXIT_FAILURE);
}
server.sin_addr.s_addr = inet_addr("192.168.1.99");
server.sin_family = AF_INET;
server.sin_port = htons(80);
fprintf(stdout, "rc returns: %d, optval is: %d, optlen is: %d\n",
rc, optval, optlen);
/* Try connecting to an arbitrary closed port */
mtcp_connect(mctx,sock , (struct sockaddr *)&server , sizeof(server));
rc = mtcp_getsockopt(mctx,sock, SOL_SOCKET, SO_ERROR,(void *)&optval, &optlen);
//TRACE_CONFIG("rc returns: %d, optval is: %d, optlen is: %d.\n",rc, optval, optlen);
fprintf(stdout, "rc returns: %d, optval is: %d, optlen is: %d\n",
rc, optval, optlen);
while(1)
sleep(10);
return EXIT_SUCCESS;
}