Skip to content

Commit 32cee3b

Browse files
markovamariardementi
authored andcommitted
Added socket 0 processing in close, setSocket and sync
1 parent cb19878 commit 32cee3b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/pcm-sensor-server.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ class basic_socketbuf : public std::basic_streambuf<CharT> {
799799

800800
void setSocket( int socketFD ) {
801801
socketFD_ = socketFD;
802+
if(!socketFD) // avoid work with 0 socket after closure socket and set value to 0
803+
return;
802804
// When receiving the socket descriptor, set the timeout
803805
const auto res = setsockopt( socketFD_, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout_, sizeof(struct timeval) );
804806
if (res != 0)
@@ -877,6 +879,8 @@ class basic_socketbuf : public std::basic_streambuf<CharT> {
877879
}
878880

879881
int sync() override {
882+
if ( socketFD_ == 0 ) // Socket is closed already
883+
return 0;
880884
int_type ret = writeToSocket();
881885
if ( traits_type::eof() == ret )
882886
return -1;
@@ -1053,7 +1057,7 @@ class basic_socketstream : public std::basic_iostream<CharT, Traits> {
10531057

10541058
void close() {
10551059
const auto s = socketBuffer_.socket();
1056-
if (s != -1) ::close(s);
1060+
if (s != 0) ::close(s);
10571061
socketBuffer_.setSocket( 0 );
10581062
}
10591063

0 commit comments

Comments
 (0)