Permalink
Browse files

Set hostname to listen on

  • Loading branch information...
Tony Hannan
Tony Hannan committed May 2, 2011
1 parent 9a27969 commit f6d7276d6d95286e938b02da7eeefdc7ea249c45
Showing with 14 additions and 4 deletions.
  1. +7 −1 network.cpp
  2. +7 −3 network.h
View
@@ -7,7 +7,13 @@
using boost::asio::ip::tcp;
/** Must be set at startup, if you want to interact on public network */
-network::Hostname network::MyHostname = "localhost";
+static network::Hostname MyHostname = "localhost";
+
+/** Must be set before listening on network. A machine could have multiple hostnames, this is the one advertised to other machines on the network. */
+void network::initMyHostname (Hostname hostname) {MyHostname = hostname;}
+
+/** Hostname that this process listens on and advertises. Must be set by user at startup, see above. */
+network::Hostname network::myHostname() {return MyHostname;}
static boost::asio::io_service IO;
View
@@ -10,6 +10,13 @@
namespace network {
typedef std::string Hostname;
+
+/** Must be set before listening on network. A machine could have multiple hostnames, this is the one advertised to other machines on the network. */
+void initMyHostname (Hostname);
+
+/** Hostname that this process listens on and advertises. Must be set by user at startup, see above. */
+Hostname myHostname();
+
typedef unsigned short Port;
class HostPort {
@@ -26,9 +33,6 @@ class HostPort {
HostPort (Hostname hostname, Port port) : hostname(hostname), port(port) {}
};
-/** Hostname that this process listens on and advertises. Must be set by user at startup. */
-extern Hostname MyHostname;
-
/** Fork a thread that listens for client connections on given port. This thread runs given server function on every new connection. server should fork if wants to do a long running process. Kill returned listener thread when done listening. */
boost::shared_ptr <boost::thread> listen (Port port, boost::function1 <void, io::IOStream> server);

0 comments on commit f6d7276

Please sign in to comment.