epoll测试实例
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
#include <stdio.h>
#include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <unistd.h> #include <fcntl.h> #include <sys/epoll.h> #include <errno.h> static int flags = fcntl (sfd, F_GETFL, ); flags |= O_NONBLOCK; ; static int memset (&hints, , sizeof (struct addrinfo)); s = getaddrinfo (NULL, port, &hints, &result); for (rp = result; rp != NULL; rp = rp->ai_next) s = bind (sfd, rp->ai_addr, rp->ai_addrlen); close (sfd); if (rp == NULL) freeaddrinfo (result); return sfd; int ) sfd = create_and_bind (argv[]); s = make_socket_non_blocking (sfd); s = listen (sfd, SOMAXCONN); efd = epoll_create1 (); event.data.fd = sfd; /* Buffer where events are returned */ /* The event loop */ n = epoll_wait (efd, events, MAXEVENTS, -); else if (sfd == events[i].data.fd) in_len = sizeof in_addr; s = getnameinfo (&in_addr, in_len, /* Make the incoming socket non-blocking and add it to the event.data.fd = infd; ) count = read (events[i].data.fd, buf, sizeof buf); /* Write the buffer to standard output */ if (done) /* Closing the descriptor will make epoll remove it free (events); close (sfd); return EXIT_SUCCESS; |
具体函数介绍请参考:https://banu.com/blog/2/how-to-use-epoll-a-complete-example-in-c/
运行结果:
服务器端:

客户端:

epoll测试实例的更多相关文章
- JMeter学习-026-JMeter 分布式(远程)参数化测试实例
以前文所述对文章详情的HTTP请求进行性能测试为例.日常实际场景中,不可能所有的人都在同时访问一篇文章,而是多人访问不同的文章,因而需要对文章编号进行参数化,以更好的模拟日常的性能测试场景.同时,因文 ...
- webservice测试实例
webservice测试实例(LR8.1) 接口声明:这个接口是sina的短信服务接口,我只是用来做脚本学习使用,不会对其产生压力:希望读者也只是用来进行录制学习,而不是产生压力. 接口文档:http ...
- [原]在Fedora中编译Libevent测试实例
在我的昨天的博文<[原]我在Windows环境下的首个Libevent测试实例>中介绍了在Windows环境下如何编译一个echo server例子.今天我又试了一下在Linux环境中编译 ...
- C++动态链接库测试实例
前话 上一章节我导出了一个动态链接库 要使用该链接库,我们还需要该链接库对外公开的函数,即头文件 下面开始实例 测试实例 第一步--将动态链接库的dll.lib.和头文件导入项目中 文件目录如下: 项 ...
- Linux下简易蜂鸣器驱动代码及测试实例
驱动代码: #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> ...
- 微服务架构 - 离线部署k8s平台并部署测试实例
一般在公司部署或者真实环境部署k8s平台,很有可能是内网环境,也即意味着是无法连接互联网的环境,这时就需要离线部署k8s平台.在此整理离线部署k8s的步骤,分享给大家,有什么不足之处,欢迎指正. 1. ...
- WinForm中 Asp.Net Signalr消息推送测试实例
p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...
- Confluence 6 从生产环境中恢复一个测试实例
请参考 Restoring a Test Instance from Production 页面中的内容获得更多完整的说明. 很多 Confluence 的管理员将会使用生产实例运行完整数据和服务的 ...
- Rabbit简单测试实例
Rabbit简单测试实例 安装环境: Yum -y install python-pip Pip install pika 生产者 1 2 3 4 5 6 7 8 9 10 11 import pik ...
随机推荐
- fzyzojP3782 -组合数问题
这个ai<=2000有点意思 启发我们用O(W^2)的算法 FFT不存在,对应关系过紧 考虑组合意义转化建模,再进行分离 (除以2不需要逆元不懂为啥,但是算个逆元总不费事) 由于终点可能在起点的 ...
- python之旅:函数对象、函数嵌套、名称空间与作用域、装饰器
一 函数对象 一 函数是第一类对象,即函数可以当作数据传递 #1 可以被引用 #2 可以当作参数传递 #3 返回值可以是函数 #3 可以当作容器类型的元素 二 利用该特性,优雅的取代多分支的if de ...
- codeforces div1 & div2 参与人员分数统计
Analysis helps to see the nature of things.
- Qt error ------ incomplete type 'QApplication' used in nested name specifier
没有包含 ‘QApplication’ 头文件
- Linux服务器上使用curl命令发送报文
报文格式如下: curl -l -H "Content-type: application/json" -X POST -d 'postdata' http://172.20.10 ...
- bzoj千题计划157:bzoj1220:[HNOI2002]跳蚤
扩展欧几里得:ax+by=gcd(a,b) 一定有解 能跳到左边一格,即ax+by=-1 若a,b的gcd=1,则一定有解 所以问题转化为 求n个不大于m的数,他们与m的gcd=1 的方案数 容斥原理 ...
- Visual Studio Code 教程之————入门篇
Visual Studio代码是一个轻量级但功能强大的源代码编辑器,可在您的桌面上运行,适用于Windows,macOS和Linux.它内置对JavaScript,TypeScript和Node.js ...
- Nginx+tomcat 负载均衡
一.系统版本 Nginx使用版本.tomcat使用版本: Nginx:nginx-1.10.2.tar.gz Java :Java version: 1.8.0_60, vendor: Oracl ...
- 20155302 2016-2017-2 《Java程序设计》第七周学习总结
20155302 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 Lambda表达式的优点:更加紧凑的代码.修改方法的能力.更好地支持多核处理 "L ...
- TensorFlow在win10上的安装与使用(三)
本篇博客介绍最经典的手写数字识别Mnist在tf上的应用. Mnist有两种模型,一种是将其数据集看作是没有关系的像素值点,用softmax回归来做.另一种就是利用卷积神经网络,考虑局部图片像素的相关 ...