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
4342
UdpDefaultWriter::UdpDefaultWriter(Network::IoHandle& io_handle) : io_handle_(io_handle) {}
10

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

            
13
Api::IoCallUint64Result UdpDefaultWriter::writePacket(const Buffer::Instance& buffer,
14
                                                      const Address::Ip* local_ip,
15
592837
                                                      const Address::Instance& peer_address) {
16
592837
  ASSERT(!write_blocked_, "Cannot write while IO handle is blocked.");
17
592837
  Api::IoCallUint64Result result =
18
592837
      Utility::writeToSocket(io_handle_, buffer, local_ip, peer_address);
19
592837
  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
592837
  return result;
24
592837
}
25

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