1
#include "source/common/network/udp_packet_writer_handler_impl.h"
2

            
3
#include "source/common/buffer/buffer_impl.h"
4
#include "source/common/network/utility.h"
5

            
6
namespace Envoy {
7
namespace Network {
8

            
9
4343
UdpDefaultWriter::UdpDefaultWriter(Network::IoHandle& io_handle) : io_handle_(io_handle) {}
10

            
11
4343
UdpDefaultWriter::~UdpDefaultWriter() = default;
12

            
13
Api::IoCallUint64Result UdpDefaultWriter::writePacket(const Buffer::Instance& buffer,
14
                                                      const Address::Ip* local_ip,
15
596746
                                                      const Address::Instance& peer_address) {
16
596746
  ASSERT(!write_blocked_, "Cannot write while IO handle is blocked.");
17
596746
  Api::IoCallUint64Result result =
18
596746
      Utility::writeToSocket(io_handle_, buffer, local_ip, peer_address);
19
596746
  if (result.err_ && result.err_->getErrorCode() == Api::IoError::IoErrorCode::Again) {
20
    // Writer is blocked when error code received is EWOULDBLOCK/EAGAIN
21
7
    write_blocked_ = true;
22
7
  }
23
596746
  return result;
24
596746
}
25

            
26
} // namespace Network
27
} // namespace Envoy