Exemplo n.º 1
0
int InitComms ()
  {
  struct sockaddr_in sa;
    
  try
    {
  
    // Create the control socket
    if ( (iControl = socket (AF_INET, SOCK_STREAM, 0)) == -1)
      throw std::runtime_error ("creating control socket");
    
    // make sure socket doesn't block
    if (fcntl( iControl, F_SETFL, FNDELAY ) == -1)
      throw std::runtime_error ("fcntl on control socket");
  
    struct linger ld = linger ();  // zero it
  
    // Don't allow closed sockets to linger
    if (setsockopt( iControl, SOL_SOCKET, SO_LINGER,
                    (char *) &ld, sizeof ld ) == -1)
      throw std::runtime_error ("setsockopt (SO_LINGER)");

    int x = 1;

    // Allow address reuse 
    if (setsockopt( iControl, SOL_SOCKET, SO_REUSEADDR,
                   (char *) &x, sizeof x ) == -1)
      throw std::runtime_error ("setsockopt (SO_REUSEADDR)");
    
    sa.sin_family       = AF_INET;
    sa.sin_port         = htons (PORT);
    sa.sin_addr.s_addr  = INADDR_ANY;   /* change to listen on a specific adapter */
  
    // bind the socket to our connection port
    if ( bind (iControl, (struct sockaddr *) &sa, sizeof sa) == -1)
      throw std::runtime_error ("bind");
    
    // listen for connections
  
    if (listen (iControl, SOMAXCONN) == -1)   // SOMAXCONN is the backlog count
      throw std::runtime_error ("listen");
  
    tLastMessage = time (NULL);
    }  // end of try block
    
  // problem?
  catch (std::runtime_error & e)
    {
    std::cerr << "Cannot initialise comms ..." << std::endl;
    perror (e.what ());
    return 1;    
    }

  // standard termination signals
  signal (SIGINT,  bailout);
  signal (SIGTERM, bailout);
  signal (SIGHUP,  bailout);

  return 0;
  }   /* end of InitComms */
