vibe.d beta banner
get vibe.d
0.10.0

Asynchronous I/O that doesn’t get in your way, written in D

Function runApplication

Performs final initialization and runs the event loop.

int runApplication (
  string[]* args_out = null
) @safe;

This function performs three tasks:

  1. Makes sure that no unrecognized command line options are passed to the application and potentially displays command line help. See also finalizeCommandLineOptions.
  2. Performs privilege lowering if required.
  3. Runs the event loop and blocks until it finishes.

Parameters

NameDescription
args_out Optional parameter to receive unrecognized command line arguments. If left to null, an error will be reported if any unrecognized argument is passed.

See also

finalizeCommandLineOptions, lowerPrivileges, runEventLoop

Example

A simple echo server, listening on a privileged TCP port.

import vibe.core.core;
import vibe.core.net;

int main()
{
	// first, perform any application specific setup (privileged ports still
	// available if run as root)
	listenTCP(7, (conn) {
		try conn.write(conn);
		catch (Exception e) { /* log error */ }
	});

	// then use runApplication to perform the remaining initialization and
	// to run the event loop
	return runApplication();
}

Example

The same as above, but performing the initialization sequence manually.

This allows to skip any additional initialization (opening the listening port) if an invalid command line argument or the --help switch is passed to the application.

import vibe.core.core;
import vibe.core.net;

int main()
{
	// process the command line first, to be able to skip the application
	// setup if not required
	if (!finalizeCommandLineOptions()) return 0;

	// then set up the application
	listenTCP(7, (conn) {
		try conn.write(conn);
		catch (Exception e) { /* log error */ }
	});

	// finally, perform privilege lowering (safe to skip for non-server
	// applications)
	lowerPrivileges();

	// and start the event loop
	return runEventLoop();
}
Authors

Sönke Ludwig

Copyright

© 2012-2019 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.