Merge branch 'main' of https://git.jsspisoft.com/ry-das
This commit is contained in:
commit
d3abc980de
16
das-dn/third_party/AdsLib/Sockets.cpp
vendored
16
das-dn/third_party/AdsLib/Sockets.cpp
vendored
@ -84,7 +84,7 @@ uint32_t getIpv4(const std::string& addr)
|
|||||||
InitSocketLibrary();
|
InitSocketLibrary();
|
||||||
const auto status = getaddrinfo(addr.c_str(), nullptr, &addrinfo, &res);
|
const auto status = getaddrinfo(addr.c_str(), nullptr, &addrinfo, &res);
|
||||||
if (status) {
|
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;
|
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)
|
bool Socket::Select(timeval* timeout)
|
||||||
{
|
{
|
||||||
/* prepare socket set for select() */
|
/* 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_set readSockets;
|
||||||
FD_ZERO(&readSockets);
|
FD_ZERO(&readSockets);
|
||||||
FD_SET(m_Socket, &readSockets);
|
FD_SET(m_Socket, &readSockets);
|
||||||
|
|
||||||
if (!IsValid()) return false;
|
|
||||||
/* wait for receive data */
|
/* wait for receive data */
|
||||||
const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr, nullptr, timeout);
|
const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr, nullptr, timeout);
|
||||||
if (0 == state) {
|
if (0 == state) {
|
||||||
LOG_ERROR("Socket select() timeout.");
|
LOG_ERROR("Socket select() timeout.");
|
||||||
|
return false;
|
||||||
//throw TimeoutEx("select() timeout");
|
//throw TimeoutEx("select() timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,6 +262,7 @@ bool Socket::Select(timeval* timeout)
|
|||||||
if (m_LastError == WSAENOTSOCK) {
|
if (m_LastError == WSAENOTSOCK) {
|
||||||
//throw std::runtime_error("connection closed");
|
//throw std::runtime_error("connection closed");
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* and check if socket was correct */
|
/* and check if socket was correct */
|
||||||
@ -263,6 +271,10 @@ bool Socket::Select(timeval* timeout)
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
if (!FD_ISSET(m_Socket, &readSockets))
|
if (!FD_ISSET(m_Socket, &readSockets))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -65,7 +65,7 @@ long AmsRouter::ConnectTarget(AmsNetId ams, const std::string& host)
|
|||||||
|
|
||||||
connection_attempts[ams] = {};
|
connection_attempts[ams] = {};
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
try {
|
// try {
|
||||||
//AmsConnection is created and try to connect remote host
|
//AmsConnection is created and try to connect remote host
|
||||||
auto new_connection = std::unique_ptr<AmsConnection>(new AmsConnection {*this, hostAddresses.get()});
|
auto new_connection = std::unique_ptr<AmsConnection>(new AmsConnection {*this, hostAddresses.get()});
|
||||||
if(new_connection.get() == nullptr || new_connection.get()->IsConnected() == false){
|
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;//
|
return -1;//
|
||||||
} catch (std::exception& e) {
|
// } catch (std::exception& e) {
|
||||||
std::cout<<"AmsRouter::AddRoute(Exception) is occured."<<"\n";
|
// std::cout<<"AmsRouter::AddRoute(Exception) is occured."<<"\n";
|
||||||
lock.lock();
|
// lock.lock();
|
||||||
connection_attempts.erase(ams);
|
// connection_attempts.erase(ams);
|
||||||
connection_attempt_events.notify_all();
|
// connection_attempt_events.notify_all();
|
||||||
throw e;
|
// throw e;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmsRouter::DisconnectTarget(const AmsNetId& ams)
|
void AmsRouter::DisconnectTarget(const AmsNetId& ams)
|
||||||
|
Loading…
Reference in New Issue
Block a user