MCPcopy Create free account
hub / github.com/F-Stack/f-stack / conn_init

Function conn_init

dpdk/examples/ip_pipeline/conn.c:37–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35};
36
37struct conn *
38conn_init(struct conn_params *p)
39{
40 struct sockaddr_in server_address;
41 struct conn *conn;
42 int fd_server, fd_client_group, status;
43
44 memset(&server_address, 0, sizeof(server_address));
45
46 /* Check input arguments */
47 if ((p == NULL) ||
48 (p->welcome == NULL) ||
49 (p->prompt == NULL) ||
50 (p->addr == NULL) ||
51 (p->buf_size == 0) ||
52 (p->msg_in_len_max == 0) ||
53 (p->msg_out_len_max == 0) ||
54 (p->msg_handle == NULL))
55 return NULL;
56
57 status = inet_aton(p->addr, &server_address.sin_addr);
58 if (status == 0)
59 return NULL;
60
61 /* Memory allocation */
62 conn = calloc(1, sizeof(struct conn));
63 if (conn == NULL)
64 return NULL;
65
66 conn->welcome = calloc(1, CONN_WELCOME_LEN_MAX + 1);
67 conn->prompt = calloc(1, CONN_PROMPT_LEN_MAX + 1);
68 conn->buf = calloc(1, p->buf_size);
69 conn->msg_in = calloc(1, p->msg_in_len_max + 1);
70 conn->msg_out = calloc(1, p->msg_out_len_max + 1);
71
72 if ((conn->welcome == NULL) ||
73 (conn->prompt == NULL) ||
74 (conn->buf == NULL) ||
75 (conn->msg_in == NULL) ||
76 (conn->msg_out == NULL)) {
77 conn_free(conn);
78 return NULL;
79 }
80
81 /* Server socket */
82 server_address.sin_family = AF_INET;
83 server_address.sin_port = htons(p->port);
84
85 fd_server = socket(AF_INET,
86 SOCK_STREAM | SOCK_NONBLOCK,
87 0);
88 if (fd_server == -1) {
89 conn_free(conn);
90 return NULL;
91 }
92
93 status = bind(fd_server,
94 (struct sockaddr *) &server_address,

Callers 1

mainFunction · 0.70

Calls 10

memsetFunction · 0.85
inet_atonFunction · 0.85
callocFunction · 0.85
epoll_createFunction · 0.85
strncpyFunction · 0.85
conn_freeFunction · 0.70
socketClass · 0.50
bindFunction · 0.50
closeFunction · 0.50
listenFunction · 0.50

Tested by

no test coverage detected