scheduler cause high CPU usage in syslog

This commit is contained in:
lxsang 2020-08-31 08:24:21 +02:00
parent 883ef9c3a3
commit e38cd9de1b
3 changed files with 505 additions and 439 deletions

Binary file not shown.

View File

@ -92,7 +92,6 @@ static const char* S_510 = "Not Extended";
static const char *S_511 = "Network Authentication Required"; static const char *S_511 = "Network Authentication Required";
static const char *S_UNOF = "Unofficial Status"; static const char *S_UNOF = "Unofficial Status";
int require_plugin(const char *name) int require_plugin(const char *name)
{ {
UNUSED(name); UNUSED(name);
@ -131,73 +130,136 @@ const char* get_status_str(int stat)
{ {
switch (stat) switch (stat)
{ {
case 100: return S_100; case 100:
case 101: return S_101; return S_100;
case 102: return S_102; case 101:
case 103: return S_103; return S_101;
case 102:
return S_102;
case 103:
return S_103;
case 200: return S_200; case 200:
case 201: return S_201; return S_200;
case 202: return S_202; case 201:
case 203: return S_203; return S_201;
case 204: return S_204; case 202:
case 205: return S_205; return S_202;
case 206: return S_206; case 203:
case 207: return S_207; return S_203;
case 208: return S_208; case 204:
case 226: return S_226; return S_204;
case 205:
return S_205;
case 206:
return S_206;
case 207:
return S_207;
case 208:
return S_208;
case 226:
return S_226;
case 300: return S_300; case 300:
case 301: return S_301; return S_300;
case 302: return S_302; case 301:
case 303: return S_303; return S_301;
case 304: return S_304; case 302:
case 305: return S_305; return S_302;
case 306: return S_306; case 303:
case 307: return S_307; return S_303;
case 308: return S_308; case 304:
return S_304;
case 305:
return S_305;
case 306:
return S_306;
case 307:
return S_307;
case 308:
return S_308;
case 400: return S_400; case 400:
case 401: return S_401; return S_400;
case 402: return S_402; case 401:
case 403: return S_403; return S_401;
case 404: return S_404; case 402:
case 405: return S_405; return S_402;
case 406: return S_406; case 403:
case 407: return S_407; return S_403;
case 408: return S_408; case 404:
case 409: return S_409; return S_404;
case 410: return S_410; case 405:
case 411: return S_411; return S_405;
case 412: return S_412; case 406:
case 413: return S_413; return S_406;
case 414: return S_414; case 407:
case 415: return S_415; return S_407;
case 416: return S_416; case 408:
case 417: return S_417; return S_408;
case 421: return S_421; case 409:
case 422: return S_422; return S_409;
case 423: return S_423; case 410:
case 424: return S_424; return S_410;
case 425: return S_425; case 411:
case 426: return S_426; return S_411;
case 428: return S_428; case 412:
case 429: return S_429; return S_412;
case 431: return S_431; case 413:
case 451: return S_451; return S_413;
case 414:
return S_414;
case 415:
return S_415;
case 416:
return S_416;
case 417:
return S_417;
case 421:
return S_421;
case 422:
return S_422;
case 423:
return S_423;
case 424:
return S_424;
case 425:
return S_425;
case 426:
return S_426;
case 428:
return S_428;
case 429:
return S_429;
case 431:
return S_431;
case 451:
return S_451;
case 500: return S_500; case 500:
case 501: return S_501; return S_500;
case 502: return S_502; case 501:
case 503: return S_503; return S_501;
case 504: return S_504; case 502:
case 505: return S_505; return S_502;
case 506: return S_506; case 503:
case 507: return S_507; return S_503;
case 508: return S_508; case 504:
case 510: return S_510; return S_504;
case 511: return S_511; case 505:
default: return S_UNOF; return S_505;
case 506:
return S_506;
case 507:
return S_507;
case 508:
return S_508;
case 510:
return S_510;
case 511:
return S_511;
default:
return S_UNOF;
} }
} }
@ -297,7 +359,6 @@ void octstream(void* client, char* name)
//Content-Disposition: attachment; filename="fname.ext" //Content-Disposition: attachment; filename="fname.ext"
}*/ }*/
int antd_send(void *src, const void *data_in, int len_in) int antd_send(void *src, const void *data_in, int len_in)
{ {
uint8_t *data = (uint8_t *)data_in; uint8_t *data = (uint8_t *)data_in;
@ -482,7 +543,8 @@ int antd_send(void *src, const void* data_in, int len_in)
} }
int antd_recv(void *src, void *data, int len) int antd_recv(void *src, void *data, int len)
{ {
if(!src) return -1; if (!src)
return -1;
int read = 0; int read = 0;
char *ptr = NULL; char *ptr = NULL;
int received = 0; int received = 0;
@ -644,7 +706,8 @@ int antd_recv(void *src, void* data, int len)
}*/ }*/
return read; return read;
} }
void set_nonblock(int socket) { void set_nonblock(int socket)
{
int flags; int flags;
flags = fcntl(socket, F_GETFL, 0); flags = fcntl(socket, F_GETFL, 0);
//assert(flags != -1); //assert(flags != -1);
@ -659,7 +722,8 @@ void set_nonblock(int socket) {
}*/ }*/
int antd_close(void *src) int antd_close(void *src)
{ {
if(!src) return -1; if (!src)
return -1;
antd_client_t *source = (antd_client_t *)src; antd_client_t *source = (antd_client_t *)src;
#ifdef USE_ZLIB #ifdef USE_ZLIB
//TODO: send finish data to the socket before quit //TODO: send finish data to the socket before quit
@ -677,7 +741,8 @@ int antd_close(void* src)
} }
#endif #endif
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
if(source->ssl){ if (source->ssl)
{
//printf("SSL:Shutdown ssl\n"); //printf("SSL:Shutdown ssl\n");
//SSL_shutdown((SSL*) source->ssl); //SSL_shutdown((SSL*) source->ssl);
SSL_set_shutdown((SSL *)source->ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); SSL_set_shutdown((SSL *)source->ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
@ -767,7 +832,8 @@ int __f(void* client, const char* file)
while (!feof(ptr)) while (!feof(ptr))
{ {
size = fread(buffer, 1, BUFFLEN, ptr); size = fread(buffer, 1, BUFFLEN, ptr);
if(antd_send(client,buffer,size) == -1) return 0; if (antd_send(client, buffer, size) == -1)
return 0;
} }
fclose(ptr); fclose(ptr);
return 1; return 1;
@ -832,12 +898,13 @@ void antd_error(void* client, int status, const char* msg)
} }
} }
int ws_enable(dictionary_t dic) int ws_enable(dictionary_t dic)
{ {
if(!dic) return 0; if (!dic)
return 0;
char *v = (char *)dvalue(dic, "__web_socket__"); char *v = (char *)dvalue(dic, "__web_socket__");
if(!v) return 0; if (!v)
return 0;
return atoi(v) == 1; return atoi(v) == 1;
} }

View File

@ -269,7 +269,6 @@ void antd_execute_task(antd_scheduler_t* scheduler, antd_task_item_t taski)
if(!taski) if(!taski)
return; return;
// execute the task // execute the task
LOG("Execute task with priority: %d", taski->task->priority);
void *ret = (*(taski->task->handle))(taski->task->data); void *ret = (*(taski->task->handle))(taski->task->data);
// check the return data if it is a new task // check the return data if it is a new task
if(!ret) if(!ret)