Exemplo n.º 2
0
void playsingle_controller::maybe_linger()
{
	// mouse_handler expects at least one team for linger mode to work.
	assert(is_regular_game_end());
	if (get_end_level_data_const().transient.linger_mode && !gamestate().board_.teams().empty()) {
		linger();
	}
}
Exemplo n.º 3
0
void playsingle_controller::maybe_linger()
{
    //Make sure [end_level_data] gets writen into the snapshot even when skipping linger mode.
    linger_ = true;
    if (get_end_level_data_const().transient.linger_mode) {
        linger();
    }
}
Exemplo n.º 4
0
void
freeSupervisor(Definition def, Code codes, int do_linger)
{ size_t size = (size_t)codes[-1];

  if ( size > 0 )		/* 0: built-in, see initSupervisors() */
  { if ( do_linger )
      linger(&def->lingering, free_codes_ptr, codes);
    else
      freeHeap(&codes[-1], (size+1)*sizeof(code));
  }
}
Exemplo n.º 5
0
void playmp_controller::maybe_linger()
{
	linger_ = true;
	if (!get_end_level_data_const().transient.linger_mode) {
		if(!is_host()) {
			// If we continue without lingering we need to
			// make sure the host uploads the next scenario
			// before we attempt to download it.
			wait_for_upload();
		}
	} else {
		linger();
	}
}
Exemplo n.º 6
0
void playmp_controller::maybe_linger()
{
	// mouse_handler expects at least one team for linger mode to work.
	assert(is_regular_game_end());
	if (!get_end_level_data_const().transient.linger_mode || gamestate().board_.teams().empty()) {
		if(!is_host()) {
			// If we continue without lingering we need to
			// make sure the host uploads the next scenario
			// before we attempt to download it.
			wait_for_upload();
		}
	} else {
		linger();
	}
}
Exemplo n.º 7
0
void play_controller::hotkey_handler::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp)
{
	if (context_menu)
	{
		last_context_menu_x_ = xloc;
		last_context_menu_y_ = yloc;
	}

	std::vector<std::string> items = items_arg;
	const hotkey::hotkey_command* cmd;
	std::vector<std::string>::iterator i = items.begin();
	while(i != items.end()) {
		if (*i == "AUTOSAVES") {
			// Autosave visibility is similar to LOAD_GAME hotkey
			cmd = &hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_LOAD_GAME);
		} else {
			cmd = &hotkey::get_hotkey_command(*i);
		}
		// Remove WML commands if they would not be allowed here
		if(*i == "wml") {
			if(!context_menu || !viewing_team_is_playing()
			|| events::commands_disabled || !viewing_team().is_local_human()
			|| (linger() && !game_config::debug)){
				i = items.erase(i);
				continue;
			}
		// Remove commands that can't be executed or don't belong in this type of menu
		} else if(!can_execute_command(*cmd)
			|| (context_menu && !in_context_menu(cmd->id))) {
			i = items.erase(i);
			continue;
		}
		++i;
	}

	// Add special non-hotkey items to the menu and remember their indices
	expand_autosaves(items);
	expand_wml_commands(items);

	if(items.empty())
		return;

	command_executor::show_menu(items, xloc, yloc, context_menu, disp);
}
Exemplo n.º 8
0
int main ()
{
    int rc;

    rc = hwm ();
    assert (rc == 0);
    rc = invalid_rep ();
    assert (rc == 0);
    rc = linger ();
    assert (rc == 0);
    rc = msg_flags ();
    assert (rc == 0);
    rc = pair_inproc ();
    assert (rc == 0);
    rc = pair_ipc ();
    assert (rc == 0);
    rc = reconnect ();
    assert (rc == 0);
    rc = reqrep_device ();
    assert (rc == 0);
    rc = reqrep_inproc ();
    assert (rc == 0);
    rc = reqrep_ipc ();
    assert (rc == 0);
    rc = reqrep_tcp ();
    assert (rc == 0);
    rc = shutdown_stress ();
    assert (rc == 0);
    rc = sub_forward ();
    assert (rc == 0);
    rc = timeo ();
    assert (rc == 0);
    rc = max_sockets ();
    assert (rc == 0);
    rc = emptyctx ();
    assert (rc == 0);
    rc = polltimeo ();
    assert (rc == 0);

    fprintf (stderr, "SUCCESS\n");
    sleep (1);

    return 0;
}
Exemplo n.º 9
0
static BOOL
startServer (unsigned short nPort, unsigned long nIP)
{
	SOCKADDR_IN sin;
	int ret;
	unsigned int yes;

	yes = TRUE;

	/* Grab a place to listen for connections. */
	srv = socket (AF_INET, SOCK_STREAM, 0);
	if (srv < 0) {
		return FALSE;
	}

	linger (srv);

	/* If this server has been restarted, don't wait for the old
	 * one to disappear completely */
	setsockopt (srv, SOL_SOCKET, SO_REUSEADDR, (char *) &yes, sizeof (yes));

	memset (&sin, 0, sizeof (sin));
	sin.sin_family = AF_INET;
	sin.sin_port = htons (nPort);

	sin.sin_addr.s_addr = nIP;
	ret = bind (srv, (SOCKADDR *) & sin, sizeof (sin));
	if (ret < 0) {
		return FALSE;
	}

	/* Start listening for incoming connections. */
	ret = listen (srv, 5);
	if (ret == 0)
		return TRUE;
	return FALSE;
}
Exemplo n.º 10
0
/*
This big messy function processes each incoming request.
*/
BOOL
HandleRequest ()
{
	SOCKET cli;
	conn_t *conn;
	os_thread_t thr;
	os_thread_init (&thr);

	/* Accept an incoming request, or wait till one arrives. */
	cli = accept (srv, NULL, NULL);
	if (cli == INVALID_SOCKET) {
#ifdef WITH_DEBUG
		DEBUG_LOG ("Accept barfed");
#endif
		return FALSE;
	}
	linger (cli);
	config_reference (conf);
	conn = (conn_t *) malloc (sizeof (conn_t));
	if (conn) {
		conn_init_tcp (conn, conf, cli);

		if (os_thread_exec (&thr, ChildThread, conn)) {
			os_thread_detach (&thr);
			return TRUE;
		}
		conn_close (conn);
	}
	closesocket (cli);
	config_dereference (conf);

#ifdef WITH_DEBUG
	DEBUG_LOG ("Couldn't allocate memory or create thread");
#endif

	return FALSE;
}
Exemplo n.º 11
0
bool playsingle_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_command& cmd, int index) const
{
	hotkey::HOTKEY_COMMAND command = cmd.id;
	bool res = true;
	switch (command){

		case hotkey::HOTKEY_WML:
		{
			int prefixlen = wml_menu_hotkey_prefix.length();
			if(cmd.command.compare(0, prefixlen, wml_menu_hotkey_prefix) != 0) {
				return false;
			}
			game_events::wmi_container::const_iterator it = gamestate().get_wml_menu_items().find(cmd.command.substr(prefixlen));
			if(it == gamestate().get_wml_menu_items().end()) {
				return false;
			}

			return !(**it).is_synced() || play_controller_.can_use_synced_wml_menu();
		}
		case hotkey::HOTKEY_UNIT_HOLD_POSITION:
		case hotkey::HOTKEY_END_UNIT_TURN:
			return !browse() && !linger() && !events::commands_disabled;
		case hotkey::HOTKEY_RECRUIT:
		case hotkey::HOTKEY_REPEAT_RECRUIT:
		case hotkey::HOTKEY_RECALL:
			return (!browse() || whiteboard_manager_->is_active()) && !linger() && !events::commands_disabled;
		case hotkey::HOTKEY_ENDTURN:
			return (!browse() || linger()) && !events::commands_disabled;

		case hotkey::HOTKEY_DELAY_SHROUD:
			return !linger() 
				&& (viewing_team().uses_fog() || viewing_team().uses_shroud())
				&& viewing_team_is_playing()
				&& viewing_team().is_local_human() 
				&& !events::commands_disabled;
		case hotkey::HOTKEY_UPDATE_SHROUD:
			return !linger()
				&& viewing_team_is_playing()
				&& viewing_team().is_local_human() 
				&& !events::commands_disabled
				&& viewing_team().auto_shroud_updates() == false;

		// Commands we can only do if in debug mode
		case hotkey::HOTKEY_CREATE_UNIT:
		case hotkey::HOTKEY_CHANGE_SIDE:
		case hotkey::HOTKEY_KILL_UNIT:
			return !events::commands_disabled && game_config::debug && play_controller_.get_map_const().on_board(mouse_handler_.get_last_hex());

		case hotkey::HOTKEY_CLEAR_LABELS:
			res = !is_observer();
			break;
		case hotkey::HOTKEY_LABEL_TEAM_TERRAIN:
		case hotkey::HOTKEY_LABEL_TERRAIN: {
			const terrain_label *label = gui()->labels().get_label(mouse_handler_.get_last_hex());
			res = !events::commands_disabled && play_controller_.get_map_const().on_board(mouse_handler_.get_last_hex())
				&& !gui()->shrouded(mouse_handler_.get_last_hex())
				&& !is_observer()
				&& (!label || !label->immutable());
			break;
		}
		case hotkey::HOTKEY_CONTINUE_MOVE: {
			if(browse() || events::commands_disabled)
				return false;

			if( (menu_handler_.current_unit().valid())
				&& (menu_handler_.current_unit()->move_interrupted()))
				return true;
			const unit_map::const_iterator i = play_controller_.get_units_const().find(mouse_handler_.get_selected_hex());
			if (!i.valid()) return false;
			return i->move_interrupted();
		}
		case hotkey::HOTKEY_WB_TOGGLE:
			return !is_observer();
		case hotkey::HOTKEY_WB_EXECUTE_ACTION:
		case hotkey::HOTKEY_WB_EXECUTE_ALL_ACTIONS:
			return whiteboard_manager_->can_enable_execution_hotkeys();
		case hotkey::HOTKEY_WB_DELETE_ACTION:
			return whiteboard_manager_->can_enable_modifier_hotkeys();
		case hotkey::HOTKEY_WB_BUMP_UP_ACTION:
		case hotkey::HOTKEY_WB_BUMP_DOWN_ACTION:
			return whiteboard_manager_->can_enable_reorder_hotkeys();
		case hotkey::HOTKEY_WB_SUPPOSE_DEAD:
		{
			//@todo re-enable this once we figure out a decent UI for suppose_dead
			return false;
		}

		default: return play_controller::hotkey_handler::can_execute_command(cmd, index);
	}
	return res;
}
Exemplo n.º 12
0
bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_command& cmd, int index) const
{
	if(index >= 0) {
		unsigned i = static_cast<unsigned>(index);
		if((i < savenames_.size() && !savenames_[i].empty())
		|| (i < wml_commands_.size() && wml_commands_[i])) {
			return true;
		}
	}
	switch(cmd.id) {

	// Commands we can always do:
	case hotkey::HOTKEY_LEADER:
	case hotkey::HOTKEY_CYCLE_UNITS:
	case hotkey::HOTKEY_CYCLE_BACK_UNITS:
	case hotkey::HOTKEY_ZOOM_IN:
	case hotkey::HOTKEY_ZOOM_OUT:
	case hotkey::HOTKEY_ZOOM_DEFAULT:
	case hotkey::HOTKEY_FULLSCREEN:
	case hotkey::HOTKEY_SCREENSHOT:
	case hotkey::HOTKEY_MAP_SCREENSHOT:
	case hotkey::HOTKEY_ACCELERATED:
	case hotkey::HOTKEY_SAVE_MAP:
	case hotkey::HOTKEY_TOGGLE_ELLIPSES:
	case hotkey::HOTKEY_TOGGLE_GRID:
	case hotkey::HOTKEY_MOUSE_SCROLL:
	case hotkey::HOTKEY_ANIMATE_MAP:
	case hotkey::HOTKEY_STATUS_TABLE:
	case hotkey::HOTKEY_MUTE:
	case hotkey::HOTKEY_PREFERENCES:
	case hotkey::HOTKEY_OBJECTIVES:
	case hotkey::HOTKEY_UNIT_LIST:
	case hotkey::HOTKEY_STATISTICS:
	case hotkey::HOTKEY_QUIT_GAME:
	case hotkey::HOTKEY_SEARCH:
	case hotkey::HOTKEY_HELP:
	case hotkey::HOTKEY_USER_CMD:
	case hotkey::HOTKEY_CUSTOM_CMD:
	case hotkey::HOTKEY_AI_FORMULA:
	case hotkey::HOTKEY_CLEAR_MSG:
	case hotkey::HOTKEY_SELECT_HEX:
	case hotkey::HOTKEY_DESELECT_HEX:
	case hotkey::HOTKEY_MOVE_ACTION:
	case hotkey::HOTKEY_SELECT_AND_ACTION:
	case hotkey::HOTKEY_MINIMAP_CODING_TERRAIN:
	case hotkey::HOTKEY_MINIMAP_CODING_UNIT:
	case hotkey::HOTKEY_MINIMAP_DRAW_UNITS:
	case hotkey::HOTKEY_MINIMAP_DRAW_TERRAIN:
	case hotkey::HOTKEY_MINIMAP_DRAW_VILLAGES:
	case hotkey::HOTKEY_NULL:
	case hotkey::HOTKEY_SAVE_REPLAY:
	case hotkey::LUA_CONSOLE:
		return true;

	// Commands that have some preconditions:
	case hotkey::HOTKEY_SAVE_GAME:
		return !events::commands_disabled;

	case hotkey::HOTKEY_SHOW_ENEMY_MOVES:
	case hotkey::HOTKEY_BEST_ENEMY_MOVES:
		return !linger() && play_controller_.enemies_visible();

	case hotkey::HOTKEY_LOAD_GAME:
		return network::nconnections() == 0; // Can only load games if not in a network game

	case hotkey::HOTKEY_CHAT_LOG:
		return true;

	case hotkey::HOTKEY_REDO:
		return play_controller_.can_redo();
	case hotkey::HOTKEY_UNDO:
		return play_controller_.can_undo();

	case hotkey::HOTKEY_UNIT_DESCRIPTION:
		return menu_handler_.current_unit().valid();

	case hotkey::HOTKEY_TERRAIN_DESCRIPTION:
		return mouse_handler_.get_last_hex().valid();

	case hotkey::HOTKEY_RENAME_UNIT:
		return !events::commands_disabled &&
			menu_handler_.current_unit().valid() &&
			!(menu_handler_.current_unit()->unrenamable()) &&
			menu_handler_.current_unit()->side() == gui()->viewing_side() &&
			play_controller_.get_teams_const()[menu_handler_.current_unit()->side() - 1].is_local_human();

	default:
		return false;
	}
}
Exemplo n.º 13
0
void tBroadwave::initialiseBroadwave()
{
#if defined VISUAL_STUDIO
  // Initialize Winsock.
  int iResult = WSAStartup(MAKEWORD(2,2), &this->wsaData);

  if (iResult != NO_ERROR)
  {
	cerr << "Error with WSAStartup while initialising Broadwave.\n";
  }
  else
  {
	cout << "Broadwave: WSAStarup() okay.\n";
  }
#endif

  // Create a socket.
  this->m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

  if (this->m_socket == INVALID_SOCKET)
  {
#if defined VISUAL_STUDIO
	cerr << "Client: socket() - Error at socket(): " << WSAGetLastError() << "\n";
	WSACleanup();
#endif
	return;
  }
  else
  {
	cout << "Broadwave: socket() okay.\n";
  }

#if defined VISUAL_STUDIO
  u_long nonBlocking = 1;
  ioctlsocket(this->m_socket, FIONBIO, &nonBlocking);
#elif defined LINUX_GCC
  // make sure socket doesn't block  
  if (fcntl( this->m_socket, F_SETFL, FNDELAY ) == -1)  
	throw runtime_error ("fcntl on control socket");
#endif

  struct linger ld = linger ();  // zero it  

  // Don't allow closed sockets to linger  
  if (setsockopt(this->m_socket, SOL_SOCKET, SO_LINGER,  
                 (char *) &ld, sizeof ld ) == -1)  
	throw runtime_error ("setsockopt (SO_LINGER)");  

  int x = 1;  

  // Allow address reuse   
  if (setsockopt( this->m_socket, SOL_SOCKET, SO_REUSEADDR,  
                 (char *) &x, sizeof x ) == -1)  
	throw runtime_error ("setsockopt (SO_REUSEADDR)");  

  // Connect to a server.
  this->clientService.sin_family = AF_INET;
  this->clientService.sin_addr.s_addr = inet_addr(BROADWAVE_IP);
  this->clientService.sin_port = htons(BROADWAVE_PORT);
#if defined VISUAL_STUDIO
  if (connect(this->m_socket, (SOCKADDR*)&this->clientService, sizeof(this->clientService)) == SOCKET_ERROR)
  {
	cerr << "Client: connect() - Failed to connect.\n";
	WSACleanup();
#elif defined LINUX_GCC
	if (connect(this->m_socket, (sockaddr*)&this->clientService, sizeof(this->clientService)) == 0)
	  //if (connect(this->m_socket, &this->clientService, sizeof(this->clientService)) == 0)
	{
	  cerr << "Client: connect() - Failed to connect.\n";
#endif
		return;
	}

	this->initialised = true;

	// Login
	tBroadwave::loginBroadwave ();	
  }

  void tBroadwave::listenBroadwave ()
  {
	if (!this->initialised)
	{
	  return;
	}

	static vector<char> inbuf (1000); 

#if defined VISUAL_STUDIO
	int nRead = recv(this->m_socket, &inbuf [0], (int) inbuf.size(), 0);

	if (nRead == -1)
	{
	  if (errno != WSAEWOULDBLOCK)
	  {
		perror("read from broadwave");
	  }
	  return;
	}

	if (nRead <= 0)
	{
	  closesocket(this->m_socket);
	  cerr << "Connection to Broadwave [" << this->m_socket << "] closed " << endl;
	  this->m_socket = NO_SOCKET;
	  return;
	}
#elif defined LINUX_GCC
	int nRead = read(this->m_socket, &inbuf [0], (int)inbuf.size());

	if (nRead == -1) { 
	  if (errno != EWOULDBLOCK) { 
		perror ("read from broadwave");
	  }
	  return;  
	}

	if (nRead <= 0) {
	  close(this->m_socket); 
	  cout << "Connection " << this->m_socket << " closed" << endl;  
	  this->m_socket = NO_SOCKET;  
	  return; 
	}
#endif

	string input;

	input += string(&inbuf[0], nRead);

	while (true)
	{
	  string::size_type i = input.find("\n");
	  if (i == string::npos)
	  {
		break;
	  }

	  string sLine = input.substr(0, i);
	  input = input.substr(i + 1, string::npos);

	  // This is where telnet negotiations occur
	  if (sLine[0] == IAC)
	  {
		string MCCP;
		MCCP.push_back(IAC);
		MCCP.push_back(WILL);
		MCCP.push_back(COMPRESS2);
		if (sLine.compare(0, 3, MCCP))
		{
		  // This assumes that MCCP is not available.

		  // Send IAC WONT COMPRESS2 here
		}
		sLine.erase(0, 3);
	  }
	  else if (sLine[0] == '~') // System Command from Broadwave
	  {
		sLine.erase(0, 1);
		if (sLine == "loginok")
		{
		  cout << "Successfully logged in to Broadwave Server." << endl;
		}
		else if (sLine == "shutdown")
		{
		  string outstring = "The Broadwave Server has been remotely shut down.";

		  // PLACEHOLDER - Server Shutdown
		  // If we've entered this else if, then the broadwave server has been shut down.
		  // The string outstring contains that message - you'll need to use your MUD's
		  // code to broadcast it.

		  send_to_gods(outstring.c_str());


		}
		continue;
	  }

	  if (!sLine.empty())
	  {
		istringstream is (sLine);
		string subwave, actor, realm, message;

		is >> subwave >> actor >> ws;
		string remnants;
		getline(is, remnants);

		realm = remnants.substr(0, remnants.find('*'));
		message = remnants.substr(remnants.find('*')+1, string::npos);

		string outstring;
		if (realm == THIS_REALM)
		{
		  outstring = "[" + subwave + ":" + actor + "] " + message;
		}
		else
		{
		  outstring = "[" + subwave + ":" + actor + "(" + realm + ")] " + message;
		}
		send_to_gods(outstring.c_str());

	  }
	}
  }
Exemplo n.º 14
0
bool Mud::initComunications()
{
    struct sockaddr_in socketAddress;
#ifdef _WIN32
    WSADATA wsaData;
    int iResult;

    // Initialize Winsock
    iResult = WSAStartup(0x0202, &wsaData);
    if (iResult != 0)
    {
        throw std::runtime_error("WSAStartup failed: "+ ToString(iResult));
    }
#endif

    // Create the control socket.
    if ((_servSocket = socket(AF_INET, SOCK_STREAM, 0)) == 0)
    {
        perror("Creating Control Socket");
        return false;
    }

    // Make sure socket doesn't block.
#ifdef __linux__
    if (fcntl(_servSocket, F_SETFL, FNDELAY) == -1)
    {
        throw std::runtime_error("FCNTL on Control Socket");
    }
#elif __APPLE__
    if (fcntl(_servSocket, F_SETFL, FNDELAY) == -1)
    {
        throw std::runtime_error("FCNTL on Control Socket");
    }
#elif __CYGWIN__

    int flags = fcntl(_servSocket, F_GETFL, 0);
    //if (fcntl(_servSocket, F_SETFL, flags | O_NONBLOCK | O_RDWR | O_NOCTTY | O_NDELAY) == -1)
    if (fcntl(_servSocket, F_SETFL, flags | O_NDELAY | O_NONBLOCK) == -1)
    {
        perror("FCNTL on Control Socket");
        return false;
    }
#elif _WIN32
    u_long imode = 1;
    if (ioctlsocket(_servSocket, FIONBIO, &imode) == -1)
    {
        throw std::runtime_error("FCNTL on Control Socket");
    }
#endif

    // Zero it.
    struct linger ld = linger();

    // Don't allow closed sockets to linger.
    if (setsockopt(_servSocket, SOL_SOCKET, SO_LINGER, (char *) &ld, sizeof ld) < 0)
    {
        perror("Setsockopt (SO_LINGER)");
        return false;
    }

    int x = 1;

    // Allow address reuse.
    if (setsockopt(_servSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &x, sizeof x) == -1)
    {
        perror("Setsockopt (SO_REUSEADDR)");
        return false;
    }

    socketAddress.sin_family = AF_INET;
    socketAddress.sin_port = htons(mudPort);
    socketAddress.sin_addr.s_addr = INADDR_ANY; // Change to listen on a specific adapter.

    // Bind the socket to our connection port.
    if (::bind(_servSocket, (struct sockaddr *) &socketAddress, sizeof(socketAddress)) < 0)
    {
        perror("BIND");
        return false;
    }

    // Listen for connections
    // Note: SOMAXCONN is the backlog count.
    if (listen(_servSocket, SOMAXCONN) == -1)
    {
        perror("LISTEN");
        return false;
    }

    // Standard termination signals.
    signal(SIGINT, Bailout);
    signal(SIGTERM, Bailout);
    signal(SIGHUP, Bailout);

    return true;
}