string makeQueueName() { string szTime(""); svutil::TTime curTime = svutil::TTime::GetCurrentTimeEx(); char chTime[32] = {0}; sprintf(chTime, "%d%d%d%d%d%d%d", getpid(), curTime.GetYear(), curTime.GetMonth(), curTime.GetDay(), curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond()); szTime = chTime; return szTime; }
// establish a client side connection int establishConnection(struct socketDescriptor * sd) { // create a stream socket if (!sd->description) sd->description = ""; sd->socket = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in sinRemote; sinRemote.sin_family = AF_INET; if ((sinRemote.sin_addr.s_addr = lookupAddress(sd->host)) == INADDR_NONE) return FALSE; sinRemote.sin_port = htons(sd->port); char hostname[256]; lookupName(inet_ntoa(sinRemote.sin_addr), hostname, sizeof(hostname)); if (sd->socket==INVALID_SOCKET || connect(sd->socket, (sockaddr*)&sinRemote, sizeof(sockaddr_in))==SOCKET_ERROR) { if (sd->lastError != WSAGetLastError()) { sd->lastError = WSAGetLastError(); if (sd->lastError == WSAECONNREFUSED) printq("establishConnection %s: server %s refused connection request\n", szTime(), hostname); else if (sd->lastError == WSAETIMEDOUT) printq("establishConnection %s: server %s connection request timed out\n", szTime(), hostname); else if (!sd->exit) printErrorMsg("establishConnection"); } if (sd->socket != INVALID_SOCKET) { closesocket(sd->socket); sd->socket = INVALID_SOCKET; } sd->connected=FALSE; return FALSE; } else { sd->lastError = NO_ERROR; } printq("Client established connection to %s on socket %d\n", hostname, sd->socket); processServerConnect(sd->host); if (sd->reconnectMsg) sendMsg(sd, sd->reconnectMsg, sd->debugMsg); singleThreadSd = sd; sd->connected=TRUE; return TRUE; }