Using helper macro instead of main()
This library includes functions to simplify startup.
- printgnu() Displays a standard message on the console at startup.
- daemonize() Forks and exits the process to run it in the background.
- lockpidfile() Creates a file that contains the pid and locks it.
- seedrand() Seed the random number generator.
- sslstartup() Start open ssl.
- Install a default signal handler and use a callback to handle signals (Not supported on WIN32).
These are all wrapped up in a macro FRAMEWORK_MAIN() that replaces main(). This is done by implementing main creating a callback initialising the services and calling the callback
FRAMEWORK_MAIN(
"Socket Client/Server Echo (TCP/TLS/UDP/DTLS)",
"Gregory Hinton Nietsky",
"gregory@distrotech.co.za",
if (argc < 3) {
#ifndef __WIN32
printf("Requires arguments %s [tcp|tls|udp|dtls|unix_d|unix_s] [ipaddr|socket]\n", argv[0]);
#else
printf("Requires arguments %s [tcp|tls|udp|dtls] ipaddr\n", argv[0]);
#endif
return (-1);
}
As you can see this macro has replaced main() you have access to the arg count and arg list as usual via argc / argv.
Various flags control the behaviour in this case daemonize was run after the args have been checked.
- See Also
- framework_flags
-
framework_init()
-
framework_mkcore()
- Warning
- memory allocated by framework_mkcore() is only released by framework_init() always call framework_mkcore() first and always call framework_init() when calling framework_mkcore().