mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-29 16:44:29 +02:00
parent
9b008dd3d1
commit
4b157ac54f
@ -358,8 +358,10 @@ Socket::Ptr Socket::Accept(void)
|
|||||||
return make_shared<Socket>(fd);
|
return make_shared<Socket>(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::Poll(bool read, bool write)
|
bool Socket::Poll(bool read, bool write)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
fd_set readfds, writefds, exceptfds;
|
fd_set readfds, writefds, exceptfds;
|
||||||
|
|
||||||
@ -374,7 +376,9 @@ void Socket::Poll(bool read, bool write)
|
|||||||
FD_ZERO(&exceptfds);
|
FD_ZERO(&exceptfds);
|
||||||
FD_SET(GetFD(), &exceptfds);
|
FD_SET(GetFD(), &exceptfds);
|
||||||
|
|
||||||
if (select(GetFD() + 1, &readfds, &writefds, &exceptfds, NULL) < 0) {
|
rc = select(GetFD() + 1, &readfds, &writefds, &exceptfds, NULL);
|
||||||
|
|
||||||
|
if (rc < 0) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "select() failed with return code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\"";
|
msgbuf << "select() failed with return code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\"";
|
||||||
Log(LogCritical, "Socket", msgbuf.str());
|
Log(LogCritical, "Socket", msgbuf.str());
|
||||||
@ -389,7 +393,9 @@ void Socket::Poll(bool read, bool write)
|
|||||||
pfd.events = (read ? POLLIN : 0) | (write ? POLLOUT : 0);
|
pfd.events = (read ? POLLIN : 0) | (write ? POLLOUT : 0);
|
||||||
pfd.revents = 0;
|
pfd.revents = 0;
|
||||||
|
|
||||||
if (poll(&pfd, 1, -1) < 0) {
|
rc = poll(&pfd, 1, -1);
|
||||||
|
|
||||||
|
if (rc < 0) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "poll() failed with return code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
|
msgbuf << "poll() failed with return code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
|
||||||
Log(LogCritical, "Socket", msgbuf.str());
|
Log(LogCritical, "Socket", msgbuf.str());
|
||||||
@ -399,6 +405,8 @@ void Socket::Poll(bool read, bool write)
|
|||||||
<< boost::errinfo_errno(errno));
|
<< boost::errinfo_errno(errno));
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
return (rc != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::MakeNonBlocking(void)
|
void Socket::MakeNonBlocking(void)
|
||||||
@ -408,4 +416,4 @@ void Socket::MakeNonBlocking(void)
|
|||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
Utility::SetNonBlocking(GetFD());
|
Utility::SetNonBlocking(GetFD());
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
void Listen(void);
|
void Listen(void);
|
||||||
Socket::Ptr Accept(void);
|
Socket::Ptr Accept(void);
|
||||||
|
|
||||||
void Poll(bool read, bool write);
|
bool Poll(bool read, bool write);
|
||||||
|
|
||||||
void MakeNonBlocking(void);
|
void MakeNonBlocking(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user