starwing / znet Goto Github PK
View Code? Open in Web Editor NEWA C network library
License: MIT License
A C network library
License: MIT License
znet - a simple C network library --------------------------------- This library is inspired by Yawei Zhang's ZsummerX[1] library, but this one is a pure C version. Now it implement a IOCP (IO Completion Port) backend on Windows, and a epoll backend on Linux, a kqueue backend on BSD and Mac OS X systems, and select backend for others. The ZNet library itself is a single-header library[2], and have some utils single-header libraries for common usages. all liraries are standalone and can used without other headers. See test.c for examples, and you can see more things in examples folder. Utils: zn_buffer.h: mainly based the luaL_Buffer in Lua code. But the interface is targeted by send/recv method, so it's very useful to make znet send data continually and receive packets by packets. zn_deque.h: a double-direct pipe implement that can be used a queue or stack cross threads. it implements block API like push/pop from deque, and non-block API to fetch the front and back items from deque. zn_task.h: a task thread pool implement. you can create a task pool and post tasks to pool, task will run in other thread, you can use zn_deque.h to notice original thread the completion of tasks. The znet library and utils have the same license when Lua[3], have fun :) [1]: https://github.com/zsummer/zsummerX [2]: https://github.com/nothings/stb [3]: https://www.lua.org/license.html
总之:
epoll_ctl(epoll, EPOLL_CTL_DEL, fd, 0)
肯定能将fd从epoll set中移除,epoll_wait不会报告fd。close(fd)
会关闭file description并且从epoll set中移除。 否则epoll_wait有可能会报告。man 7 epoll
Will closing a file descriptor cause it to be removed from all epoll sets automatically?
用户即使摸不到fd,也可以fork。。。 保险起见还是保持原样吧,也就多一个系统调用而已。。。
libuv也这样改过: linux: always deregister closing fds from epoll
看后关。。。
我看每个tcp的buffer有个pool,那tcp本身需不需要一个pool呢?
不知道INET6_ADDRSTRLEN在windows下是个什么状况。
msvc/mingw(or cygwin?)的各个版本里自带的header里有没有?
因为windows下比较混乱的原因, 不直接用INET6_ADDRSTRLEN这个名字也行, 但目前用的值实在是太大了。。。 zn_PeerInfo和zn_Tcp非常大。。。
分摊系统调用开销。于是就和linux一样面临一个问题:用多大的buffer。。。?
太小的话,系统调用开销占的比例就高。比如znet_iocp.h里的znS_poll。
太大也不好,(在最坏被填充满的情况下)会过多占用缓存。比如znet_epoll.h里的znS_poll。4096*12。。。
so。。。 将buffer大小的选择权交给,或者说责任推卸给,用户?
具体做法么。。。 可以是:
example.c file's cpp version would be very apriciated. Thank you.
是否忘了提交了?
if (b->sending->used == count) { /* all sent? */
need to changed to:
if (b->sending->used - b->sent_count == count) { /* all sent? */
这个函数无法区分错误。。。 可以用getaddrinfo。。。 除了可以检查错误外,它可以同时处理v4(比如"127.0.0.1")和v6("::1")。 但用起来比较麻烦, 还不知道windows上是不是支持。。。
不管怎样也得把inet_addr给排除掉。。。
另外。。。 是不打算解析地址吧。。。 但const char *addr这样的参数。。。
zn_connect不解析地址,总有一个地方要解析, 一般就直接解析成二进制形式了, 然后再转成字符串传进来???
@ownwaterloo 计划加入 getaddrinfo 和 getnameinfo 的功能了。主要的动机其实是异步执行耗时任务,也就是线程池,如果不想自己写mysql的协议,那么异步执行阻塞任务其实是很重要的事情。
那么,目前的工作就成了:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.