This commit is contained in:
houwei 2024-12-30 13:33:00 +08:00
commit d3abc980de
3 changed files with 24 additions and 12 deletions

View File

@ -40,7 +40,7 @@ struct myAdsVariable {
&bytesRead);
if (error || (size != bytesRead)) {
vLog(LOG_ERROR, "AdsVariable read failed: %d,%s\n", error, strerror(errno));
vLog(LOG_ERROR, "AdsVariable read failed: %d, %s\n", error, strerror(errno));
return FALSE;
}

View File

@ -84,7 +84,7 @@ uint32_t getIpv4(const std::string& addr)
InitSocketLibrary();
const auto status = getaddrinfo(addr.c_str(), nullptr, &addrinfo, &res);
if (status) {
throw std::runtime_error("Invalid IPv4 address or unknown hostname: " + addr);
//throw std::runtime_error("Invalid IPv4 address or unknown hostname: " + addr);
}
const auto value = ((struct sockaddr_in*)res->ai_addr)->sin_addr.s_addr;
@ -239,15 +239,22 @@ Frame& Socket::read(Frame& frame, timeval* timeout)
bool Socket::Select(timeval* timeout)
{
/* prepare socket set for select() */
if (!IsValid()) {
return false;
}
if (m_Socket < 0 || m_Socket >= FD_SETSIZE) {
LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set");
return false;
}
fd_set readSockets;
FD_ZERO(&readSockets);
FD_SET(m_Socket, &readSockets);
if (!IsValid()) return false;
/* wait for receive data */
const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr, nullptr, timeout);
if (0 == state) {
LOG_ERROR("Socket select() timeout.");
return false;
//throw TimeoutEx("select() timeout");
}
@ -255,6 +262,7 @@ bool Socket::Select(timeval* timeout)
if (m_LastError == WSAENOTSOCK) {
//throw std::runtime_error("connection closed");
Shutdown();
return false;
}
/* and check if socket was correct */
@ -263,7 +271,11 @@ bool Socket::Select(timeval* timeout)
return false;
}
if(!FD_ISSET(m_Socket, &readSockets))
if (m_Socket < 0 || m_Socket >= FD_SETSIZE) {
LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set");
return false;
}
if (!FD_ISSET(m_Socket, &readSockets))
{
return false;
}

View File

@ -65,7 +65,7 @@ long AmsRouter::ConnectTarget(AmsNetId ams, const std::string& host)
connection_attempts[ams] = {};
lock.unlock();
try {
// try {
//AmsConnection is created and try to connect remote host
auto new_connection = std::unique_ptr<AmsConnection>(new AmsConnection {*this, hostAddresses.get()});
if(new_connection.get() == nullptr || new_connection.get()->IsConnected() == false){
@ -89,13 +89,13 @@ long AmsRouter::ConnectTarget(AmsNetId ams, const std::string& host)
}
return -1;//
} catch (std::exception& e) {
std::cout<<"AmsRouter::AddRoute(Exception) is occured."<<"\n";
lock.lock();
connection_attempts.erase(ams);
connection_attempt_events.notify_all();
throw e;
}
// } catch (std::exception& e) {
// std::cout<<"AmsRouter::AddRoute(Exception) is occured."<<"\n";
// lock.lock();
// connection_attempts.erase(ams);
// connection_attempt_events.notify_all();
// throw e;
// }
}
void AmsRouter::DisconnectTarget(const AmsNetId& ams)