elog to util; parser.data.pos

This commit is contained in:
freemine 2020-08-01 10:59:12 +08:00
parent 521d7c1519
commit d9c04b18e9
4 changed files with 34 additions and 4 deletions

View File

@ -55,6 +55,7 @@ static void httpRemoveContextFromEpoll(HttpContext *pContext) {
static void httpDestroyContext(void *data) { static void httpDestroyContext(void *data) {
HttpContext *pContext = *(HttpContext **)data; HttpContext *pContext = *(HttpContext **)data;
D("==context[%p] destroyed==", pContext);
if (pContext->fd > 0) tclose(pContext->fd); if (pContext->fd > 0) tclose(pContext->fd);
HttpThread *pThread = pContext->pThread; HttpThread *pThread = pContext->pThread;
@ -80,6 +81,7 @@ bool httpInitContexts() {
httpError("failed to init context cache"); httpError("failed to init context cache");
return false; return false;
} }
D("==cache [%p] created==", tsHttpServer.contextCache);
return true; return true;
} }
@ -120,6 +122,8 @@ HttpContext *httpCreateContext(int32_t fd) {
HttpContext *pContext = calloc(1, sizeof(HttpContext)); HttpContext *pContext = calloc(1, sizeof(HttpContext));
if (pContext == NULL) return NULL; if (pContext == NULL) return NULL;
D("==context[%p] created==", pContext);
pContext->fd = fd; pContext->fd = fd;
pContext->httpVersion = HTTP_VERSION_10; pContext->httpVersion = HTTP_VERSION_10;
pContext->lastAccessTime = taosGetTimestampSec(); pContext->lastAccessTime = taosGetTimestampSec();
@ -209,6 +213,7 @@ bool httpInitContext(HttpContext *pContext) {
} }
void httpCloseContextByApp(HttpContext *pContext) { void httpCloseContextByApp(HttpContext *pContext) {
D("==");
pContext->parsed = false; pContext->parsed = false;
bool keepAlive = true; bool keepAlive = true;
@ -220,6 +225,7 @@ void httpCloseContextByApp(HttpContext *pContext) {
} }
if (keepAlive) { if (keepAlive) {
D("==keepAlive==");
if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_READY)) { if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_READY)) {
httpDebug("context:%p, fd:%d, ip:%s, last state:handling, keepAlive:true, reuse context", pContext, pContext->fd, httpDebug("context:%p, fd:%d, ip:%s, last state:handling, keepAlive:true, reuse context", pContext, pContext->fd,
pContext->ipstr); pContext->ipstr);
@ -240,6 +246,7 @@ void httpCloseContextByApp(HttpContext *pContext) {
pContext->ipstr, httpContextStateStr(pContext->state), pContext->state); pContext->ipstr, httpContextStateStr(pContext->state), pContext->state);
} }
} else { } else {
D("==not keepAlive==");
httpRemoveContextFromEpoll(pContext); httpRemoveContextFromEpoll(pContext);
httpDebug("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:false, close context", pContext, pContext->fd, httpDebug("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:false, close context", pContext, pContext->fd,
pContext->ipstr, httpContextStateStr(pContext->state), pContext->state); pContext->ipstr, httpContextStateStr(pContext->state), pContext->state);
@ -365,9 +372,7 @@ static void on_body(void *arg, const char *chunk, size_t len) {
if (pParser->failed) return; if (pParser->failed) return;
if (!pContext->parsed) { if (pParser->data.pos == 0) pParser->data.pos = pParser->pLast;
pContext->parsed = true;
}
A("not implemented yet"); A("not implemented yet");
} }
@ -378,6 +383,8 @@ static void on_end(void *arg) {
if (pParser->failed) return; if (pParser->failed) return;
if (pParser->data.pos == 0) pParser->data.pos = pParser->pLast;
if (!pContext->parsed) { if (!pContext->parsed) {
pContext->parsed = true; pContext->parsed = true;
} }

View File

@ -138,7 +138,7 @@ static bool httpDecompressData(HttpContext *pContext) {
} }
static bool httpReadData(HttpContext *pContext) { static bool httpReadData(HttpContext *pContext) {
if (1) return ehttpReadData(pContext); if (0) return ehttpReadData(pContext);
if (!pContext->parsed) { if (!pContext->parsed) {
httpInitContext(pContext); httpInitContext(pContext);
@ -447,6 +447,29 @@ static bool ehttpReadData(HttpContext *pContext) {
httpNotifyContextClose(pContext); httpNotifyContextClose(pContext);
return false; return false;
} }
if (pContext->parsed) {
int ret = httpCheckReadCompleted(pContext);
if (ret == HTTP_CHECK_BODY_CONTINUE) {
//httpDebug("context:%p, fd:%d, ip:%s, not finished yet, wait another event", pContext, pContext->fd, pContext->ipstr);
httpReleaseContext(pContext);
return false;
} else if (ret == HTTP_CHECK_BODY_SUCCESS){
httpDebug("context:%p, fd:%d, ip:%s, thread:%s, read size:%d, dataLen:%d",
pContext, pContext->fd, pContext->ipstr, pContext->pThread->label, pContext->parser.bufsize, pContext->parser.data.len);
if (httpDecompressData(pContext)) {
return true;
} else {
httpNotifyContextClose(pContext);
httpReleaseContext(pContext);
return false;
}
} else {
httpError("context:%p, fd:%d, ip:%s, failed to read http body, close connect", pContext, pContext->fd, pContext->ipstr);
httpNotifyContextClose(pContext);
httpReleaseContext(pContext);
return false;
}
}
return pContext->parsed; return pContext->parsed;
} else if (nread < 0) { } else if (nread < 0) {
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {