summaryrefslogtreecommitdiff
path: root/extra/yassl/src/socket_wrapper.cpp
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2012-08-14 17:23:34 +0300
committerMichael Widenius <monty@askmonty.org>2012-08-14 17:23:34 +0300
commit60589aeee03949033c66da5c1eae70d4342179fc (patch)
tree1cd399dbed17c5c7b4ed16eb7b872dc979af1c93 /extra/yassl/src/socket_wrapper.cpp
parentb39e6e3d093b45f792959ef06fea1c175263ae1a (diff)
downloadmariadb-git-60589aeee03949033c66da5c1eae70d4342179fc.tar.gz
Next part of merge. See TODO for details
Diffstat (limited to 'extra/yassl/src/socket_wrapper.cpp')
-rw-r--r--extra/yassl/src/socket_wrapper.cpp76
1 files changed, 58 insertions, 18 deletions
diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp
index d88df13c08e..cf761d912e6 100644
--- a/extra/yassl/src/socket_wrapper.cpp
+++ b/extra/yassl/src/socket_wrapper.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -52,11 +52,33 @@
#endif // _WIN32
+namespace {
+
+
+extern "C" long system_recv(void *ptr, void *buf, size_t count, int flags)
+{
+ yaSSL::socket_t *socket = (yaSSL::socket_t *) ptr;
+ return ::recv(*socket, reinterpret_cast<char *>(buf), count, flags);
+}
+
+
+extern "C" long system_send(void *ptr, const void *buf, size_t count,
+ int flags)
+{
+ yaSSL::socket_t *socket = (yaSSL::socket_t *) ptr;
+ return ::send(*socket, reinterpret_cast<const char *>(buf), count, flags);
+}
+
+
+}
+
+
namespace yaSSL {
Socket::Socket(socket_t s)
- : socket_(s), wouldBlock_(false), nonBlocking_(false)
+ : socket_(s), wouldBlock_(false), nonBlocking_(false),
+ ptr_(&socket_), send_func_(system_send), recv_func_(system_recv)
{}
@@ -108,8 +130,25 @@ uint Socket::get_ready() const
return ready;
}
+void Socket::set_transport_ptr(void *ptr)
+{
+ ptr_ = ptr;
+}
+
-uint Socket::send(const byte* buf, unsigned int sz, unsigned int& written,
+void Socket::set_transport_recv_function(yaSSL_recv_func_t recv_func)
+{
+ recv_func_ = recv_func;
+}
+
+
+void Socket::set_transport_send_function(yaSSL_send_func_t send_func)
+{
+ send_func_ = send_func;
+}
+
+
+uint Socket::send(const byte* buf, unsigned int sz, unsigned int &written,
int flags)
{
const byte* pos = buf;
@@ -117,22 +156,23 @@ uint Socket::send(const byte* buf, unsigned int sz, unsigned int& written,
wouldBlock_ = false;
- while (pos != end) {
- int sent = ::send(socket_, reinterpret_cast<const char *>(pos),
- static_cast<int>(end - pos), flags);
- if (sent == -1) {
- if (get_lastError() == SOCKET_EWOULDBLOCK ||
- get_lastError() == SOCKET_EAGAIN) {
- wouldBlock_ = true; // would have blocked this time only
- nonBlocking_ = true; // nonblocking, win32 only way to tell
- return 0;
- }
- return static_cast<uint>(-1);
+ while (pos != end)
+ {
+ int sent = send_func_(ptr_, pos, static_cast<int>(end - pos), flags);
+ if (sent == -1)
+ {
+ if (get_lastError() == SOCKET_EWOULDBLOCK ||
+ get_lastError() == SOCKET_EAGAIN)
+ {
+ wouldBlock_ = true; // would have blocked this time only
+ nonBlocking_ = true; // nonblocking, win32 only way to tell
+ return 0;
}
- pos += sent;
- written += sent;
+ return static_cast<uint>(-1);
+ }
+ pos += sent;
+ written += sent;
}
-
return sz;
}
@@ -141,7 +181,7 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags)
{
wouldBlock_ = false;
- int recvd = ::recv(socket_, reinterpret_cast<char *>(buf), sz, flags);
+ int recvd = recv_func_(ptr_, buf, sz, flags);
// idea to seperate error from would block by arnetheduck@gmail.com
if (recvd == -1) {