| 7105 | } |
| 7106 | |
| 7107 | static int waitForReadiness (const int handle, const bool forReading, const int timeoutMsecs) noexcept |
| 7108 | { |
| 7109 | struct timeval timeout; |
| 7110 | struct timeval* timeoutp; |
| 7111 | |
| 7112 | if (timeoutMsecs >= 0) |
| 7113 | { |
| 7114 | timeout.tv_sec = timeoutMsecs / 1000; |
| 7115 | timeout.tv_usec = (timeoutMsecs % 1000) * 1000; |
| 7116 | timeoutp = &timeout; |
| 7117 | } |
| 7118 | else |
| 7119 | { |
| 7120 | timeoutp = 0; |
| 7121 | } |
| 7122 | |
| 7123 | fd_set rset, wset; |
| 7124 | FD_ZERO (&rset); |
| 7125 | FD_SET (handle, &rset); |
| 7126 | FD_ZERO (&wset); |
| 7127 | FD_SET (handle, &wset); |
| 7128 | |
| 7129 | fd_set* const prset = forReading ? &rset : nullptr; |
| 7130 | fd_set* const pwset = forReading ? nullptr : &wset; |
| 7131 | |
| 7132 | #if JUCE_WINDOWS |
| 7133 | if (select (handle + 1, prset, pwset, 0, timeoutp) < 0) |
| 7134 | return -1; |
| 7135 | #else |
| 7136 | { |
| 7137 | int result; |
| 7138 | while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0 |
| 7139 | && errno == EINTR) |
| 7140 | { |
| 7141 | } |
| 7142 | |
| 7143 | if (result < 0) |
| 7144 | return -1; |
| 7145 | } |
| 7146 | #endif |
| 7147 | |
| 7148 | { |
| 7149 | int opt; |
| 7150 | juce_socklen_t len = sizeof (opt); |
| 7151 | |
| 7152 | if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0 |
| 7153 | || opt != 0) |
| 7154 | return -1; |
| 7155 | } |
| 7156 | |
| 7157 | return FD_ISSET (handle, forReading ? &rset : &wset) ? 1 : 0; |
| 7158 | } |
| 7159 | |
| 7160 | static bool setSocketBlockingState (const int handle, const bool shouldBlock) noexcept |
| 7161 | { |
no outgoing calls
no test coverage detected