rcComm_t* connection_pool::refresh_connection(int _index) { conn_ctxs_[_index].error = {}; if (!verify_connection(_index)) { create_connection(_index, [] { throw std::runtime_error{"connect error"}; }, [] { throw std::runtime_error{"client login error"}; }); } return conn_ctxs_[_index].conn.get(); }
int verify_services(int port, char* ip_address) { char msg[SEND_BUF_SIZE]; switch(port){ case 22: if (verify_connection(port, ip_address, "", "", 0) == ERROR) { return ERROR; }; break; case 25: if (verify_connection(port, ip_address, "", "220 ", 4) == ERROR) { return ERROR; }; break; case 587: if (verify_connection(port, ip_address, "", "220 ", 4) == ERROR) { return ERROR; }; break; case 43: if (verify_connection(port, ip_address, "whois", "", 0) == ERROR) { return ERROR; }; break; case 80: if (verify_connection(port, ip_address, "GET", "Server:", 0) == ERROR) { return ERROR; }; break; case 110: if (verify_connection(port, ip_address, "", "+OK", 4) == ERROR) { return ERROR; }; break; case 143: if (verify_connection(port, ip_address, "", "]", 2) == ERROR) { return ERROR; }; break; } return OK; }
bool CSSLComm::Connect(const char *pCertPath) { bool bConnected = connected(); if (!bConnected && NULL != pCertPath && pCertPath[0] != '\0') { const char *pCertDirPos = strrchr(pCertPath, '\\'); if (NULL == pCertDirPos) { pCertDirPos = strrchr(pCertPath, '/'); } if (NULL != pCertDirPos) { char strCertDir[512] = {0}; memcpy(strCertDir, pCertPath, pCertDirPos - pCertPath); bConnected = ssl_connect(APPLE_HOST, APPLE_PORT, pCertPath, pCertPath, strCertDir); printf("connect %s:%d result:%d\n", APPLE_HOST, APPLE_PORT, bConnected); } } if (bConnected) { verify_connection(m_pssl, APPLE_HOST); } return bConnected; }