util: drop inet_nonblocking_connect()
[qemu/ar7.git] / include / qemu / sockets.h
blob2cbe6432cdadc4ac079c97630b61176c56729c08
1 /* headers to use the BSD sockets */
3 #ifndef QEMU_SOCKETS_H
4 #define QEMU_SOCKETS_H
6 #ifdef _WIN32
8 int inet_aton(const char *cp, struct in_addr *ia);
10 #endif /* !_WIN32 */
12 #include "qapi-types.h"
14 /* misc helpers */
15 int qemu_socket(int domain, int type, int protocol);
16 int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
17 int socket_set_cork(int fd, int v);
18 int socket_set_nodelay(int fd);
19 void qemu_set_block(int fd);
20 void qemu_set_nonblock(int fd);
21 int socket_set_fast_reuse(int fd);
23 #ifdef WIN32
24 /* Windows has different names for the same constants with the same values */
25 #define SHUT_RD 0
26 #define SHUT_WR 1
27 #define SHUT_RDWR 2
28 #endif
30 /* callback function for nonblocking connect
31 * valid fd on success, negative error code on failure
33 typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque);
35 InetSocketAddress *inet_parse(const char *str, Error **errp);
36 int inet_listen(const char *str, char *ostr, int olen,
37 int socktype, int port_offset, Error **errp);
38 int inet_connect(const char *str, Error **errp);
40 NetworkAddressFamily inet_netfamily(int family);
42 int unix_listen(const char *path, char *ostr, int olen, Error **errp);
43 int unix_connect(const char *path, Error **errp);
44 int unix_nonblocking_connect(const char *str,
45 NonBlockingConnectHandler *callback,
46 void *opaque, Error **errp);
48 SocketAddress *socket_parse(const char *str, Error **errp);
49 int socket_connect(SocketAddress *addr, Error **errp,
50 NonBlockingConnectHandler *callback, void *opaque);
51 int socket_listen(SocketAddress *addr, Error **errp);
52 void socket_listen_cleanup(int fd, Error **errp);
53 int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
55 /* Old, ipv4 only bits. Don't use for new code. */
56 int parse_host_port(struct sockaddr_in *saddr, const char *str);
57 int socket_init(void);
59 /**
60 * socket_sockaddr_to_address:
61 * @sa: socket address struct
62 * @salen: size of @sa struct
63 * @errp: pointer to uninitialized error object
65 * Get the string representation of the socket
66 * address. A pointer to the allocated address information
67 * struct will be returned, which the caller is required to
68 * release with a call qapi_free_SocketAddress when no
69 * longer required.
71 * Returns: the socket address struct, or NULL on error
73 SocketAddress *
74 socket_sockaddr_to_address(struct sockaddr_storage *sa,
75 socklen_t salen,
76 Error **errp);
78 /**
79 * socket_local_address:
80 * @fd: the socket file handle
81 * @errp: pointer to uninitialized error object
83 * Get the string representation of the local socket
84 * address. A pointer to the allocated address information
85 * struct will be returned, which the caller is required to
86 * release with a call qapi_free_SocketAddress when no
87 * longer required.
89 * Returns: the socket address struct, or NULL on error
91 SocketAddress *socket_local_address(int fd, Error **errp);
93 /**
94 * socket_remote_address:
95 * @fd: the socket file handle
96 * @errp: pointer to uninitialized error object
98 * Get the string representation of the remote socket
99 * address. A pointer to the allocated address information
100 * struct will be returned, which the caller is required to
101 * release with a call qapi_free_SocketAddress when no
102 * longer required.
104 * Returns: the socket address struct, or NULL on error
106 SocketAddress *socket_remote_address(int fd, Error **errp);
109 * socket_address_to_string:
110 * @addr: the socket address struct
111 * @errp: pointer to uninitialized error object
113 * Get the string representation of the socket
114 * address. A pointer to the char array containing
115 * string format will be returned, the caller is
116 * required to release the returned value when no
117 * longer required with g_free.
119 * Returns: the socket address in string format, or NULL on error
121 char *socket_address_to_string(struct SocketAddress *addr, Error **errp);
123 #endif /* QEMU_SOCKETS_H */