Nginx读取后端服务响应数据流程

gdb attach [worker进程号]

在指定文件的898行打上断点
b src/event/modules/ngx_epoll_module.c:898

客户端发送请求

按3次c以后,按n(函数单行执行)和s(函数逐行执行)单步调试

确定函数调用过程

上一步调用函数代码

下一步被调函数位置

rev->handler(rev);

src/http/ngx_http_upstream.c

ngx_http_upstream_handler

u->read_event_handler(r, u);

src/http/ngx_http_upstream.c

ngx_http_upstream_process_header

n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);

src/os/unix/ngx_recv.c

ngx_unix_recv

n = recv(c->fd, buf, size, 0);

Linux系统函数

n的值是119

具体内容是

确定响应结果开始位置

src/http/ngx_http_upstream.c

说明Nginx响应客户端body数据来自epoll_wait。

posted on 2023-01-26 21:42  王景迁  阅读(253)  评论(0编辑  收藏  举报

导航