From 2c1500016690e0b78b444a52b261877d5b51e96f Mon Sep 17 00:00:00 2001 From: zhengshuxin Date: Mon, 5 Sep 2022 10:25:10 +0800 Subject: [PATCH] check if read error in HttpServlet.cpp --- lib_acl_cpp/src/http/HttpServlet.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib_acl_cpp/src/http/HttpServlet.cpp b/lib_acl_cpp/src/http/HttpServlet.cpp index 9d18e35a5..a834a80a1 100644 --- a/lib_acl_cpp/src/http/HttpServlet.cpp +++ b/lib_acl_cpp/src/http/HttpServlet.cpp @@ -241,13 +241,32 @@ bool HttpServlet::start(void) case HTTP_METHOD_OTHER: ret = doOther(*req_, *res_, method_s.c_str()); break; + case HTTP_METHOD_UNKNOWN: default: ret = false; // 有可能是IO失败或未知方法 - if (req_->getLastError() == HTTP_REQ_ERR_METHOD) { + + switch (req_->getLastError()) { + case HTTP_REQ_ERR_IO: + logger_error("read error=%s, method=%d, peer=%s, fd=%d", + last_serror(), method, + req_->getSocketStream().get_peer(true), + (int) req_->getSocketStream().sock_handle()); + break; + case HTTP_REQ_ERR_METHOD: doUnknown(*req_, *res_); - } else if (first) { + break; + default: + if (!first) { + break; + } + + logger_error("method=%d, error=%s, fd=%d", + method, last_serror(), + (int) req_->getSocketStream().sock_handle()); doError(*req_, *res_); + break; } + break; }