mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-01-18 22:09:35 +08:00
add signal handler
This commit is contained in:
parent
5fcf83e61a
commit
20799f78c2
18
common.cpp
18
common.cpp
@ -47,7 +47,7 @@ struct random_fd_t
|
||||
return random_number_fd;
|
||||
}
|
||||
}random_fd;
|
||||
|
||||
/*
|
||||
u64_t get_current_time()//ms
|
||||
{
|
||||
timespec tmp_time;
|
||||
@ -60,6 +60,22 @@ u64_t get_current_time_us()
|
||||
timespec tmp_time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
return (uint64_t(tmp_time.tv_sec))*1000llu*1000llu+ (uint64_t(tmp_time.tv_nsec))/1000llu;
|
||||
}*/
|
||||
|
||||
u64_t get_current_time()//ms
|
||||
{
|
||||
//timespec tmp_time;
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
//return ((u64_t)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
||||
return (u64_t)(ev_time()*1000);
|
||||
}
|
||||
|
||||
u64_t get_current_time_us()
|
||||
{
|
||||
//timespec tmp_time;
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
//return (uint64_t(tmp_time.tv_sec))*1000llu*1000llu+ (uint64_t(tmp_time.tv_nsec))/1000llu;
|
||||
return (u64_t)(ev_time()*1000*1000);
|
||||
}
|
||||
|
||||
u64_t pack_u64(u32_t a,u32_t b)
|
||||
|
1
common.h
1
common.h
@ -67,6 +67,7 @@ typedef short i16_t;
|
||||
|
||||
typedef u64_t my_time_t;
|
||||
|
||||
|
||||
const int max_data_len=3600;
|
||||
const int buf_len=max_data_len+200;
|
||||
|
||||
|
30
main.cpp
30
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user