* Check whether this socket can send or receive something. * @return \c true when there is something to receive. * @note Sets #writable if more data can be sent. */
| 192 | * @note Sets #writable if more data can be sent. |
| 193 | */ |
| 194 | bool NetworkTCPSocketHandler::CanSendReceive() |
| 195 | { |
| 196 | assert(this->sock != INVALID_SOCKET); |
| 197 | |
| 198 | fd_set read_fd, write_fd; |
| 199 | struct timeval tv; |
| 200 | |
| 201 | FD_ZERO(&read_fd); |
| 202 | FD_ZERO(&write_fd); |
| 203 | |
| 204 | FD_SET(this->sock, &read_fd); |
| 205 | FD_SET(this->sock, &write_fd); |
| 206 | |
| 207 | tv.tv_sec = tv.tv_usec = 0; // don't block at all. |
| 208 | if (select(FD_SETSIZE, &read_fd, &write_fd, nullptr, &tv) < 0) return false; |
| 209 | |
| 210 | this->writable = !!FD_ISSET(this->sock, &write_fd); |
| 211 | return FD_ISSET(this->sock, &read_fd) != 0; |
| 212 | } |
no outgoing calls
no test coverage detected