From db6b0cca5e81267ef55c13b022bbadfac9e784a8 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Fri, 24 Apr 2020 16:13:55 +0200 Subject: [PATCH] added accessors for some members --- socketstream.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/socketstream.cpp b/socketstream.cpp index a0cc416..9a03c64 100644 --- a/socketstream.cpp +++ b/socketstream.cpp @@ -20,10 +20,8 @@ using namespace sc::io; socketstream::socketstream(int domain, int type) : fdstream(), _domain(domain), _type(type) { - _socket = socket(_domain, _type, 0); + this->socket(::socket(_domain, _type, 0)); throw_if_min1_msg(_socket, "could not create socket"); - _inbuf.fd(_socket); - _outbuf.fd(_socket); std::memset(&_sa, 0, sizeof(struct sockaddr_storage)); } @@ -31,8 +29,8 @@ socketstream::socketstream() : fdstream() { std::memset(&_sa, 0, sizeof(struct sockaddr_storage)); } -socketstream::socketstream(socketstream&& other) { - _socket = other._socket; +socketstream::socketstream(socketstream&& other) : fdstream(other._socket) { + this->socket(other._socket); _domain = other._domain; _type = other._type; std::memcpy(&_sa, &other._sa, sizeof(struct sockaddr_storage)); @@ -43,7 +41,7 @@ socketstream::socketstream(socketstream&& other) { socketstream& socketstream::operator=(socketstream&& other) { if (this != &other) { - _socket = other._socket; + this->socket(other._socket); _domain = other._domain; _type = other._type; std::memcpy(&_sa, &other._sa, sizeof(struct sockaddr_storage)); @@ -97,7 +95,7 @@ void socketstream::make_server(const socket_address& sa) { } } - socketstream socketstream::accept() const { +socketstream socketstream::accept() const { socketstream peer; socklen_t len = sizeof(struct sockaddr_storage); int active_socket = ::accept(_socket, reinterpret_cast(&peer._sa), &len); @@ -105,6 +103,8 @@ void socketstream::make_server(const socket_address& sa) { peer._socket = active_socket; peer._domain = _domain; peer._type = _type; + peer._inbuf.fd(active_socket); + peer._outbuf.fd(active_socket); return peer; } @@ -188,3 +188,9 @@ socket_address socketstream::address_from_endpoint(const struct sockaddr* endpoi } return sa; } + +void socketstream::socket(int sock) { + _socket = sock; + ifd(sock); + ofd(sock); +}