diff --git a/test_file/makefile b/test_file/makefile new file mode 100644 index 0000000..7fd3540 --- /dev/null +++ b/test_file/makefile @@ -0,0 +1,2 @@ +test_file:test_file.cpp + g++ $^ -o $@ -levent \ No newline at end of file diff --git a/test_file/test_file.cpp b/test_file/test_file.cpp new file mode 100644 index 0000000..9c6ce95 --- /dev/null +++ b/test_file/test_file.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#ifdef _WIN32 + +#else + #include + + #include + #include + #include + #include +#endif // !_WIN32 + +using namespace std; + +void read_file(evutil_socket_t fd,short event,void *arg){ + char buf[1024] = {0}; + int len = read(fd,buf,sizeof(buf) - 1); + if(len > 0){ + cout << buf << endl; // 当有用户登录就会把 该信息打印出来 + }else { + cout << "." << endl; + this_thread::sleep_for(500ms); + } + +} + +int main(int agrc,char** agrv){ +#ifdef _WIN32 + //初始化socket库 + WSADATA wsa; + WSAStartup(MAKEWORD(2, 2), &wsa); +#else + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { //忽略管道信号,发送数据给已关闭的socket,会飞掉! + return 1; + } +#endif + + event_config* conf = event_config_new(); + event_config_require_features(conf,EV_FEATURE_FDS); + event_base *base = event_base_new_with_config(conf); + event_config_free(conf); + + if(!base){ + cerr << "event_base_new_with_config failed" <