#if !SDB_HOST
#include "commandline_sdbd.h"
#endif
+#include "utils.h"
#ifdef HAVE_BIG_ENDIAN
#define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
&& !request_plugin_verification(SDBD_CMD_VERIFY_PEERIP, inet_ntoa(addr.sin_addr))) {
sdb_close(fd);
} else {
+ int ret = -1;
+ ret = keep_alive(fd, 1, SDB_KEEPALIVE_CNT, SDB_KEEPALIVE_IDLE, SDB_KEEPALIVE_INTVL);
+ if (ret < 0) {
+ D("failed to set keep alive option. FD(%d), error=%s\n", fd, strerror(errno));
+ } else {
+ D("Success to set keep alive option. FD(%d), cnt=%d, idle=%d(sec), interval=%d(sec)\n",
+ fd, SDB_KEEPALIVE_CNT, SDB_KEEPALIVE_IDLE, SDB_KEEPALIVE_INTVL);
+ }
+
register_socket_transport(fd, "host", port, 1, NULL);
}
} else {
#include <errno.h>
#include <ctype.h>
+#include <sys/socket.h>
+#include <netinet/tcp.h>
+
#define STRING_MAXLEN 1024
char*
buff_addc (char* buff, char* buffEnd, int c)
return result;
}
+int keep_alive(int fd, int onoff, int cnt, int idle, int interval)
+{
+ int ret = -1;
+
+ ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &onoff, sizeof(onoff));
+ if (ret == -1) {
+ return ret;
+ }
+
+ /* override /proc/sys/net/ipv4/tcp_keepalive_probes */
+ ret = setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
+ if (ret == -1) {
+ return ret;
+ }
+
+ /* override /proc/sys/net/ipv4/tcp_keepalive_time */
+ ret = setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
+ if (ret == -1) {
+ return ret;
+ }
+
+ /* override /proc/sys/net/ipv4/tcp_keepalive_intvl */
+ ret = setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
+ if (ret == -1) {
+ return ret;
+ }
+
+ return 0;
+}
+
char** str_split(char* a_str, const char a_delim);
+#define SDB_KEEPALIVE_CNT (9)
+#define SDB_KEEPALIVE_IDLE (1)
+#define SDB_KEEPALIVE_INTVL (1)
+int keep_alive(int fd, int onoff, int cnt, int idle, int interval);
+
#endif /* _SDB_UTILS_H */