| 2253 | } |
| 2254 | |
| 2255 | void write_buf(int f, const char *buf, size_t len) |
| 2256 | { |
| 2257 | size_t pos, siz; |
| 2258 | |
| 2259 | if (f != iobuf.out_fd) { |
| 2260 | safe_write(f, buf, len); |
| 2261 | goto batch_copy; |
| 2262 | } |
| 2263 | |
| 2264 | if (iobuf.out.len + len > iobuf.out.size) |
| 2265 | perform_io(len, PIO_NEED_OUTROOM); |
| 2266 | |
| 2267 | pos = iobuf.out.pos + iobuf.out.len; /* Must be set after any flushing. */ |
| 2268 | if (pos >= iobuf.out.size) |
| 2269 | pos -= iobuf.out.size; |
| 2270 | |
| 2271 | /* Handle a split copy if we wrap around the end of the circular buffer. */ |
| 2272 | if (pos >= iobuf.out.pos && (siz = iobuf.out.size - pos) < len) { |
| 2273 | memcpy(iobuf.out.buf + pos, buf, siz); |
| 2274 | memcpy(iobuf.out.buf, buf + siz, len - siz); |
| 2275 | } else |
| 2276 | memcpy(iobuf.out.buf + pos, buf, len); |
| 2277 | |
| 2278 | iobuf.out.len += len; |
| 2279 | total_data_written += len; |
| 2280 | |
| 2281 | batch_copy: |
| 2282 | if (f == write_batch_monitor_out) |
| 2283 | safe_write(batch_fd, buf, len); |
| 2284 | } |
| 2285 | |
| 2286 | /* Write a string to the connection */ |
| 2287 | void write_sbuf(int f, const char *buf) |
no test coverage detected