int TL_Mysql::query(const char* query, size_t qlen) { if (!_isconnected) { reConnect(); } int ret = mysql_real_query(&_mysql, query, qlen); if (ret != 0) { int eno = mysql_errno(&_mysql); if (eno == CR_SERVER_LOST || eno == CR_SERVER_GONE_ERROR) { try { reConnect(); ret = mysql_real_query(&_mysql, query, qlen); if (ret != 0) { char errstr[200]; int err = mysql_errno(&_mysql); snprintf(errstr, 200, "TL_Mysql Error 001::query:%d %d %s\n", ret, err, mysql_error(&_mysql)); throw TL_Exp(errstr, err); } } catch (TL_Exp& e) { throw e; } } else { char errstr[200]; snprintf(errstr, 200, "TL_Mysql Error 002::query:%d %d %s\n", ret, mysql_errno(&_mysql), mysql_error(&_mysql)); throw TL_Exp(errstr); } } return ret; }
bool TL_Mysql::connect(const std::string& hostname, const std::string& username, const std::string& password, int port, const std::string& dbname) { _conf.hostname = hostname; _conf.username = username; _conf.password = password; _conf.dbname = dbname; _conf.port = port; _isconnected = false; return reConnect(); }
void loop() { delay(500); pinVal = digitalRead(pinNumber); if (pinVal == HIGH) { if (showerBusy == LOW) { showerBusy = HIGH; RGB.color(255, 0, 0); reConnect(); Spark.publish("shower", "busy", 60, PRIVATE); } } else { if (showerBusy == HIGH) { showerBusy = LOW; RGB.color(0, 255, 0); reConnect(); Spark.publish("shower", "free", 60, PRIVATE); } } reConnect(); }
void cTcpClient::setAutoConnection(bool jn) { if(DEB_TCPCLIENT_METHODEN) qDebug() << "<cTcpClient::setAutoConnection("<<jn<<")>"; if(jn==true) { if(!autoConnectGesetzt) { QObject::connect(this, SIGNAL(gotConnection(bool)), this, SLOT(reConnect(bool))); reConnect(isConnected()); } }
void ChatServer::setIPAddressAndPort(QString ip, int port){ qDebug()<<"changing destination"; SocketState s = this->state(); this->_ipAddr = ip; this->_port = port; if(s == ConnectedState){ qDebug() << "Reconnecting"; emit disconnectFromHost(); emit reConnect(); } }
bool TL_Mysql::connect(const TL_MysqlConf & conf) { _conf = conf; return reConnect(); }
void AtDrv::startClient(uint8_t sock, const char *host, uint16_t port, uint8_t protMode) { // if we enable CHECK_TCP_STATE feature, always call reConnect(), or we won't get right // tcp port status, since we disable tcp auto reconnect. #ifndef CHECK_TCP_STATE bool needReConn = false; #else bool needReConn = true; #endif int curMode; char curHostBuf[MAX_HOST_NAME_BUF_SIZE]; uint8_t curProtocol; uint16_t curPort; uint16_t curLocalPort; uint32_t curTimeout; bool curTcpAuto; // clear uart buffer first stopClient(sock); if(!isAtMode()) { if(!switchToAtMode()) { INFO1("Can't switch to at mode"); goto end; } } if(!getMode(sock, &curMode) || curMode != MODE_CLIENT) { needReConn = true; INFO1("curMode != MODE_CLIENT"); if(!setMode(sock, MODE_CLIENT)) { INFO1("Can't set mode"); goto end; } } if(!getRemoteHost(sock, curHostBuf) || (strcmp(curHostBuf, host) != 0)) { needReConn = true; INFO1("curHostBuf != host"); if(!setRemoteHost(sock, host)) { INFO1("Can't set host"); goto end; } } if(!getProtocol(sock, &curProtocol) || curProtocol != protMode) { needReConn = true; INFO1("curProtocol != protMode"); if(!setProtocol(sock, protMode)) { INFO1("Can't set protocol"); goto end; } } if(!getRemotePort(sock, &curPort) || curPort != port) { needReConn = true; INFO1("curPort != port"); if(!setPort(sock, port)) { INFO1("Can't set port"); goto end; } } if(!getTcpAuto(sock, &curTcpAuto) || curTcpAuto != false) { needReConn = true; INFO1("curTcpAuto != false"); if(!setTcpAuto(sock, false)) { INFO1("Can't set tcp auto"); goto end; } } if(!getLocalPort(sock, &curLocalPort) || curLocalPort != localSockPort[sock]) { needReConn = true; INFO1("curLocalPort != port"); if(!setLocalPort(sock, localSockPort[sock])) { INFO1("Can't set port"); goto end; } } if(needReConn) { if(!reConnect()) { INFO1("Can't reconnect"); goto end; } } sockPort[sock] = localSockPort[sock]; sockConnected[sock] = true; end: return; }
void AtDrv::startClient(uint8_t sock, uint32_t ipAddress, uint16_t port, uint8_t protMode) { // if we enable CHECK_TCP_STATE feature, always call reConnect(), or we won't get right // tcp port status, since we disable tcp auto reconnect. #ifndef CHECK_TCP_STATE bool needReConn = false; #else bool needReConn = true; #endif int curMode; uint32_t curIp; uint8_t curProtocol; uint16_t curPort; uint16_t curLocalPort; uint32_t curTimeout; bool curTcpAuto; // clear uart buffer first stopClient(sock); if(!isAtMode()) { if(!switchToAtMode()) { INFO1("Can't switch to at mode"); goto end; } } if(!getMode(sock, &curMode) || curMode != MODE_CLIENT) { needReConn = true; INFO1("curMode != MODE_CLIENT"); if(!setMode(sock, MODE_CLIENT)) { INFO1("Can't set mode"); goto end; } } if(!getRemoteIp(sock, (uint8_t *)&curIp) || curIp != ipAddress) { needReConn = true; INFO1("curIp != ipAddress"); if(!setRemoteIp(sock, ipAddress)) { INFO1("Can't set ip"); goto end; } } if(!getProtocol(sock, &curProtocol) || curProtocol != protMode) { needReConn = true; INFO1("curProtocol != protMode"); if(!setProtocol(sock, protMode)) { INFO1("Can't set protocol"); goto end; } } if(!getRemotePort(sock, &curPort) || curPort != port) { needReConn = true; INFO1("curPort != port"); if(!setPort(sock, port)) { INFO1("Can't set port"); goto end; } } if(!getTcpAuto(sock, &curTcpAuto) || curTcpAuto != false) { needReConn = true; INFO1("curTcpAuto != false"); if(!setTcpAuto(sock, false)) { INFO1("Can't set tcp auto"); goto end; } } if(!getLocalPort(sock, &curLocalPort) || curLocalPort != localSockPort[sock]) { needReConn = true; INFO1("curLocalPort != port"); if(!setLocalPort(sock, localSockPort[sock])) { INFO1("Can't set port"); goto end; } } if(needReConn) { if(!reConnect()) { INFO1("Can't reconnect"); goto end; } } sockPort[sock] = localSockPort[sock]; sockConnected[sock] = true; end: return; }
void AtDrv::startServer(uint8_t sock, uint16_t port, uint8_t protMode) { bool needReConn = false; int curMode; uint8_t curProtocol; uint16_t curPort; uint32_t curTimeout; if(!isAtMode()) { if(!switchToAtMode()) { INFO1("Can't switch to at mode"); goto end; } } if(!getMode(sock, &curMode) || curMode != MODE_SERVER) { needReConn = true; INFO1("curMode != MODE_SERVER"); if(!setMode(sock, MODE_SERVER)) { INFO1("Can't set mode"); goto end; } } if(!getProtocol(sock, &curProtocol) || curProtocol != protMode) { needReConn = true; INFO1("curProtocol != protMode"); if(!setProtocol(sock, protMode)) { INFO1("Can't set protocol"); goto end; } } if(!getRemotePort(sock, &curPort) || curPort != port) { needReConn = true; INFO1("curPort != port"); if(!setPort(sock, port)) { INFO1("Can't set port"); goto end; } } if(!getNetworkTimeout(sock, &curTimeout) || curTimeout != 0) { needReConn = true; INFO1("curTimeout != 0"); if(!setNetworkTimeout(sock, 0)) { INFO1("Can't set timeout"); goto end; } } if(needReConn) { if(!reConnect()) { INFO1("Can't reconnect"); goto end; } } sockPort[sock] = port; sockConnected[sock] = true; end: return; }
ChatServer::ChatServer(QObject *parent, QString ip, int port):QTcpSocket(parent){ this->_ipAddr = ip; this->_port = port; this->connect(this, SIGNAL(reConnect()),this, SLOT(connectToServer())); }