lighttpd状态机

状态

这个状态机目前由11个状态组成,每一个连接逐步经过这些状态,有些状态比较特殊,可能会执行不到.

● connect

等待一个连接

● reqstart

初始化读空闲定时器

● read

读取HTTP请求头

● reqend

解析HTTP请求

● readpost

读取HTTP请求体

● handlereq

在内部处理请求(可能产生子请求)

● respstart

准备HTTP响应头

● write

发送HTTP响应头 + 响应内容

● respend

清理环境,输出 log

● error

重置连接(关闭连接)

● close

关闭连接(处理 lingering 延时)

internal-http-states


A simple GET request (green path)

connect 状态下等待连接,如果没有连接到来会空转,一旦连接建立,切换至 reqstart 状态,初始化读取定时器,切换至 read 状态, 然后读取数据,直到读取到HTTP请求头的终止符(CRLFCRLF),快速解析这个请求头.

解析这个请求头的动作是在 handlereq 状态来处理的,处理成功后如果决定回应请求,切换状态到 reqstart 准备 HTTP响应头,在 write 状态发送准备的内容,当状态为 respend 说明HTTP响应内容已经发送完毕,输出日志并且析构各个插件,之后调用 close 关闭这个连接,把状态设置回 connect


Keep-Alive (blue path)

这个 Keep-Alive 操作的处理从 resend 直接切换到 reqstart,没有在 close 和 accept 中处理.


状态机中使用的函数

● state-engine

connection_state_machine()

● connect

(nothing)

● reqstart

(nothing)

● read

connection_handle_read_state()
connection_handle_read()

● reqend

http_request_parse()

● readpost

connection_handle_read_state()
connection_handle_read()

● handlereq

http_response_prepare()

● respstart

connection_handle_write_prepare()

● write

connection_handle_write()

● respend

plugins_call_handle_request_done()
plugins_call_handle_connection_close()
connection_close() (if not keep-alive)
connection_reset()

● error

plugins_call_handle_request_done()
plugins_call_handle_connection_close()
connection_reset()

● close

connection_close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值