From: <av...@us...> - 2011-04-11 13:41:25
|
Revision: 7297 http://openhpi.svn.sourceforge.net/openhpi/?rev=7297&view=rev Author: avpak Date: 2011-04-11 13:41:18 +0000 (Mon, 11 Apr 2011) Log Message: ----------- Feature request #3094859 Modified Paths: -------------- openhpi/trunk/openhpid/openhpid-posix.cpp openhpi/trunk/openhpid/openhpid-win32.cpp openhpi/trunk/openhpid/server.cpp openhpi/trunk/openhpid/server.h openhpi/trunk/transport/strmsock.cpp openhpi/trunk/transport/strmsock.h Modified: openhpi/trunk/openhpid/openhpid-posix.cpp =================================================================== --- openhpi/trunk/openhpid/openhpid-posix.cpp 2011-04-06 12:08:34 UTC (rev 7296) +++ openhpi/trunk/openhpid/openhpid-posix.cpp 2011-04-11 13:41:18 UTC (rev 7297) @@ -49,9 +49,10 @@ static gchar *cfgfile = NULL; static gboolean verbose_flag = FALSE; +static gchar *bindaddr = NULL; static gint port = OPENHPI_DEFAULT_DAEMON_PORT; static gchar *portstr = NULL; -static gchar *optpidfile = NULL; +static gchar *optpidfile = NULL; static gint sock_timeout = 0; // unlimited -- TODO: unlimited or 30 minutes default? was unsigned int static gint max_threads = -1; // unlimited static gboolean runasforeground = FALSE; @@ -67,8 +68,13 @@ " configuration file.", "conf_file" }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag, "This option causes the daemon to display verbose\n" " messages. This option is optional.", NULL }, + { "bind", 'b', 0, G_OPTION_ARG_STRING, &bindaddr, "Bind address for the daemon socket.\n" + " Also bind address can be specified with\n" + " OPENHPI_DAEMON_BIND_ADDRESS environment variable.\n" + " No bind address is used by default.", "bind_address" }, { "port", 'p', 0, G_OPTION_ARG_STRING, &portstr, "Overrides the default listening port (4743) of\n" " the daemon. The option is optional.", "port" }, + { "pidfile", 'f', 0, G_OPTION_ARG_FILENAME, &optpidfile, "Overrides the default path/name for the daemon.\n" " pid file. The option is optional.", "pidfile" }, { "timeout", 's', 0, G_OPTION_ARG_INT, &sock_timeout, "Overrides the default socket read timeout of 30\n" @@ -111,6 +117,10 @@ printf(" configuration file.\n"); printf(" -v, --verbose This option causes the daemon to display verbose\n"); printf(" messages. This option is optional.\n"); + printf(" -b, --bind Sets bind address for the daemon socket.\n"); + printf(" Also bind address can be specified with\n"); + printf(" OPENHPI_DAEMON_BIND_ADDRESS environment variable.\n"); + printf(" No bind address is used by default.\n"); printf(" -p, --port=port Overrides the default listening port (4743) of\n"); printf(" the daemon. The option is optional.\n"); printf(" -f, --pidfile=pidfile Overrides the default path/name for the daemon.\n"); @@ -314,25 +324,43 @@ exit(-1); } + if (cfgfile) { + setenv("OPENHPI_CONF", cfgfile, 1); + } else { + cfgfile = getenv("OPENHPI_CONF"); + } + if (bindaddr) { + setenv("OPENHPI_DAEMON_BIND_ADDRESS", bindaddr, 1); + } else { + bindaddr = getenv("OPENHPI_DAEMON_BIND_ADDRESS"); + } if (portstr) { setenv("OPENHPI_DAEMON_PORT", portstr, 1); + } else { + portstr = getenv("OPENHPI_DAEMON_PORT"); + } + if (portstr) { port = atoi(portstr); } - if (cfgfile) setenv("OPENHPI_CONF", cfgfile, 1); + if (enableIPv4) { + ipvflags |= FlagIPv4; + } + if (enableIPv6) { + ipvflags |= FlagIPv6; + } + if (ipvflags == 0) { + ipvflags = FlagIPv4; + } + if (optpidfile) { + pidfile = g_strdup(optpidfile); + } - if (enableIPv4) ipvflags |= FlagIPv4; - if (enableIPv6) ipvflags |= FlagIPv6; - if (ipvflags == 0) ipvflags = FlagIPv4; - if (optpidfile) pidfile = g_strdup(optpidfile); - - // see if any invalid parameters are given if (sock_timeout<0) { CRIT("Socket timeout value must be positive. Exiting."); display_help(); } - // see if we have a valid configuration file if ((!cfgfile) || (!g_file_test(cfgfile, G_FILE_TEST_EXISTS))) { CRIT("Cannot find configuration file. Exiting."); @@ -365,15 +393,20 @@ // announce ourselves INFO("%s version %s started.", argv[0], VERSION); - if (cfgfile) INFO("OPENHPI_CONF = %s.", cfgfile); - INFO("OPENHPI_DAEMON_PORT = %u", port); - INFO("Enabled IP versions:%s%s\n", + if (cfgfile) { + INFO("OPENHPI_CONF = %s.", cfgfile); + } + if (bindaddr) { + INFO("OPENHPI_DAEMON_BIND_ADDRESS = %s.", bindaddr); + } + INFO("OPENHPI_DAEMON_PORT = %u.", port); + INFO("Enabled IP versions:%s%s.\n", (ipvflags & FlagIPv4) ? " IPv4" : "", (ipvflags & FlagIPv6) ? " IPv6" : ""); - INFO("Max threads: %d\n", max_threads); - INFO("Socket timeout(sec): %d\n", sock_timeout); + INFO("Max threads: %d.\n", max_threads); + INFO("Socket timeout(sec): %d.\n", sock_timeout); - bool rc = oh_server_run(ipvflags, port, sock_timeout, max_threads); + bool rc = oh_server_run(ipvflags, bindaddr, port, sock_timeout, max_threads); if (!rc) { return 9; } Modified: openhpi/trunk/openhpid/openhpid-win32.cpp =================================================================== --- openhpi/trunk/openhpid/openhpid-win32.cpp 2011-04-06 12:08:34 UTC (rev 7296) +++ openhpi/trunk/openhpid/openhpid-win32.cpp 2011-04-11 13:41:18 UTC (rev 7297) @@ -35,6 +35,7 @@ /*--------------------------------------------------------------------*/ static gchar *cfgfile = NULL; static gboolean verbose_flag = FALSE; +static gchar *bindaddr = NULL; static gint port = OPENHPI_DEFAULT_DAEMON_PORT; static gchar *portstr = NULL; static gint sock_timeout = 0; // unlimited -- TODO: unlimited or 30 minutes default? was unsigned int @@ -52,6 +53,10 @@ " configuration file.", "conf_file" }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag, "This option causes the daemon to display verbose\n" " messages. This option is optional.", NULL }, + { "bind", 'b', 0, G_OPTION_ARG_STRING, &bindaddr, "Bind address for the daemon socket.\n" + " Also bind address can be specified with\n" + " OPENHPI_DAEMON_BIND_ADDRESS environment variable.\n" + " No bind address is used by default.", "bind_address" }, { "port", 'p', 0, G_OPTION_ARG_STRING, &portstr, "Overrides the default listening port (4743) of\n" " the daemon. The option is optional.", "port" }, { "timeout", 's', 0, G_OPTION_ARG_INT, &sock_timeout, "Overrides the default socket read timeout of 30\n" @@ -93,6 +98,10 @@ printf(" configuration file.\n"); printf(" -v, --verbose This option causes the daemon to display verbose\n"); printf(" messages. This option is optional.\n"); + printf(" -b, --bind Sets bind address for the daemon socket.\n"); + printf(" Also bind address can be specified with\n"); + printf(" OPENHPI_DAEMON_BIND_ADDRESS environment variable.\n"); + printf(" No bind address is used by default.\n"); printf(" -p, --port=port Overrides the default listening port (4743) of\n"); printf(" the daemon. The option is optional.\n"); printf(" -s, --timeout=seconds Overrides the default socket read timeout of 30\n"); @@ -187,16 +196,34 @@ exit(-1); } + if (cfgfile) { + setenv("OPENHPI_CONF", cfgfile); + } else { + cfgfile = getenv("OPENHPI_CONF"); + } + if (bindaddr) { + setenv("OPENHPI_DAEMON_BIND_ADDRESS", bindaddr); + } else { + bindaddr = getenv("OPENHPI_DAEMON_BIND_ADDRESS"); + } if (portstr) { setenv("OPENHPI_DAEMON_PORT", portstr); + } else { + portstr = getenv("OPENHPI_DAEMON_PORT"); + } + if (portstr) { port = atoi(portstr); } - if (cfgfile) setenv("OPENHPI_CONF", cfgfile); + if (enableIPv4) { + ipvflags |= FlagIPv4; + } + if (enableIPv6) { + ipvflags |= FlagIPv6; + } + if (ipvflags == 0) { + ipvflags = FlagIPv4; + } - if (enableIPv4) ipvflags |= FlagIPv4; - if (enableIPv6) ipvflags |= FlagIPv6; - if (ipvflags == 0) ipvflags = FlagIPv4; - // see if any invalid parameters are given if (sock_timeout<0) { CRIT("Socket timeout value must be positive. Exiting."); @@ -217,15 +244,20 @@ // announce ourselves INFO("%s version %s started.", argv[0], VERSION); - if (cfgfile) INFO("OPENHPI_CONF = %s.", cfgfile); + if (cfgfile) { + INFO("OPENHPI_CONF = %s.", cfgfile); + } + if (bindaddr) { + INFO("OPENHPI_DAEMON_BIND_ADDRESS = %s.", bindaddr); + } INFO("OPENHPI_DAEMON_PORT = %u.", port); INFO("Enabled IP versions:%s%s\n", (ipvflags & FlagIPv4) ? " IPv4" : "", (ipvflags & FlagIPv6) ? " IPv6" : ""); - INFO("Max threads: %d\n", max_threads); - INFO("Socket timeout(sec): %d\n", sock_timeout); + INFO("Max threads: %d.\n", max_threads); + INFO("Socket timeout(sec): %d.\n", sock_timeout); - bool rc = oh_server_run(ipvflags, port, sock_timeout, max_threads); + bool rc = oh_server_run(ipvflags, bindaddr, port, sock_timeout, max_threads); if (!rc) { return 9; } Modified: openhpi/trunk/openhpid/server.cpp =================================================================== --- openhpi/trunk/openhpid/server.cpp 2011-04-06 12:08:34 UTC (rev 7296) +++ openhpi/trunk/openhpid/server.cpp 2011-04-11 13:41:18 UTC (rev 7297) @@ -76,13 +76,14 @@ /*--------------------------------------------------------------------*/ bool oh_server_run( int ipvflags, + const char * bindaddr, uint16_t port, unsigned int sock_timeout, int max_threads ) { // create the server socket cServerStreamSock ssock; - if (!ssock.Create(ipvflags, port)) { + if (!ssock.Create(ipvflags, bindaddr, port)) { CRIT("Error creating server socket. Exiting."); return false; } Modified: openhpi/trunk/openhpid/server.h =================================================================== --- openhpi/trunk/openhpid/server.h 2011-04-06 12:08:34 UTC (rev 7296) +++ openhpi/trunk/openhpid/server.h 2011-04-11 13:41:18 UTC (rev 7297) @@ -23,6 +23,7 @@ bool oh_server_run( int ipvflags, + const char * bindaddr, uint16_t port, unsigned int sock_timeout, int max_threads ); Modified: openhpi/trunk/transport/strmsock.cpp =================================================================== --- openhpi/trunk/transport/strmsock.cpp 2011-04-06 12:08:34 UTC (rev 7296) +++ openhpi/trunk/transport/strmsock.cpp 2011-04-11 13:41:18 UTC (rev 7297) @@ -276,6 +276,8 @@ return true; } + // TODO shutdown + int cc; #ifdef _WIN32 cc = closesocket( m_sockfd ); @@ -403,13 +405,13 @@ // empty } -bool cServerStreamSock::Create( int ipvflags, uint16_t port ) +bool cServerStreamSock::Create( int ipvflags, const char * bindaddr, uint16_t port ) { bool bound = false; struct addrinfo * info; std::list<struct addrinfo *> infos; - SelectAddresses( ipvflags, AI_PASSIVE, 0, port, infos ); + SelectAddresses( ipvflags, AI_PASSIVE, bindaddr, port, infos ); while ( !infos.empty() ) { info = *infos.begin(); Modified: openhpi/trunk/transport/strmsock.h =================================================================== --- openhpi/trunk/transport/strmsock.h 2011-04-06 12:08:34 UTC (rev 7296) +++ openhpi/trunk/transport/strmsock.h 2011-04-11 13:41:18 UTC (rev 7297) @@ -162,7 +162,7 @@ explicit cServerStreamSock(); ~cServerStreamSock(); - bool Create( int ipvflags, uint16_t port ); + bool Create( int ipvflags, const char * bindaddr, uint16_t port ); cStreamSock * Accept(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |