EIO_Status CSocket::Connect(const string& host, unsigned short port, const STimeout* timeout, TSOCK_Flags flags) { if ( m_Socket ) { if (SOCK_Status(m_Socket, eIO_Open) != eIO_Closed) return eIO_Unknown; if (m_IsOwned != eNoOwnership) SOCK_Close(m_Socket); } if (timeout != kDefaultTimeout) { if ( timeout ) { if (&oo_timeout != timeout) oo_timeout = *timeout; o_timeout = &oo_timeout; } else o_timeout = 0; } EIO_Status status = SOCK_CreateEx(host.c_str(), port, o_timeout, &m_Socket, 0, 0, flags); if (status == eIO_Success) { SOCK_SetTimeout(m_Socket, eIO_Read, r_timeout); SOCK_SetTimeout(m_Socket, eIO_Write, w_timeout); SOCK_SetTimeout(m_Socket, eIO_Close, c_timeout); } else assert(!m_Socket); return status; }
CSocket::CSocket(const string& host, unsigned short port, const STimeout* timeout, TSOCK_Flags flags) : m_IsOwned(eTakeOwnership), r_timeout(0), w_timeout(0), c_timeout(0) { if (timeout && timeout != kDefaultTimeout) { oo_timeout = *timeout; o_timeout = &oo_timeout; } else o_timeout = 0; SOCK_CreateEx(host.c_str(), port, o_timeout, &m_Socket, 0, 0, flags); }
CSocket::CSocket(unsigned int host, unsigned short port, const STimeout* timeout, TSOCK_Flags flags) : m_IsOwned(eTakeOwnership), r_timeout(0), w_timeout(0), c_timeout(0) { char x_host[16/*sizeof("255.255.255.255")*/]; if (timeout && timeout != kDefaultTimeout) { oo_timeout = *timeout; o_timeout = &oo_timeout; } else o_timeout = 0; if (SOCK_ntoa(host, x_host, sizeof(x_host)) != 0) m_Socket = 0; else SOCK_CreateEx(x_host, port, o_timeout, &m_Socket, 0, 0, flags); }
static EIO_Status s_VT_Open (CONNECTOR connector, const STimeout* timeout) { SSockConnector* xxx = (SSockConnector*) connector->handle; EIO_Status status = eIO_Success; if (!xxx->sock) { unsigned short i; if (!xxx->port) return eIO_Closed; assert(xxx->try_own); for (i = 0; i < xxx->try_own; i++) { /* connect */ status = SOCK_CreateEx(xxx->host, xxx->port, timeout, &xxx->sock, xxx->init_data, xxx->init_size, xxx->flags); if (xxx->sock) break; assert(status != eIO_Success); } } assert(!xxx->sock ^ !(status != eIO_Success)); return status; }
static CConn_IOStream::TConn_Pair s_SocketConnectorBuilder(const SConnNetInfo* net_info, const STimeout* timeout, const void* data, size_t size, TSOCK_Flags flags) { EIO_Status status = eIO_Success; bool proxy = false; SOCK sock = 0; _ASSERT(net_info); if ((flags & (fSOCK_LogOn | fSOCK_LogDefault)) == fSOCK_LogDefault && net_info->debug_printout == eDebugPrintout_Data) { flags &= ~fSOCK_LogDefault; flags |= fSOCK_LogOn; } if (*net_info->http_proxy_host && net_info->http_proxy_port) { status = HTTP_CreateTunnel(net_info, fHTTP_NoAutoRetry, &sock); _ASSERT(!sock ^ !(status != eIO_Success)); if (status == eIO_Success && ((flags & ~(fSOCK_LogOn | fSOCK_LogDefault)) || size)) { SOCK s; status = SOCK_CreateOnTopEx(sock, 0, &s, data, size, flags); _ASSERT(!s ^ !(status != eIO_Success)); SOCK_Destroy(sock); sock = s; } proxy = true; } if (!sock && (!proxy || net_info->http_proxy_leak)) { const char* host = (net_info->firewall && *net_info->proxy_host ? net_info->proxy_host : net_info->host); if (timeout == kDefaultTimeout) timeout = net_info->timeout; if (!proxy && net_info->debug_printout) { SConnNetInfo* x_net_info = ConnNetInfo_Clone(net_info); if (x_net_info) { x_net_info->req_method = eReqMethod_Any; x_net_info->stateless = 0; x_net_info->lb_disable = 0; x_net_info->http_proxy_host[0] = '\0'; x_net_info->http_proxy_port = 0; x_net_info->http_proxy_user[0] = '\0'; x_net_info->http_proxy_pass[0] = '\0'; x_net_info->proxy_host[0] = '\0'; ConnNetInfo_SetUserHeader(x_net_info, 0); if (x_net_info->http_referer) { free((void*) x_net_info->http_referer); x_net_info->http_referer = 0; } x_net_info->timeout = timeout; } ConnNetInfo_Log(x_net_info, eLOG_Note, CORE_GetLOG()); ConnNetInfo_Destroy(x_net_info); } status = SOCK_CreateEx(host, net_info->port, timeout, &sock, data, size, flags); _ASSERT(!sock ^ !(status != eIO_Success)); } string hostport(net_info->host); hostport += ':'; hostport += NStr::UIntToString(net_info->port); CONNECTOR c = SOCK_CreateConnectorOnTopEx(sock, 1/*own*/, hostport.c_str()); if (!c) { SOCK_Abort(sock); SOCK_Close(sock); status = eIO_Unknown; } return CConn_IOStream::TConn_Pair(c, status); }