added accessors for some members

This commit is contained in:
Bob Polis 2020-04-24 16:13:55 +02:00
parent 027f9cb59e
commit db6b0cca5e

View File

@ -20,10 +20,8 @@ using namespace sc::io;
socketstream::socketstream(int domain, int type) socketstream::socketstream(int domain, int type)
: fdstream(), _domain(domain), _type(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"); throw_if_min1_msg(_socket, "could not create socket");
_inbuf.fd(_socket);
_outbuf.fd(_socket);
std::memset(&_sa, 0, sizeof(struct sockaddr_storage)); std::memset(&_sa, 0, sizeof(struct sockaddr_storage));
} }
@ -31,8 +29,8 @@ socketstream::socketstream() : fdstream() {
std::memset(&_sa, 0, sizeof(struct sockaddr_storage)); std::memset(&_sa, 0, sizeof(struct sockaddr_storage));
} }
socketstream::socketstream(socketstream&& other) { socketstream::socketstream(socketstream&& other) : fdstream(other._socket) {
_socket = other._socket; this->socket(other._socket);
_domain = other._domain; _domain = other._domain;
_type = other._type; _type = other._type;
std::memcpy(&_sa, &other._sa, sizeof(struct sockaddr_storage)); std::memcpy(&_sa, &other._sa, sizeof(struct sockaddr_storage));
@ -43,7 +41,7 @@ socketstream::socketstream(socketstream&& other) {
socketstream& socketstream::operator=(socketstream&& other) { socketstream& socketstream::operator=(socketstream&& other) {
if (this != &other) { if (this != &other) {
_socket = other._socket; this->socket(other._socket);
_domain = other._domain; _domain = other._domain;
_type = other._type; _type = other._type;
std::memcpy(&_sa, &other._sa, sizeof(struct sockaddr_storage)); 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; socketstream peer;
socklen_t len = sizeof(struct sockaddr_storage); socklen_t len = sizeof(struct sockaddr_storage);
int active_socket = ::accept(_socket, reinterpret_cast<struct sockaddr*>(&peer._sa), &len); int active_socket = ::accept(_socket, reinterpret_cast<struct sockaddr*>(&peer._sa), &len);
@ -105,6 +103,8 @@ void socketstream::make_server(const socket_address& sa) {
peer._socket = active_socket; peer._socket = active_socket;
peer._domain = _domain; peer._domain = _domain;
peer._type = _type; peer._type = _type;
peer._inbuf.fd(active_socket);
peer._outbuf.fd(active_socket);
return peer; return peer;
} }
@ -188,3 +188,9 @@ socket_address socketstream::address_from_endpoint(const struct sockaddr* endpoi
} }
return sa; return sa;
} }
void socketstream::socket(int sock) {
_socket = sock;
ifd(sock);
ofd(sock);
}