Skip to content

Commit

Permalink
Improved error processing for write_simple_packet
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-odintsov committed May 24, 2022
1 parent a70fcfc commit ce2eddc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/fast_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,17 +1400,23 @@ bool write_simple_packet(int fd, simple_packet_t& packet, bool populate_ipv6) {
kj::Array<capnp::word> words = messageToFlatArray(message);
kj::ArrayPtr<kj::byte> bytes = words.asBytes();

size_t write_result = write(fd, bytes.begin(), bytes.size());
ssize_t write_result = write(fd, bytes.begin(), bytes.size());

// If write returned error or we could not write whole packet notify caller about it
if (write_result < 0 || write_result != bytes.size()) {
// If write returned error then stop processing
if (write_result < 0) {
// If we received error from it, let's provide details about it in DEBUG mode
if (write_result == -1) {
logger << log4cpp::Priority::DEBUG << "write in write_simple_packet returned error: " << errno;
}

return false;
}

// we could not write whole packet notify caller about it
if (write_result != bytes.size()) {
logger << log4cpp::Priority::DEBUG << "write in write_simple_packet did not write all data";
return false;
}
} catch (...) {
// logger << log4cpp::Priority::ERROR << "writeSimplePacket failed with error";
return false;
Expand Down

0 comments on commit ce2eddc

Please sign in to comment.