ServerConfig::NetError TcpNetwork::FlushSendBuff(const int sessionIndex) { auto& session = m_ClientSessionPool[sessionIndex]; auto fd = static_cast<SOCKET>(session.SocketFD); if (session.IsConnected() == false) { return NET_ERROR_CODE::CLIENT_FLUSH_SEND_BUFF_REMOTE_CLOSE; } auto result = SendSocket(fd, session.pSendBuffer, session.SendSize); if (result.Error != NET_ERROR_CODE::NONE) { return result; } auto sendSize = result.Value; if (sendSize < session.SendSize) { memmove(&session.pSendBuffer[0], &session.pSendBuffer[sendSize], session.SendSize - sendSize); session.SendSize -= sendSize; } else { session.SendSize = 0; } return result; }
void PacketManager::SendPackets2(void) { if (mSendData.size() == 0) return; #ifdef DEBUG_TIME Debug::TimeTrack("SendPackets2", 50); #endif std::list<PendingSocket>::iterator it; it = mSendData.begin(); while (it != mSendData.end()) { int res = SendSocket(it->mSocket, *it); if (res == SEND_DELAY) { mTotalWait++; ++it; } else { //If we get here, it had a serious failure or it succeeded. //Either way, we're done with the data, so it can be erased. if (res == SEND_FAILED) { g_Logs.server->error("Disconnecting Socket:%v", it->mSocket); SocketClass::DisconnectClient(it->mSocket); } mSendData.erase(it++); } } }
NET_ERROR_CODE TCPNetwork::FlushSendBuffer(const int sessionIdx) { //분석해보기 auto& cs = m_clientSessionPool[sessionIdx]; auto fd = static_cast<SOCKET>(cs.SocketFD); if (cs.IsConnected() == false) { return NET_ERROR_CODE::CLIENT_FLUSH_SEND_BUFF_REMOTE_CLOSE; } auto ret = SendSocket(fd, cs.pSendBuffer, cs.SendSize); if (ret != NET_ERROR_CODE::NONE) { return ret; } int sendSize = static_cast<int>(ret); if (sendSize < cs.SendSize) { memmove(cs.pSendBuffer, cs.pRecvBuffer + sendSize, cs.SendSize - sendSize); cs.SendSize -= sendSize; } else { cs.SendSize = 0; } return ret; }
Tipo_Data *GetOneRecordAsinc(int id,int nSocket,char szSql[]) { MYSQL_RES *res=NULL; char szAux[MAX_BUFFER]; int i; int nIntentos; nIntentos=0; time_t time1,time2; int nLen; MYSQL_ROW row; MYSQL_FIELD *fields; Tipo_Data *pData=NULL; int num_fields; reintenta: if (Conexion[id].nAbierta==0) { if (!Conexion[id].nAbierta) { WriteError(id,"Abre Conexion BD"); Conexion[id].pMysqlconn=OpenDatabase(id,global.szBaseDatos,global.szIpBd,global.szPortPostgres); } if (Conexion[id].pMysqlconn==NULL) { WriteError(id,"Falla Conexion BD"); return pData; } Conexion[id].nAbierta=1; } //sprintf(szAux,"SQL=%s Len=%i",szSql,strlen(szSql)); //WriteLog(id,szAux); if ( mysql_real_query(Conexion[id].pMysqlconn,szSql,strlen(szSql)) != 0) { sprintf(szAux,"Error en PQsendQuery Mysql %s",mysql_error(Conexion[id].pMysqlconn)); WriteLog(id,szAux); WriteError(id,szAux); fprintf(stderr, "Falla Envio de Query %s\n\r",mysql_error(Conexion[id].pMysqlconn)); //Vamos a reabrir la conexion a la base de datos if (nIntentos++<2) { WriteError(id,"Reintento"); WriteLog(id,"Reintento"); //PQclear(res); CierraMysql(id); Conexion[id].pMysqlconn=OpenDatabase(id,global.szBaseDatos,global.szIpBd,global.szPortPostgres); if (Conexion[id].pMysqlconn==NULL) { WriteLog(id,"FALLA_RECONEXION_BD"); Conexion[id].nAbierta=0; return pData; } else { WriteError(id,"Conexion OK"); WriteLog(id,"Conexion OK"); Conexion[id].nAbierta=1; goto reintenta; } } else { WriteLog(id,"FALLA_FIN_REINTENTOS"); CierraMysql(id); return pData; } return pData; } do { time(&time1); res=mysql_use_result(Conexion[id].pMysqlconn); if (res==NULL) { //WriteError(id,"Error al obtener resultado"); mysql_free_result(res); return NULL; //CierraMysql(id); //return pData; } num_fields = mysql_num_fields(res); while ((row = mysql_fetch_row(res)) != NULL) { unsigned long *lengths; WriteLog(id,"Entre"); lengths = mysql_fetch_lengths(res); fields = mysql_fetch_fields(res); //Nombre del campo for(i = 0; i < num_fields; i++) { pData=InsertaData("<STATUS>OK</STATUS>",pData); pData=InsertaDataLen("<",1,pData); pData=InsertaData(fields[i].name,pData); pData=InsertaDataLen(">",1,pData); pData=InsertaDataLen(row[i],(int) lengths[i],pData); pData=InsertaDataLen("</",2,pData); pData=InsertaData(fields[i].name,pData); pData=InsertaDataLen(">",1,pData); } SendSocket(id,nSocket,pData->data,strlen(pData->data)); pData=LiberaData(pData); } } while (mysql_next_result(Conexion[id].pMysqlconn)==0); //sprintf(szAux,"Puntero2=%x",Conexion[id].pMysqlconn); //WriteLog(id,szAux); mysql_free_result(res); return NULL; }