refactor code
This commit is contained in:
parent
b96e282aff
commit
ddd3c23ff0
|
@ -602,37 +602,41 @@ static void httpModuleDestroy(SHttpModule* http) {
|
||||||
// not free http, http freeed by ref
|
// not free http, http freeed by ref
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void httpModuleDestroy2(SHttpModule* http) {
|
||||||
|
httpModuleDestroy(http);
|
||||||
|
taosMemoryFree(http);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, uint16_t port, char* pCont,
|
static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, uint16_t port, char* pCont,
|
||||||
int32_t contLen, EHttpCompFlag flag, int64_t chanId) {
|
int32_t contLen, EHttpCompFlag flag, int64_t chanId) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
SHttpModule* load = NULL;
|
||||||
SHttpMsg* msg = httpCreateMsg(server, uri, port, pCont, contLen, flag, chanId);
|
SHttpMsg* msg = httpCreateMsg(server, uri, port, pCont, contLen, flag, chanId);
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
return terrno;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHttpModule* load = taosAcquireRef(httpRefMgt, chanId);
|
load = taosAcquireRef(httpRefMgt, chanId);
|
||||||
if (load == NULL) {
|
if (load == NULL) {
|
||||||
httpDestroyMsg(msg);
|
goto _ERROR;
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_load_8(&load->quit)) {
|
if (atomic_load_8(&load->quit)) {
|
||||||
httpDestroyMsg(msg);
|
|
||||||
taosReleaseRef(httpRefMgt, chanId);
|
|
||||||
terrno = TSDB_CODE_HTTP_MODULE_QUIT;
|
terrno = TSDB_CODE_HTTP_MODULE_QUIT;
|
||||||
return terrno;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = transAsyncSend(load->asyncPool, &(msg->q));
|
ret = transAsyncSend(load->asyncPool, &(msg->q));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
httpDestroyMsg(msg);
|
|
||||||
taosReleaseRef(httpRefMgt, chanId);
|
|
||||||
terrno = TSDB_CODE_HTTP_MODULE_QUIT;
|
terrno = TSDB_CODE_HTTP_MODULE_QUIT;
|
||||||
return terrno;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
msg = NULL;
|
||||||
|
|
||||||
taosReleaseRef(httpRefMgt, chanId);
|
_ERROR:
|
||||||
return ret;
|
httpDestroyMsg(msg);
|
||||||
|
if (load != NULL) taosReleaseRef(httpRefMgt, chanId);
|
||||||
|
return ret = terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosSendHttpReportByChan(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
int32_t taosSendHttpReportByChan(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||||
|
@ -670,15 +674,14 @@ int64_t transInitHttpChanImpl() {
|
||||||
|
|
||||||
http->connStatusTable = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
http->connStatusTable = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
if (http->connStatusTable == NULL) {
|
if (http->connStatusTable == NULL) {
|
||||||
httpModuleDestroy(http);
|
httpModuleDestroy2(http);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
http->loop = taosMemoryMalloc(sizeof(uv_loop_t));
|
http->loop = taosMemoryMalloc(sizeof(uv_loop_t));
|
||||||
if (http->loop == NULL) {
|
if (http->loop == NULL) {
|
||||||
httpModuleDestroy(http);
|
httpModuleDestroy2(http);
|
||||||
taosMemoryFree(http);
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
@ -686,24 +689,21 @@ int64_t transInitHttpChanImpl() {
|
||||||
int err = uv_loop_init(http->loop);
|
int err = uv_loop_init(http->loop);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
tError("http-report failed init uv, reason:%s", uv_strerror(err));
|
tError("http-report failed init uv, reason:%s", uv_strerror(err));
|
||||||
httpModuleDestroy(http);
|
httpModuleDestroy2(http);
|
||||||
taosMemoryFree(http);
|
|
||||||
terrno = TSDB_CODE_THIRDPARTY_ERROR;
|
terrno = TSDB_CODE_THIRDPARTY_ERROR;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
http->asyncPool = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb);
|
http->asyncPool = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb);
|
||||||
if (NULL == http->asyncPool) {
|
if (NULL == http->asyncPool) {
|
||||||
httpModuleDestroy(http);
|
httpModuleDestroy2(http);
|
||||||
taosMemoryFree(http);
|
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
http->quit = 0;
|
http->quit = 0;
|
||||||
|
|
||||||
err = taosThreadCreate(&http->thread, NULL, httpThread, (void*)http);
|
err = taosThreadCreate(&http->thread, NULL, httpThread, (void*)http);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
httpModuleDestroy(http);
|
httpModuleDestroy2(http);
|
||||||
taosMemoryFree(http);
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
@ -741,5 +741,5 @@ void taosDestroyHttpChan(int64_t chanId) {
|
||||||
httpModuleDestroy(load);
|
httpModuleDestroy(load);
|
||||||
|
|
||||||
taosReleaseRef(httpRefMgt, chanId);
|
taosReleaseRef(httpRefMgt, chanId);
|
||||||
taosReleaseRef(httpRefMgt, chanId);
|
taosRemoveRef(httpRefMgt, chanId);
|
||||||
}
|
}
|
Loading…
Reference in New Issue