Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35e1c55a authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Fix behaviour of Read on closed Socket

Reading from a closed socket should be returning 0, instead
it returns EBADHDL as the file descriptor is replaced by -1
after closing. This causes aborts down the line when RootCanal
fulfills a scheduled Read from a closed HCI socket.

Test: Manual
Change-Id: I637078285de26c48a887b4956397b66df2b5c7bd
parent 44787758
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -67,6 +67,11 @@ PosixAsyncSocket::PosixAsyncSocket(PosixAsyncSocket&& other) {
PosixAsyncSocket::~PosixAsyncSocket() { Close(); }

ssize_t PosixAsyncSocket::Recv(uint8_t* buffer, uint64_t bufferSize) {
  if (fd_ == -1) {
    // Socket was closed locally.
    return 0;
  }

  errno = 0;
  ssize_t res = 0;
  OSI_NO_INTR(res = read(fd_, buffer, bufferSize));