fixed bug not clearing socket descriptor

This commit is contained in:
Erik Frojdh 2019-03-29 10:14:07 +01:00
parent 78fcb7eb98
commit ed9dc3b386

View File

@ -16,7 +16,7 @@ namespace sls {
DataSocket::DataSocket(int socketId) : socketId_(socketId) {} DataSocket::DataSocket(int socketId) : socketId_(socketId) {}
DataSocket::~DataSocket() { DataSocket::~DataSocket() {
if (socketId_ == -1) { if (socketId_ <= 0) {
return; return;
} else { } else {
try { try {
@ -78,7 +78,11 @@ int DataSocket::setTimeOut(int t_seconds) {
void DataSocket::close() { void DataSocket::close() {
if (socketId_ > 0) { if (socketId_ > 0) {
::close(socketId_); if(::close(socketId_)){
throw SocketError("could not close socket");
}
socketId_ = 0;
} else { } else {
throw std::runtime_error("Socket ERROR: close called on bad socket\n"); throw std::runtime_error("Socket ERROR: close called on bad socket\n");
} }