随笔分类 -  网络编程

摘要:条件变量的意义在于:1.多个线程对一个保护的资源进行控制的时候, 当一个线程A进入临界区,发现此时需要等待这个资源满足某个条件而阻塞。这个时候因为阻塞的地方是在临界区里面,所以其他线程也无法操纵这个资源使之满足A线程的条件,从而导致线程A永远阻塞在这里。2.为了解决这个问题,可以使用条件变量 当线程... 阅读全文
posted @ 2014-04-14 10:07 superPerfect 阅读(317) 评论(0) 推荐(0)
摘要:使用到主要函数有:#include int epoll_create(int size);int epoll_create1(int flags);int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);typedef union epoll_data { void *ptr; int fd; uint32_t u32; uint64_t u64;}... 阅读全文
posted @ 2014-03-17 23:46 superPerfect 阅读(555) 评论(0) 推荐(0)
摘要:1 #define POLL_FD_SIZE 1024 2 int doServicePoll(int listenFd) 3 { 4 struct sockaddr_in cliAddr; 5 socklen_t len; 6 7 int i; 8 struct pollfd pollFdSet[POLL_FD_SIZE]; 9 for(i = 0 ; i fdNum) {41 fdNum = i;42 }43 ... 阅读全文
posted @ 2014-03-16 23:03 superPerfect 阅读(363) 评论(0) 推荐(0)
摘要://read操作加上超时时间。 1 int read_timeout(int fd, void *buf, uint32_t count, int time) 2 { 3 if(time > 0) { 4 fd_set rSet; 5 FD_ZERO(&rSet); 6 FD_SET(fd, &rSet); 7 8 struct timeval timeout; 9 memset(&timeout, 0, sizeof(timeout));10 timeout.tv_sec = time;... 阅读全文
posted @ 2014-03-16 15:52 superPerfect 阅读(2133) 评论(0) 推荐(0)