diff options
author | rubidium <rubidium@openttd.org> | 2010-10-15 19:33:08 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-10-15 19:33:08 +0000 |
commit | f555e6d72ed960a9311b8a38321ffb3d799ecc18 (patch) | |
tree | 4fc4fa0b87d9bde361b2945f308fd0246c51ecf1 /src/network/core/tcp.cpp | |
parent | 780f120c3275a78b33271596fb8daaa45dd41c7c (diff) | |
download | openttd-f555e6d72ed960a9311b8a38321ffb3d799ecc18.tar.xz |
(svn r20933) -Codechange: move some more client related methods and such to network_client.cpp
Diffstat (limited to 'src/network/core/tcp.cpp')
-rw-r--r-- | src/network/core/tcp.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index 39f90569f..cdf072cec 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -214,4 +214,31 @@ bool NetworkTCPSocketHandler::IsPacketQueueEmpty() return this->packet_queue == NULL; } +/** + * Check whether this socket can send or receive something. + * @return \c true when there is something to receive. + * @note Sets #writeable if more data can be sent. + */ +bool NetworkTCPSocketHandler::CanSendReceive() +{ + fd_set read_fd, write_fd; + struct timeval tv; + + FD_ZERO(&read_fd); + FD_ZERO(&write_fd); + + FD_SET(this->sock, &read_fd); + FD_SET(this->sock, &write_fd); + + tv.tv_sec = tv.tv_usec = 0; // don't block at all. +#if !defined(__MORPHOS__) && !defined(__AMIGA__) + select(FD_SETSIZE, &read_fd, &write_fd, NULL, &tv); +#else + WaitSelect(FD_SETSIZE, &read_fd, &write_fd, NULL, &tv, NULL); +#endif + + this->writable = !!FD_ISSET(this->sock, &write_fd); + return FD_ISSET(this->sock, &read_fd); +} + #endif /* ENABLE_NETWORK */ |