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

Function conn_poll_for_conn

dpdk/examples/pipeline/conn.c:152–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152int
153conn_poll_for_conn(struct conn *conn)
154{
155 struct sockaddr_in client_address;
156 struct epoll_event event;
157 socklen_t client_address_length;
158 int fd_client, status;
159
160 /* Check input arguments */
161 if (conn == NULL)
162 return -1;
163
164 /* Server socket */
165 client_address_length = sizeof(client_address);
166 fd_client = accept4(conn->fd_server,
167 (struct sockaddr *) &client_address,
168 &client_address_length,
169 SOCK_NONBLOCK);
170 if (fd_client == -1) {
171 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
172 return 0;
173
174 return -1;
175 }
176
177 /* Client group */
178 event.events = EPOLLIN | EPOLLRDHUP | EPOLLHUP;
179 event.data.fd = fd_client;
180
181 status = epoll_ctl(conn->fd_client_group,
182 EPOLL_CTL_ADD,
183 fd_client,
184 &event);
185 if (status == -1) {
186 close(fd_client);
187 return -1;
188 }
189
190 /* Client */
191 status = write(fd_client,
192 conn->welcome,
193 strlen(conn->welcome));
194 if (status == -1) {
195 close(fd_client);
196 return -1;
197 }
198
199 status = write(fd_client,
200 conn->prompt,
201 strlen(conn->prompt));
202 if (status == -1) {
203 close(fd_client);
204 return -1;
205 }
206
207 return 0;
208}
209

Callers 1

mainFunction · 0.70

Calls 4

epoll_ctlFunction · 0.85
accept4Function · 0.50
closeFunction · 0.50
writeFunction · 0.50

Tested by

no test coverage detected