Updated `LibeventSSLSocketImpl` for Windows file descriptors. This patch introduces the `int_fd` abstraction we use elsewhere to the `LibeventSSLSocketImpl` for dealing with Linux versus Windows file descriptors. This is necessary because on Windows, the consumer of `LibeventSSLSocketImpl::create()` etc. already use `int_fd`.
Note that this does not break Linux systems, as `int_fd` is defined as `int` on all non-Windows systems. On Windows, however, in `evbuffer_add_file` we must explicitly convert from `int_fd` (holding a Windows file handle) to a CRT `int` file descriptor (the platform-specific call to `crt()`). We have to correct the type expected by `evconnlistener_new` from `int` to `evutil_socket_t`. This previously worked as just an `int` because that is the underlying type used for sockets by libevent on Linux, but it instead uses `intptr_t` on Windows. The `int_fd` abstraction can be casted to `intptr_t` (and thus `evutil_socket_t`) automatically, but not `int`, and so correcting the type to `evutil_socket_t` allows us to use this lambda for the listener. Review: https://reviews.apache.org/r/62510/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f06e6184 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f06e6184 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f06e6184 Branch: refs/heads/master Commit: f06e6184b0d6cc4a3245a714e5b56f26eb454233 Parents: e76759a Author: Andrew Schwartzmeyer <and...@schwartzmeyer.com> Authored: Wed Oct 11 14:54:58 2017 -0700 Committer: Joseph Wu <josep...@apache.org> Committed: Wed Oct 11 14:54:58 2017 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/src/libevent_ssl_socket.cpp | 12 ++++++++---- 3rdparty/libprocess/src/libevent_ssl_socket.hpp | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/f06e6184/3rdparty/libprocess/src/libevent_ssl_socket.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/libevent_ssl_socket.cpp b/3rdparty/libprocess/src/libevent_ssl_socket.cpp index 5767ce0..1c95eba 100644 --- a/3rdparty/libprocess/src/libevent_ssl_socket.cpp +++ b/3rdparty/libprocess/src/libevent_ssl_socket.cpp @@ -84,7 +84,7 @@ namespace process { namespace network { namespace internal { -Try<std::shared_ptr<SocketImpl>> LibeventSSLSocketImpl::create(int s) +Try<std::shared_ptr<SocketImpl>> LibeventSSLSocketImpl::create(int_fd s) { openssl::initialize(); @@ -476,7 +476,7 @@ void LibeventSSLSocketImpl::event_callback(short events) } -LibeventSSLSocketImpl::LibeventSSLSocketImpl(int _s) +LibeventSSLSocketImpl::LibeventSSLSocketImpl(int_fd _s) : SocketImpl(_s), bev(nullptr), listener(nullptr), @@ -487,7 +487,7 @@ LibeventSSLSocketImpl::LibeventSSLSocketImpl(int _s) LibeventSSLSocketImpl::LibeventSSLSocketImpl( - int _s, + int_fd _s, bufferevent* _bev, Option<string>&& _peer_hostname) : SocketImpl(_s), @@ -855,7 +855,11 @@ Future<size_t> LibeventSSLSocketImpl::sendfile( // descriptor and close it after it has finished reading it. int result = evbuffer_add_file( bufferevent_get_output(self->bev), +#ifdef __WINDOWS__ + owned_fd.crt(), +#else owned_fd, +#endif // __WINDOWS__ offset, size); CHECK_EQ(0, result); @@ -883,7 +887,7 @@ Try<Nothing> LibeventSSLSocketImpl::listen(int backlog) listener = evconnlistener_new( base, [](evconnlistener* listener, - int socket, + evutil_socket_t socket, sockaddr* addr, int addr_length, void* arg) { http://git-wip-us.apache.org/repos/asf/mesos/blob/f06e6184/3rdparty/libprocess/src/libevent_ssl_socket.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/libevent_ssl_socket.hpp b/3rdparty/libprocess/src/libevent_ssl_socket.hpp index 9493a50..640fa67 100644 --- a/3rdparty/libprocess/src/libevent_ssl_socket.hpp +++ b/3rdparty/libprocess/src/libevent_ssl_socket.hpp @@ -33,9 +33,9 @@ class LibeventSSLSocketImpl : public SocketImpl { public: // See 'Socket::create()'. - static Try<std::shared_ptr<SocketImpl>> create(int s); + static Try<std::shared_ptr<SocketImpl>> create(int_fd s); - LibeventSSLSocketImpl(int _s); + LibeventSSLSocketImpl(int_fd _s); ~LibeventSSLSocketImpl() override; @@ -71,7 +71,7 @@ private: struct AcceptRequest { AcceptRequest( - int _socket, + int_fd _socket, evconnlistener* _listener, const Option<net::IP>& _ip) : peek_event(nullptr), @@ -81,7 +81,7 @@ private: event* peek_event; Promise<std::shared_ptr<SocketImpl>> promise; evconnlistener* listener; - int socket; + int_fd socket; Option<net::IP> ip; }; @@ -110,7 +110,7 @@ private: // This is a private constructor used by the accept helper // functions. LibeventSSLSocketImpl( - int _s, + int_fd _s, bufferevent* bev, Option<std::string>&& peer_hostname);