MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / InitHTTPServer

Function InitHTTPServer

src/rpc/core/httpserver.cpp:372–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370}
371
372bool InitHTTPServer() {
373 if (!InitHTTPAllowList()) {
374 return false;
375 }
376
377 // Redirect libevent's logging to our own log
378 event_set_log_callback(&libevent_log_cb);
379 /*
380 // Update libevent's log handling. Returns false if our version of
381 // libevent doesn't support debug logging, in which case we should
382 // clear the BCLog::LIBEVENT flag.
383 if (!UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT))) {
384 LogInstance().DisableCategory(BCLog::LIBEVENT);
385 }
386 */
387
388#ifdef WIN32
389 evthread_use_windows_threads();
390#else
391 evthread_use_pthreads();
392#endif
393
394 raii_event_base base_ctr = obtain_event_base();
395
396 /* Create a new evhttp object to handle requests. */
397 raii_evhttp http_ctr = obtain_evhttp(base_ctr.get());
398 struct evhttp* http = http_ctr.get();
399 if (!http) {
400 LogPrint(BCLog::ERROR, "couldn't create evhttp. Exiting.\n");
401 return false;
402 }
403
404 evhttp_set_timeout(http, SysCfg().GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
405 evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE);
406 evhttp_set_max_body_size(http, MAX_SIZE);
407 evhttp_set_gencb(http, http_request_cb, nullptr);
408
409 if (!HTTPBindAddresses(http)) {
410 LogPrint(BCLog::ERROR, "Unable to bind any endpoint for RPC server\n");
411 return false;
412 }
413
414 LogPrint(BCLog::RPC, "Initialized HTTP server\n");
415 int32_t workQueueDepth = std::max<int32_t>(SysCfg().GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
416 LogPrint(BCLog::RPC, "HTTP: creating work queue of depth %d\n", workQueueDepth);
417
418 workQueue = new WorkQueue<HTTPClosure>(workQueueDepth);
419 // transfer ownership to eventBase/HTTP via .release()
420 eventBase = base_ctr.release();
421 eventHTTP = http_ctr.release();
422 return true;
423}
424
425void FinalizeHTTPServer() {
426#if LIBEVENT_VERSION_NUMBER >= 0x02010100

Callers 1

StartRPCServerFunction · 0.85

Calls 7

InitHTTPAllowListFunction · 0.85
obtain_event_baseFunction · 0.85
obtain_evhttpFunction · 0.85
HTTPBindAddressesFunction · 0.85
GetArgMethod · 0.80
releaseMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected