markparticle / WebServer

C++ Linux WebServer服务器
Apache License 2.0
3.58k stars 733 forks source link

设置文件为非阻塞 #55

Open cbwood opened 2 years ago

cbwood commented 2 years ago
int WebServer::SetFdNonblock(int fd) {
    assert(fd > 0);
    return fcntl(fd, F_SETFL, fcntl(fd, F_GETFD, 0) | O_NONBLOCK);
}

其中F_GETFD是否应该改为F_GETFL?

Nemodontcry commented 2 years ago

确实错了,需要修改

ChoHee15 commented 2 years ago

惊了还真是 我自己大概看了一下,fd初始有一个O_RDWR状态(值为2),正常情况下与的结果应该是O_RDWR|O_NONBLOCK(2|2048=2050) 而F_GETFD返回的就是0,0|O_NONBLOCK还是O_NONBLOCK(2048),这段程序会导致丢失O_RDWR状态 但好像并不影响正常运行,不知道会不会在某种情况下成为一个雷

smallmocha commented 2 years ago
int WebServer::SetFdNonblock(int fd) {
    assert(fd > 0);
    return fcntl(fd, F_SETFL, fcntl(fd, F_GETFD, 0) | O_NONBLOCK);
}

其中F_GETFD是否应该改为F_GETFL? 确实是写错了,还好我自己实现的时候没有写错

1900100209 commented 6 months ago

我也注意到了,他写的这个项目,小问题挺多