summaryrefslogtreecommitdiff
path: root/extra/yassl/src/socket_wrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'extra/yassl/src/socket_wrapper.cpp')
-rw-r--r--extra/yassl/src/socket_wrapper.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp
index c6611803421..803f4b01249 100644
--- a/extra/yassl/src/socket_wrapper.cpp
+++ b/extra/yassl/src/socket_wrapper.cpp
@@ -58,7 +58,7 @@ namespace yaSSL {
Socket::Socket(socket_t s)
- : socket_(s)
+ : socket_(s), wouldBlock_(false)
{}
@@ -123,17 +123,21 @@ uint Socket::send(const byte* buf, unsigned int sz, int flags) const
}
-uint Socket::receive(byte* buf, unsigned int sz, int flags) const
+uint Socket::receive(byte* buf, unsigned int sz, int flags)
{
assert(socket_ != INVALID_SOCKET);
+ wouldBlock_ = false;
+
int recvd = ::recv(socket_, reinterpret_cast<char *>(buf), sz, flags);
// idea to seperate error from would block by arnetheduck@gmail.com
if (recvd == -1) {
if (get_lastError() == SOCKET_EWOULDBLOCK ||
- get_lastError() == SOCKET_EAGAIN)
+ get_lastError() == SOCKET_EAGAIN) {
+ wouldBlock_ = true;
return 0;
}
+ }
else if (recvd == 0)
return static_cast<uint>(-1);
@@ -142,7 +146,7 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags) const
// wait if blocking for input, return false for error
-bool Socket::wait() const
+bool Socket::wait()
{
byte b;
return receive(&b, 1, MSG_PEEK) != static_cast<uint>(-1);
@@ -166,6 +170,12 @@ int Socket::get_lastError()
}
+bool Socket::WouldBlock() const
+{
+ return wouldBlock_;
+}
+
+
void Socket::set_lastError(int errorCode)
{
#ifdef _WIN32