mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added connect_to()
This commit is contained in:
parent
6bf4a648b0
commit
51ad8568b4
@ -43,6 +43,31 @@ namespace dlib
|
||||
const unsigned short port;
|
||||
};
|
||||
|
||||
inline connect_to_ip_and_port connect_to (
|
||||
const network_address& addr
|
||||
)
|
||||
{
|
||||
// make sure requires clause is not broken
|
||||
DLIB_ASSERT(addr.port != 0,
|
||||
"\t connect_to_ip_and_port()"
|
||||
<< "\n\t The TCP port to connect to can't be 0."
|
||||
<< "\n\t addr.port: " << addr.port
|
||||
);
|
||||
|
||||
if (is_ip_address(addr.host_address))
|
||||
{
|
||||
return connect_to_ip_and_port(addr.host_address, addr.port);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string ip;
|
||||
if(hostname_to_ip(addr.host_address,ip))
|
||||
throw socket_error(ERESOLVE,"unable to resolve '" + addr.host_address + "' in connect_to()");
|
||||
|
||||
return connect_to_ip_and_port(ip, addr.port);
|
||||
}
|
||||
}
|
||||
|
||||
struct listen_on_port
|
||||
{
|
||||
listen_on_port(
|
||||
|
@ -27,6 +27,17 @@ namespace dlib
|
||||
!*/
|
||||
};
|
||||
|
||||
connect_to_ip_and_port connect_to (
|
||||
const network_address& addr
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
- addr.port != 0
|
||||
ensures
|
||||
- converts the given network_address object into a connect_to_ip_and_port
|
||||
object.
|
||||
!*/
|
||||
|
||||
struct listen_on_port
|
||||
{
|
||||
listen_on_port(
|
||||
|
Loading…
Reference in New Issue
Block a user