libubox: tests: add more blobmsg/json test cases
[project/libubox.git] / usock.h
1 /*
2 * usock - socket helper functions
3 *
4 * Copyright (C) 2010 Steven Barth <steven@midlink.org>
5 * Copyright (C) 2011-2012 Felix Fietkau <nbd@openwrt.org>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19 #ifndef USOCK_H_
20 #define USOCK_H_
21
22 #define USOCK_TCP 0
23 #define USOCK_UDP 1
24
25 #define USOCK_SERVER 0x0100
26 #define USOCK_NOCLOEXEC 0x0200
27 #define USOCK_NONBLOCK 0x0400
28 #define USOCK_NUMERIC 0x0800
29 #define USOCK_IPV6ONLY 0x2000
30 #define USOCK_IPV4ONLY 0x4000
31 #define USOCK_UNIX 0x8000
32
33 const char *usock_port(int port);
34 int usock(int type, const char *host, const char *service);
35 int usock_inet_timeout(int type, const char *host, const char *service,
36 void *addr, int timeout);
37 static inline int
38 usock_inet(int type, const char *host, const char *service, void *addr)
39 {
40 return usock_inet_timeout(type, host, service, addr, -1);
41 }
42
43 /**
44 * Wait for a socket to become ready.
45 *
46 * This may be useful for users of USOCK_NONBLOCK to wait (with a timeout)
47 * for a socket.
48 *
49 * @param fd file descriptor of socket
50 * @param msecs timeout in microseconds
51 */
52 int usock_wait_ready(int fd, int msecs);
53
54 #endif /* USOCK_H_ */