1#include <IO/WriteBufferFromFileDescriptorDiscardOnFailure.h>
2
3namespace ProfileEvents
4{
5 extern const Event CannotWriteToWriteBufferDiscard;
6}
7
8namespace DB
9{
10
11void WriteBufferFromFileDescriptorDiscardOnFailure::nextImpl()
12{
13 size_t bytes_written = 0;
14 while (bytes_written != offset())
15 {
16 ssize_t res = ::write(fd, working_buffer.begin() + bytes_written, offset() - bytes_written);
17
18 if ((-1 == res || 0 == res) && errno != EINTR)
19 {
20 ProfileEvents::increment(ProfileEvents::CannotWriteToWriteBufferDiscard);
21 break; /// Discard
22 }
23
24 if (res > 0)
25 bytes_written += res;
26 }
27}
28
29}
30