1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (c) 2016, Linaro Limited 4 */ 5 6 #ifndef XTEST_SOCK_SERVER_H 7 #define XTEST_SOCK_SERVER_H 8 9 #include <pthread.h> 10 #include <stdbool.h> 11 #include <sys/types.h> 12 13 struct sock_server_bind { 14 int fd; 15 char host[255]; 16 int port; 17 }; 18 19 struct sock_server { 20 struct sock_server_bind *bind; 21 size_t num_binds; 22 int quit_fd; 23 int stop_fd; 24 pthread_t thr; 25 pthread_mutex_t mu; 26 bool error; 27 struct sock_io_cb *cb; 28 }; 29 30 struct sock_io_cb { 31 bool (*accept)(void *ptr, int fd, short *events); 32 bool (*read)(void *ptr, int fd, short *events); 33 bool (*write)(void *ptr, int fd, short *events); 34 void *ptr; 35 }; 36 37 bool sock_server_init_tcp(struct sock_server *sock_serv, struct sock_io_cb *cb); 38 bool sock_server_init_udp(struct sock_server *sock_serv, struct sock_io_cb *cb); 39 void sock_server_uninit(struct sock_server *sock_serv); 40 void sock_server_lock(struct sock_server *sock_serv); 41 void sock_server_unlock(struct sock_server *sock_serv); 42 43 #endif /*XTEST_SOCK_SERVER_H*/ 44