New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DNS health checker #429

Merged
merged 3 commits into from Sep 21, 2016
Jump to file or symbol
Failed to load files and symbols.
+48 −13
Diff settings

Always

Just for now

Next

Add support for UDP socket to layer4 library

Signed-off-by: Masaya Yamamoto <yamamoto-ma@klab.com>
  • Loading branch information...
pandax381 committed Sep 20, 2016
commit bc432301a923bfb2d294cc6f284b3be4428019af
View
@@ -28,19 +28,28 @@
#include "logger.h"
enum connect_result
tcp_bind_connect(int fd, conn_opts_t *co)
socket_bind_connect(int fd, conn_opts_t *co)
{
int opt;
socklen_t optlen;
struct linger li;
socklen_t addrlen;
int ret;
int val;
struct sockaddr_storage *addr = &co->dst;
struct sockaddr_storage *bind_addr = &co->bindto;
/* free the tcp port after closing the socket descriptor */
li.l_onoff = 1;
li.l_linger = 0;
setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof (struct linger));
optlen = sizeof(opt);
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *) &opt, &optlen) < 0) {
log_message(LOG_ERR, "Can't get socket type: %s", strerror(errno));
return connect_error;
}
if (opt == SOCK_STREAM) {
/* free the tcp port after closing the socket descriptor */
li.l_onoff = 1;
li.l_linger = 0;
setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof (struct linger));
}
/* Make socket non-block. */
val = fcntl(fd, F_GETFL, 0);
@@ -84,16 +93,16 @@ tcp_bind_connect(int fd, conn_opts_t *co)
}
enum connect_result
tcp_connect(int fd, struct sockaddr_storage *addr)
socket_connect(int fd, struct sockaddr_storage *addr)
{
conn_opts_t co;
memset(&co, 0, sizeof(co));
co.dst = *addr;
return tcp_bind_connect(fd, &co);
return socket_bind_connect(fd, &co);
}
enum connect_result
tcp_socket_state(thread_t * thread, int (*func) (thread_t *))
socket_state(thread_t * thread, int (*func) (thread_t *))
{
int status;
socklen_t addrlen;
@@ -136,7 +145,7 @@ tcp_socket_state(thread_t * thread, int (*func) (thread_t *))
}
int
tcp_connection_state(int fd, enum connect_result status, thread_t * thread,
socket_connection_state(int fd, enum connect_result status, thread_t * thread,
int (*func) (thread_t *), long timeout)
{
checker_t *checker;
@@ -45,16 +45,42 @@ enum connect_result {
/* Prototypes defs */
extern enum connect_result
tcp_bind_connect(int, conn_opts_t *);
socket_bind_connect(int, conn_opts_t *);
extern enum connect_result
tcp_connect(int, struct sockaddr_storage *);
socket_connect(int, struct sockaddr_storage *);
extern enum connect_result
tcp_socket_state(thread_t *, int (*func) (thread_t *));
socket_state(thread_t *, int (*func) (thread_t *));
extern int
tcp_connection_state(int, enum connect_result
socket_connection_state(int, enum connect_result
, thread_t *, int (*func) (thread_t *)
, long);
/* Backward compatibility */
static inline enum connect_result
tcp_bind_connect(int fd, conn_opts_t *co)
{
return socket_bind_connect(fd, co);
}
static inline enum connect_result
tcp_connect(int fd, struct sockaddr_storage *addr)
{
return socket_connect(fd, addr);
}
static inline enum connect_result
tcp_socket_state(thread_t * thread, int (*func) (thread_t *))
{
return socket_state(thread, func);
}
static inline int
tcp_connection_state(int fd, enum connect_result status, thread_t * thread,
int (*func) (thread_t *), long timeout)
{
return socket_connection_state(fd, status, thread, func, timeout);
}
#endif
ProTip! Use n and p to navigate between commits in a pull request.