git-svn-id: svn://db.shs.com.ru/pip@543 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-09-06 07:27:24 +00:00
parent 6f54f501cd
commit e69f1e5ba2
3 changed files with 74 additions and 37 deletions

View File

@@ -62,30 +62,63 @@ public:
};
//! \brief IPv4 network address, ip and port
//! \brief IPv4 network address, IP and port
class Address {
friend class PIEthernet;
friend inline PIByteArray & operator <<(PIByteArray & s, const PIEthernet::Address & v);
friend inline PIByteArray & operator >>(PIByteArray & s, PIEthernet::Address & v);
public:
//! Contructs %Address with binary representation of ip and port
//! Contructs %Address with binary representation of IP and port
Address(uint ip = 0, ushort port = 0);
//! Contructs %Address with string representation "i.i.i.i:p"
Address(const PIString & ip_port);
//! Contructs %Address with IP string representation "i.i.i.i" and port
Address(const PIString & ip, ushort port);
//! Returns binary IP
uint ip() const {return ip_;}
//! Returns port
ushort port() const {return port_;}
//! Returns string IP
PIString ipString() const;
//! Returns string representation of IP and port "i.i.i.i:p"
PIString toString() const;
//! Set address IP
void setIP(uint ip);
//! Set address IP
void setIP(const PIString & ip);
//! Set address port
void setPort(ushort port);
//! Set address IP and port, "i.i.i.i:p"
void set(const PIString & ip_port);
//! Set address IP and port, "i.i.i.i"
void set(const PIString & ip, ushort port);
//! Set address binary IP and port
void set(uint ip, ushort port);
//! Set IP and port to 0
void clear();
//! Resolve hostname "host" and return it IPv4 address or "0.0.0.0" on error
static PIString resolve(const PIString & host);
//! Returns if IP and port is 0
bool isNull() const;
//! Resolve hostname "host:port" and return it address or null address on error
static Address resolve(const PIString & host_port);
//! Resolve hostname "host" with port "port" and return it address or null address on error
static Address resolve(const PIString & host, ushort port);
static void splitIPPort(const PIString & ipp, PIString * ip, int * port);
private:
@@ -227,6 +260,9 @@ public:
//! Connect to TCP server with address "ip_port". Use only for TCP_Client
bool connect(const PIString & ip_port) {setPath(ip_port); return connect();}
//! Connect to TCP server with address "addr". Use only for TCP_Client
bool connect(const Address & addr) {setPath(addr.toString()); return connect();}
//! Returns if %PIEthernet connected to TCP server. Use only for TCP_Client
bool isConnected() const {return connected_;}
@@ -244,6 +280,9 @@ public:
//! Start listen for incoming TCP connections on address "ip_port". Use only for TCP_Server
bool listen(const PIString & ip_port, bool threaded = false) {setReadAddress(ip_port); return listen(threaded);}
//! Start listen for incoming TCP connections on address "addr". Use only for TCP_Server
bool listen(const Address & addr, bool threaded = false) {setReadAddress(addr); return listen(threaded);}
PIEthernet * client(int index) {return clients_[index];}
int clientsCount() const {return clients_.size_s();}
PIVector<PIEthernet * > clients() const {return clients_;}