MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CanSendReceive

Method CanSendReceive

src/network/core/tcp.cpp:194–212  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

192 * @note Sets #writable if more data can be sent.
193 */
194bool 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}

Callers 6

ReceiveMethod · 0.80
SendReceiveMethod · 0.80
SendReceiveMethod · 0.80
SendReceiveMethod · 0.80
SendReceiveMethod · 0.80
ReceiveMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected