日期:2014-05-16 浏览次数:21269 次
socket done
bind done
listen done
epoll_create failed: Function not implemented
socket done
bind done
listen done
no socket ready for read within 5 secs
no socket ready for read within 5 secs
no socket ready for read within 5 secs
no socket ready for read within 5 secs
no socket ready for read within 5 secs
no socket ready for read within 5 secs
no socket ready for read within 5 secs
no socket ready for read within 5 secs
...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <errno.h>
#define DEFAULT_PORT 1984 //默认端口
#define BUFF_SIZE 1024 //buffer大小
#define EPOLL_MAXEVENTS 64 //epoll_wait的最多返回的events个数
#define EPOLL_TIMEOUT 5000 //epoll_wait的timeout milliseconds
//函数:设置sock为non-blocking mode
void setSockNonBlock(int sock) {
int flags;
flags = fcntl(sock, F_GETFL, 0);
if (flags < 0) {
perror("fcntl(F_GETFL) failed");
exit(EXIT_FAILURE);
}
if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) {
perror("fcntl(F_SETFL) failed");
exit(EXIT_FAILURE);
}
}
int main(int argc, char *argv[]) {
//获取自定义端口
unsigned short int port;
if (argc == 2) {
port = atoi(argv[1]);
&nbs