uloop: optimize uloop_timeout_set() implementaiton a bit.
[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
36 /**
37  * Wait for a socket to become ready.
38  *
39  * This may be useful for users of USOCK_NONBLOCK to wait (with a timeout)
40  * for a socket.
41  *
42  * @param fd file descriptor of socket
43  * @param msecs timeout in microseconds
44  */
45 int usock_wait_ready(int fd, int msecs);
46
47 #endif /* USOCK_H_ */