Add TCP query

This commit is contained in:
Nick Peng
2018-06-24 00:05:09 +08:00
parent 0e72262be3
commit 5153d6cb51
5 changed files with 395 additions and 162 deletions

View File

@@ -1,9 +1,11 @@
#include "util.h"
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
unsigned long get_tick_count(void)
{
@@ -98,4 +100,22 @@ int parse_ip(const char *value, char *ip, int *port)
}
return 0;
}
}
int set_fd_nonblock(int fd, int nonblock)
{
int ret;
int flags = fcntl(fd, F_GETFL);
if (flags == -1) {
return -1;
}
flags = (nonblock) ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
ret = fcntl(fd, F_SETFL, flags);
if (ret == -1) {
return -1;
}
return 0;
}