httpserver's People
httpserver's Issues
[Fun Fact]: TCP的AIMD(加性增乘性减)
[Fun Fact]: TCP自连接
[Fun Fact] C++ Lambda表达式
参考博客
使用Lambda表达式创建线程
//recipes/netcat.cc
std::thread thr([&stream] () {
char buf[8192];
int nr = 0;
while ( (nr = stream->receiveSome(buf, sizeof(buf))) > 0)
{
int nw = write_n(STDOUT_FILENO, buf, nr);
if (nw < nr)
{
break;
}
}
::exit(0); // should somehow notify main thread instead
});
Trilogy of TCP client/server
- SO_REUSEADDR
- Ignore SIGPIPE
- TCP_NODELAY
TCP_NODELAY选项用以禁用Nagle算法,使得数据包不用延迟发送
Nagle算法的规则(可参考tcp_output.c文件里tcp_nagle_check函数注释):
(1)如果包长度达到MSS,则允许发送;
(2)如果该包含有FIN,则允许发送;
(3)设置了TCP_NODELAY选项,则允许发送;
(4)未设置TCP_CORK选项时,若所有发出去的小数据包(包长度小于MSS)均被确认,则允许发送;
(5)上述条件都未满足,但发生了超时(一般为200ms),则立即发送。
[Fun Fact] TCP也会‘不可靠’
[Trick]: 使用RAII机制实现状态重置
//muduo/net/http/HttpComtext.cc
void reset()
{
state_ = kExpectRequestLine;
HttpRequest dummy;
request_.swap(dummy);
}
新建一个local对象,用以重置成员,当退出作用域时local对象会自动调用析构函数释放资源,快捷地实现了成员的重置。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.