Article Directory
EPOLL
Today, because
epoll
the ET mode is lostconnect事件
, it took a day of brainless debugging to find out where the error is. Hereby record it.
When only using epoll's ET mode, multiple cennect
may only trigger one 事件
, so it is necessary to loop accept
until it returns -1
and error
is set to WAGAIN
or WEOULDBLOCK
does not exit the loop. Otherwise it will 丢失connect事件
.
The difference between epoll's LT and ET
LT: horizontal trigger, the efficiency will be lower than that of ET trigger, especially in the case of large concurrency and large flow. However, LT has relatively low requirements for code writing and is not prone to problems. The performance of the LT mode service writing is: as long as there is data that has not been obtained, the kernel will continue to notify you, so there is no need to worry about the event loss.
ET: Edge triggering is very efficient. In the case of concurrent and large traffic, there will be many fewer epoll system calls than LT, so the efficiency is high. However, the requirements for programming are high, and each request needs to be handled carefully, otherwise a loss event may easily occur.
The following is an example to illustrate the difference between LT and ET (both are non-blocking mode, blocking is not said, the efficiency is too low):
In LT mode, if the accept call returns, you can immediately establish the current connection, and then epoll_wait wait The next notice is the same as select.
But for ET, if the accpet call returns, in addition to establishing the current connection, epoll_wait can't immediately continue to loop accpet until it returns -1, and errno == EAGAIN
- Reference: http://www.voidcn.com/article/p-qhcylfuz-bkv.html
man 7 epoll
while(1)
{
struct sockaddr_in client_address;
socklen_t len = sizeof client_address;
int connfd = accept(listenfd, (struct sockaddr*)&client_address, &len);
if(connfd == -1)
{
if(errno == EAGAIN || errno == EWOULDBLOCK)
{
break;
}
}
else
{
addfd(epollfd, connfd, true);
}
}
Two functions
sendfile();
copy_file_range();
以上两个函数输入必须是可以映射到内存的文件,输出sendfile()必须是套接字,copy_file_range()没有限制。
GDB
// TODO
debug multi-threaded program
http://logan.tw/posts/2015/11/01/debug-multithreaded-program-with-gdb/
other
Regarding switch
a small problem, you case
need to use curly braces for each . I have rarely used this problem before. I can refer to it here: https://stackoverflow.com/questions/5685471/error-jump-to-case-label