n3rv::httpservice

class n3rv::httpservice

Inherits from n3rv::service

Public Functions

fserve_res n3rv::httpserviceserve_file(const char *path)

Opens file on host and retrieves its content.

Return
file’s content and & bool indicating if file was found.
Parameters
  • path: File’s path.

int n3rv::httpserviceinit_http(std::string http_listen_addr, int http_listen_port)

Initializes http service on listen_addr:port.

Return
0 if HTTP init went fine, -1 otherwise.
Parameters
  • http_listen_addr: IP to bind http service on.
  • http_listen_port: TCP port to bind http service on.

int n3rv::httpservicerun_http()

Starts the http service once initialized.

Return
0 if run was succesful, -1 otherwise. WARNING: run_http is blocking.

std::thread *n3rv::httpservicerun_http_async()

Starts the http service, in a dedicated thread.

Return
The created thread pointer.

int n3rv::httpserviceattach_http(std::string uri, httpcb cb)

HTTP URI Callback binding method.

Parameters
  • uri: URI address to attach callback to.
  • cb: callback pointer.

int n3rv::httpserviceregister_dir(std::string uri, std::string path)

Adds a new FS directory to recursively serve files that are inside.

Return
0 if registering went fine, < 0 otherwise.
Parameters
  • uri: root URI of files to serve.
  • path: Filesystem path of directory to serve.

Public Static Functions

static void n3rv::httpservicehttp_gen_callback(evhttp_request *req, void *objref)

General purpose callback, mainly stands for file serving.

Parameters
  • req: libevent’s request pointer.
  • objref: this backward pointer.

static void n3rv::httpservicehttp_callback(evhttp_request *req, void *objref)

Default HTTP callback (for testing and example)

Parameters
  • req: request object coming from libevent.
  • objref: Calling object’s back ref.