| 99 | // ---------------------------------------------------------------------------------------- |
| 100 | |
| 101 | connection* connect ( |
| 102 | const std::string& host_or_ip, |
| 103 | unsigned short port |
| 104 | ) |
| 105 | { |
| 106 | std::string ip; |
| 107 | connection* con; |
| 108 | if (is_ip_address(host_or_ip)) |
| 109 | { |
| 110 | ip = host_or_ip; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | if( hostname_to_ip(host_or_ip,ip)) |
| 115 | throw socket_error(ERESOLVE,"unable to resolve '" + host_or_ip + "' in connect()"); |
| 116 | } |
| 117 | |
| 118 | if(create_connection(con,port,ip)) |
| 119 | { |
| 120 | std::ostringstream sout; |
| 121 | sout << "unable to connect to '" << host_or_ip << ":" << port << "'"; |
| 122 | throw socket_error(sout.str()); |
| 123 | } |
| 124 | |
| 125 | return con; |
| 126 | } |
| 127 | |
| 128 | // ---------------------------------------------------------------------------------------- |
| 129 | |