88 lines
2.0 KiB
C
88 lines
2.0 KiB
C
#ifndef UC_FD_UTILS_H_
|
|
#define UC_FD_UTILS_H_
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
// inspect errno if any of these fails
|
|
|
|
/**
|
|
* set the file descriptor to non-blocking
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_nonblocking(int fd);
|
|
|
|
/**
|
|
* set the file descriptor to blocking
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_blocking(int fd);
|
|
|
|
/**
|
|
* set the socket file descriptor to SO_REUSEADDR
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_reuseaddr(int sockfd);
|
|
|
|
/**
|
|
* enable TCP keepalive on the socket
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_tcp_keepalive(int sockfd);
|
|
|
|
|
|
struct UCKeepConfig {
|
|
/** The maximum number of keepalive probes TCP should
|
|
* send before dropping the connection. (TCP_KEEPCNT socket option)
|
|
*/
|
|
int keepcnt;
|
|
/** The time (in seconds) the connection needs to remain
|
|
* idle before TCP starts sending keepalive probes (TCP_KEEPIDLE socket option)
|
|
*/
|
|
int keepidle;
|
|
/** The time (in seconds) between individual keepalive probes.
|
|
* (TCP_KEEPINTVL socket option)
|
|
*/
|
|
int keepintvl;
|
|
};
|
|
|
|
/** Set the keepalive options on the socket
|
|
* This also enables TCP keepalive on the socket
|
|
*
|
|
* @param fd file descriptor
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_tcp_keepalive_cfg(int sockfd, const struct UCKeepConfig *cfg);
|
|
/**
|
|
* Set the socket send timeout, in miliseconds
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_send_timeout(int sockfd,long timeoutms);
|
|
|
|
/**
|
|
* Set the socket receive timeout, in miliseconds
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_receive_timeout(int sockfd,long timeoutms);
|
|
|
|
/*
|
|
* Set the IP DSCP (differnetiated services code point) header value
|
|
* The dscp must be < 64
|
|
* @param fd file descriptor
|
|
* @return 0 on success -1 on failure
|
|
*/
|
|
int uc_set_ip_dscp(int fd, unsigned int dscp);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
};
|
|
#endif
|
|
#endif /* FD_UTILS_H_ */
|
|
|