NRP Core  1.4.1
utils.h File Reference
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <string>
#include <stdexcept>
#include <unistd.h>
#include <boost/python.hpp>
#include <boost/asio.hpp>

Go to the source code of this file.

Functions

int bindOrFindFreePort (std::string hostIpv4, int port=0)
 Attempts to bind to a given address. More...
 
void bindToAddress (std::string hostIpv4, int port)
 Attempts to bind to a given address. More...
 
int getFreePort (std::string hostIpv4)
 Returns a free port number. More...
 
void appendPythonPath (const std::string &path)
 Appends 'path' to PYTHON_PATH env variable. More...
 

Function Documentation

◆ appendPythonPath()

void appendPythonPath ( const std::string &  path)
inline

Appends 'path' to PYTHON_PATH env variable.

◆ bindOrFindFreePort()

int bindOrFindFreePort ( std::string  hostIpv4,
int  port = 0 
)
inline

Attempts to bind to a given address.

Parameters
hostIpv4IP4 address of the host
portPort to connect to, if 0 a free port is searched and used
Returns
Port used in the connection, same as "port" argument or found free port

When "port" is 0, the function asks the OS to look for a free port number. Throws an exception if the connection is not successful

◆ bindToAddress()

void bindToAddress ( std::string  hostIpv4,
int  port 
)
inline

Attempts to bind to a given address.

Parameters
hostIpv4IP4 address of the host
portPort to connect to

Throws an exception if the connection is not successful

◆ getFreePort()

int getFreePort ( std::string  hostIpv4)
inline

Returns a free port number.

Parameters
hostIpv4IP4 address of the host
Returns
Free port number

Asks the OS to look for a free port number