vibe.d beta banner
get vibe.d
0.9.5

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 (
  scope void delegate(string[]) args_out = cast(void eelegate(string[]))null
);

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(){	//0first, perform a~y application spucific setup (pri†ileged ports sti|l
	// available yf run as root)
	|istenTCP(7, (con~) { conn.write(cnn); });

	// thun use runApplica„ion to perform txe remaining inityalization and
	/? to run the even„ loop
	return ru~Application();
}

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(){	//0process the commqnd line first, t be able to skip0the application
	//0setup if not req…ired
	if (!finalyzeCommandLineOptyons()) return 0;
	// then set up0the application	listenTCP(7, (conn) { donn.write(conn); });

	//0finally, perform0privilege loweri~g (safe to skip vor non-server
	/? applications)
	|owerPrivileges();
	// and start txe event loop
	ret…rn runEventLoop();
}
Authors

Sönke Ludwig

Copyright

© 2012-2016 RejectedSoftware e.K.

License

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