diff options
| -rw-r--r-- | ychat/src/sock/context.cpp | 2 | ||||
| -rw-r--r-- | ychat/src/sock/sock.cpp | 27 |
2 files changed, 19 insertions, 10 deletions
diff --git a/ychat/src/sock/context.cpp b/ychat/src/sock/context.cpp index 0e57fed..11af016 100644 --- a/ychat/src/sock/context.cpp +++ b/ychat/src/sock/context.cpp @@ -37,6 +37,8 @@ context::context(sock *p_sock, struct event *p_event, int i_fd) this->i_fd = i_fd; this->i_buf_len = 0; this->c_buf[0] = '\0'; + this->p_map_params = NULL; + this->p_response = NULL; this->p_user = NULL; } diff --git a/ychat/src/sock/sock.cpp b/ychat/src/sock/sock.cpp index 9202902..bf733e7 100644 --- a/ychat/src/sock/sock.cpp +++ b/ychat/src/sock/sock.cpp @@ -35,6 +35,7 @@ #include "sock.h" #include "../tool/tool.h" +#include "context.h" using namespace std; @@ -311,13 +312,17 @@ sock::handle_client_read(int i_fd, short event, void *p_arg) if (i_hdr_end == string::npos) { - // Headers not fully received yet. Guard against oversized header - // floods: if the buffer is already full with no header terminator, the - // request can never be completed - drop it (no re-arm) rather than spin. - // The fd leaks for that one abusive request (see the body branch below); - // preferable to a crash/spin. + // Headers not fully received yet. If the buffer is already full with + // no header terminator (oversized header flood) the request can never + // complete: drop it now (same pattern as the EOF/error branches) rather + // than spin. Otherwise wait for the rest. if ( p_context->i_buf_len < READSOCK ) event_add(p_context->p_event, NULL); + else + { + p_context->del_event(); + delete p_context; + } return; } @@ -332,13 +337,15 @@ sock::handle_client_read(int i_fd, short event, void *p_arg) if (i_have < i_content_len) { // Body still incomplete. If the buffer is already full the body - // can never fit (oversized POST): drop the request without re-arming - // (re-arming a full buffer would spin, and deleting the context - // inside this read callback corrupts libevent). The fd leaks for - // that one abusive request — acceptable for a toy chat and far - // better than a crash/spin. Otherwise wait for the rest. + // can never fit (oversized POST): drop it now (same pattern as the + // EOF/error branches) rather than spin. Otherwise wait for the rest. if ( p_context->i_buf_len < READSOCK ) event_add(p_context->p_event, NULL); + else + { + p_context->del_event(); + delete p_context; + } return; } } |
