added close() to socketstream

This commit is contained in:
2020-04-26 16:22:56 +02:00
parent 5f3364e805
commit 98d3e88872
2 changed files with 7 additions and 0 deletions

View File

@ -149,6 +149,8 @@ namespace sc {
// cleanup: socketstream is RAII class for open socket
virtual ~socketstream();
bool is_open() { return _iobuf.fd() != -1; }
void close();
// server
void make_server(const socket_address& sa);

View File

@ -53,8 +53,13 @@ socketstream& socketstream::operator=(socketstream&& other) {
}
socketstream::~socketstream() {
close();
}
void socketstream::close() {
if (_iobuf.fd() != -1) {
::close(_iobuf.fd());
_iobuf.fd(-1);
}
}