Files
flexnbd-c/src/common/sockutil.h

59 lines
1.7 KiB
C
Raw Normal View History

#ifndef SOCKUTIL_H
#define SOCKUTIL_H
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/select.h>
/* Returns the size of the sockaddr, or 0 on error */
2018-02-20 10:05:35 +00:00
size_t sockaddr_size(const struct sockaddr *sa);
/* Convert a sockaddr into an address. Like inet_ntop, it returns dest if
* successful, NULL otherwise. In the latter case, dest will contain "???"
*/
2018-02-20 10:05:35 +00:00
const char *sockaddr_address_string(const struct sockaddr *sa, char *dest,
size_t len);
2018-01-10 13:49:22 +00:00
/* Configure TCP keepalive on a socket */
2018-02-20 10:05:35 +00:00
int sock_set_keepalive_params(int fd, int time, int intvl, int probes);
2018-01-10 13:49:22 +00:00
/* Set the SOL_KEEPALIVE otion */
int sock_set_keepalive(int fd, int optval);
/* Set the SOL_REUSEADDR otion */
int sock_set_reuseaddr(int fd, int optval);
2018-01-10 13:49:22 +00:00
/* Set the tcp_keepidle option */
int sock_set_tcp_keepidle(int fd, int optval);
/* Set the tcp_keepintvl option */
int sock_set_tcp_keepintvl(int fd, int optval);
/* Set the tcp_keepcnt option */
int sock_set_tcp_keepcnt(int fd, int optval);
/* Set the tcp_nodelay option */
int sock_set_tcp_nodelay(int fd, int optval);
2014-02-25 15:44:46 +00:00
/* Set the tcp_cork option */
int sock_set_tcp_cork(int fd, int optval);
int sock_set_nonblock(int fd, int optval);
/* Attempt to bind the fd to the sockaddr, retrying common transient failures */
2018-02-20 10:05:35 +00:00
int sock_try_bind(int fd, const struct sockaddr *sa);
/* Try to call select(), retrying EINTR */
2018-02-20 10:05:35 +00:00
int sock_try_select(int nfds, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval *timeout);
/* Try to call connect(), timing out after wait seconds */
2018-02-20 10:05:35 +00:00
int sock_try_connect(int fd, struct sockaddr *to, socklen_t addrlen,
int wait);
/* Try to call close(), retrying EINTR */
2018-02-20 10:05:35 +00:00
int sock_try_close(int fd);
#endif