blob: bd91271d2fa97dd979cbf960f58811b16131fe03 [file] [log] [blame]
Jens Wiklander02389a92016-12-16 11:13:38 +01001/*
2 * Copyright (c) 2016, Linaro Limited
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#ifndef XTEST_SOCK_SERVER_H
15#define XTEST_SOCK_SERVER_H
16
17#include <pthread.h>
18#include <stdbool.h>
19#include <sys/types.h>
20
21struct sock_server_bind {
22 int fd;
23 char host[255];
24 int port;
25};
26
27struct sock_server {
28 struct sock_server_bind *bind;
29 size_t num_binds;
30 int quit_fd;
31 int stop_fd;
32 pthread_t thr;
33 pthread_mutex_t mu;
34 bool error;
35 struct sock_io_cb *cb;
36};
37
38struct sock_io_cb {
39 bool (*accept)(void *ptr, int fd, short *events);
40 bool (*read)(void *ptr, int fd, short *events);
41 bool (*write)(void *ptr, int fd, short *events);
42 void *ptr;
43};
44
45bool sock_server_init_tcp(struct sock_server *sock_serv, struct sock_io_cb *cb);
46bool sock_server_init_udp(struct sock_server *sock_serv, struct sock_io_cb *cb);
47void sock_server_uninit(struct sock_server *sock_serv);
48void sock_server_lock(struct sock_server *sock_serv);
49void sock_server_unlock(struct sock_server *sock_serv);
50
51#endif /*XTEST_SOCK_SERVER_H*/