From 5b9da8dd430d942426a88088bbc974c8db0790a5 Mon Sep 17 00:00:00 2001 From: wangyu Date: Sun, 3 Jun 2018 20:39:31 -0700 Subject: [PATCH] port to mac --- common.cpp | 14 +++++++++----- common.h | 12 +++++------- fec_manager.cpp | 1 + log.h | 5 ----- main.cpp | 30 ++++++++++++++++++++++++++++++ makefile | 5 +++++ 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/common.cpp b/common.cpp index a344279..7ff4cdb 100644 --- a/common.cpp +++ b/common.cpp @@ -198,6 +198,8 @@ u32_t get_true_random_number_nz() //nz for non-zero } return ret; } + +/* u64_t ntoh64(u64_t a) { if(__BYTE_ORDER == __LITTLE_ENDIAN) @@ -215,7 +217,7 @@ u64_t hton64(u64_t a) } else return a; -} +}*/ void setnonblocking(int sock) { int opts; @@ -295,8 +297,9 @@ unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int n int set_buf_size(int fd,int socket_buf_size,int force_socket_buf) { - if(force_socket_buf) + if(0) { +/* if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0) { mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); @@ -307,6 +310,7 @@ int set_buf_size(int fd,int socket_buf_size,int force_socket_buf) mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); myexit(1); } +*/ } else { @@ -447,7 +451,7 @@ int random_between(u32_t a,u32_t b) else return a+get_true_random_number()%(b+1-a); } - +/* int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval) { int ret; @@ -476,7 +480,7 @@ int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval) myexit(-1); } return 0; -} +}*/ /* int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port) { @@ -579,7 +583,7 @@ int new_listen_socket(int &fd,u32_t ip,int port) local_me.sin_port = htons(port); local_me.sin_addr.s_addr = ip; - if (bind(fd, (struct sockaddr*) &local_me, slen) == -1) { + if (::bind(fd, (struct sockaddr*) &local_me, slen) == -1) { mylog(log_fatal,"socket bind error\n"); //perror("socket bind error"); myexit(1); diff --git a/common.h b/common.h index 83b8ad1..219e70c 100644 --- a/common.h +++ b/common.h @@ -17,7 +17,6 @@ #include #include -#include #include #include //for socket ofcourse #include @@ -30,21 +29,15 @@ #include #include #include -#include #include -#include -#include #include #include -#include #include #include #include #include #include #include -#include -#include #include @@ -65,6 +58,11 @@ typedef int i32_t; typedef unsigned short u16_t; typedef short i16_t; +struct itimerspec { + struct timespec it_interval; /* Timer interval */ + struct timespec it_value; /* Initial expiration */ +}; + typedef u64_t my_time_t; const int max_data_len=3600; diff --git a/fec_manager.cpp b/fec_manager.cpp index 75b2dd8..fcb6a2a 100644 --- a/fec_manager.cpp +++ b/fec_manager.cpp @@ -28,6 +28,7 @@ int header_overhead=40; u32_t fec_buff_num=2000;// how many packet can fec_decode_manager hold. shouldnt be very large,or it will cost huge memory + blob_encode_t::blob_encode_t() { clear(); diff --git a/log.h b/log.h index d29788f..b97acd0 100755 --- a/log.h +++ b/log.h @@ -14,7 +14,6 @@ #include //#include"aes.h" -#include #include #include @@ -32,17 +31,13 @@ #include #include #include -#include #include #include #include -#include -#include #include #include -#include #include //#include #include diff --git a/main.cpp b/main.cpp index 4839d0e..d1b6db0 100644 --- a/main.cpp +++ b/main.cpp @@ -74,9 +74,39 @@ static void print_help() } +void sigpipe_cb(struct ev_loop *l, ev_signal *w, int revents) +{ + mylog(log_info, "got sigpipe, ignored"); +} + +void sigterm_cb(struct ev_loop *l, ev_signal *w, int revents) +{ + mylog(log_info, "got sigterm, exit"); + myexit(0); +} + +void sigint_cb(struct ev_loop *l, ev_signal *w, int revents) +{ + mylog(log_info, "got sigint, exit"); + myexit(0); +} + int main(int argc, char *argv[]) { + struct ev_loop* loop=ev_default_loop(0); + ev_signal signal_watcher_sigpipe; + ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE); + ev_signal_start(loop, &signal_watcher_sigpipe); + + ev_signal signal_watcher_sigterm; + ev_signal_init(&signal_watcher_sigterm, sigterm_cb, SIGTERM); + ev_signal_start(loop, &signal_watcher_sigterm); + + ev_signal signal_watcher_sigint; + ev_signal_init(&signal_watcher_sigint, sigint_cb, SIGINT); + ev_signal_start(loop, &signal_watcher_sigint); + //working_mode=tunnel_mode; assert(sizeof(u64_t)==8); diff --git a/makefile b/makefile index f4c7502..1dcf610 100755 --- a/makefile +++ b/makefile @@ -18,6 +18,11 @@ TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/speederv2_\1/g'` all:git_version rm -f ${NAME} ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3 + +mac:git_version + rm -f ${NAME} + ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -ggdb -O3 -Wno-c++17-compat-mangling + debug: git_version rm -f ${NAME} ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG