mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
server works again
This commit is contained in:
parent
233fab4fac
commit
7de2f800f9
37
common.cpp
37
common.cpp
@ -347,11 +347,48 @@ int my_ip_t::from_str(char * str)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
char *get_sock_error()
|
||||||
|
{
|
||||||
|
static char buf[1000];
|
||||||
|
int e=WSAGetLastError();
|
||||||
|
wchar_t *s = NULL;
|
||||||
|
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL, e,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(LPWSTR)&s, 0, NULL);
|
||||||
|
sprintf(buf, "%d:%S", e,s);
|
||||||
|
int len=strlen(buf);
|
||||||
|
if(len>0&&buf[len-1]=='\n') buf[len-1]=0;
|
||||||
|
LocalFree(s);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
int get_sock_errno()
|
||||||
|
{
|
||||||
|
return WSAGetLastError();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
char *get_sock_error()
|
||||||
|
{
|
||||||
|
static char buf[1000];
|
||||||
|
sprintf(buf, "%d:%s", errno,strerror(errno));
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
int get_sock_errno()
|
||||||
|
{
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
u64_t get_current_time()
|
u64_t get_current_time()
|
||||||
{
|
{
|
||||||
timespec tmp_time;
|
timespec tmp_time;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &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)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
||||||
|
|
||||||
|
//return (u64_t)(ev_time()*1000); //todo change to this later
|
||||||
}
|
}
|
||||||
|
|
||||||
u64_t pack_u64(u32_t a,u32_t b)
|
u64_t pack_u64(u32_t a,u32_t b)
|
||||||
|
4
common.h
4
common.h
@ -50,11 +50,11 @@
|
|||||||
//#include <linux/if_ether.h>
|
//#include <linux/if_ether.h>
|
||||||
#include <linux/filter.h>
|
#include <linux/filter.h>
|
||||||
#include <linux/if_packet.h>
|
#include <linux/if_packet.h>
|
||||||
//#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
//#include <sys/wait.h> //signal
|
//#include <sys/wait.h> //signal
|
||||||
#include <netinet/if_ether.h>
|
#include <netinet/if_ether.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
//#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
45
main.cpp
45
main.cpp
@ -48,26 +48,37 @@ int main(int argc, char *argv[])
|
|||||||
assert(sizeof(unsigned long long)==8);
|
assert(sizeof(unsigned long long)==8);
|
||||||
|
|
||||||
dup2(1, 2);//redirect stderr to stdout
|
dup2(1, 2);//redirect stderr to stdout
|
||||||
|
#if defined(__MINGW32__)
|
||||||
struct ev_loop* loop=ev_default_loop(0);
|
enable_log_color=0;
|
||||||
|
|
||||||
#if !defined(__MINGW32__)
|
|
||||||
ev_signal signal_watcher_sigpipe;
|
|
||||||
ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE);
|
|
||||||
ev_signal_start(loop, &signal_watcher_sigpipe);
|
|
||||||
#else
|
|
||||||
enable_log_color=0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
pre_process_arg(argc,argv);
|
pre_process_arg(argc,argv);
|
||||||
|
if(program_mode==client_mode)
|
||||||
|
{
|
||||||
|
struct ev_loop* loop=ev_default_loop(0);
|
||||||
|
#if !defined(__MINGW32__)
|
||||||
|
ev_signal signal_watcher_sigpipe;
|
||||||
|
ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE);
|
||||||
|
ev_signal_start(loop, &signal_watcher_sigpipe);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
signal(SIGINT, signal_handler);
|
||||||
|
signal(SIGHUP, signal_handler);
|
||||||
|
signal(SIGKILL, signal_handler);
|
||||||
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGQUIT, signal_handler);
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(__MINGW32__)
|
#if !defined(__MINGW32__)
|
||||||
if(geteuid() != 0)
|
if(geteuid() != 0)
|
||||||
{
|
{
|
||||||
|
3
misc.cpp
3
misc.cpp
@ -1091,7 +1091,6 @@ int unit_test()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int set_timer(int epollfd,int &timer_fd)//put a timer_fd into epoll,general function,used both in client and server
|
int set_timer(int epollfd,int &timer_fd)//put a timer_fd into epoll,general function,used both in client and server
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -1154,7 +1153,7 @@ int set_timer_server(int epollfd,int &timer_fd,fd64_t &fd64)//only for server
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
int handle_lower_level(raw_info_t &raw_info)//fill lower_level info,when --lower-level is enabled,only for server
|
int handle_lower_level(raw_info_t &raw_info)//fill lower_level info,when --lower-level is enabled,only for server
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "encrypt.h"
|
#include "encrypt.h"
|
||||||
#include "fd_manager.h"
|
#include "fd_manager.h"
|
||||||
|
|
||||||
#if 0
|
|
||||||
int server_easytcp=0;//currently only for test
|
int server_easytcp=0;//currently only for test
|
||||||
|
|
||||||
int server_on_timer_multi(conn_info_t &conn_info) //for server. called when a timer is ready in epoll.for server,there will be one timer for every connection
|
int server_on_timer_multi(conn_info_t &conn_info) //for server. called when a timer is ready in epoll.for server,there will be one timer for every connection
|
||||||
@ -900,8 +899,3 @@ int server_event_loop()
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
int server_event_loop()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user