Skip to content

Commit c868bf3

Browse files
rdementiCopilot
authored andcommitted
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8ff5a6e commit c868bf3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

tests/utests/pcm-sensor-server-overflow-utest.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ class SocketDrainer {
7070

7171
~SocketDrainer() {
7272
stop_.store(true);
73-
::shutdown(fd_, SHUT_RDWR);
73+
if (fd_ >= 0) {
74+
::shutdown(fd_, SHUT_RDWR);
75+
}
7476
if (thread_.joinable()) {
7577
thread_.join();
7678
}
79+
if (fd_ >= 0) {
80+
::close(fd_);
81+
fd_ = -1;
82+
}
7783
}
7884

7985
const std::vector<char>& data() const { return received_; }
@@ -124,7 +130,7 @@ TEST(PcmSensorServerOverflowTest, OverflowDoesNotWritePastOutputBuffer)
124130

125131
// After overflow() returns, the put area should have been flushed to the
126132
// socket and the sentinel in inputBuffer_[0] must still be intact.
127-
EXPECT_EQ(static_cast<unsigned char>(buf->inputBuffer_[0]), kSentinel)
133+
EXPECT_EQ(kSentinel, static_cast<unsigned char>(buf->inputBuffer_[0]))
128134
<< "basic_socketbuf::overflow() corrupted inputBuffer_[0]: "
129135
<< "wrote ch=0x" << std::hex << static_cast<int>(kOverflowChar)
130136
<< " past the end of outputBuffer_ (SIZE=" << std::dec
@@ -135,8 +141,7 @@ TEST(PcmSensorServerOverflowTest, OverflowDoesNotWritePastOutputBuffer)
135141

136142
// Release the socket before the buf destructor runs sync(); this keeps
137143
// the test output stable regardless of whether the drainer has already
138-
// exited.
144+
// exited. Resetting buf closes sv[0].
139145
buf.reset();
140-
::close(sv[0]);
141146
// sv[1] is closed by the drainer's shutdown.
142147
}

0 commit comments

Comments
 (0)