| 200 | } |
| 201 | |
| 202 | static int do_packet_write(const int fd_out, const char *buf, size_t size, |
| 203 | struct strbuf *err) |
| 204 | { |
| 205 | char header[4]; |
| 206 | size_t packet_size; |
| 207 | |
| 208 | if (size > LARGE_PACKET_DATA_MAX) { |
| 209 | strbuf_addstr(err, _("packet write failed - data exceeds max packet size")); |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | packet_trace(buf, size, 1); |
| 214 | packet_size = size + 4; |
| 215 | |
| 216 | set_packet_header(header, packet_size); |
| 217 | |
| 218 | /* |
| 219 | * Write the header and the buffer in 2 parts so that we do |
| 220 | * not need to allocate a buffer or rely on a static buffer. |
| 221 | * This also avoids putting a large buffer on the stack which |
| 222 | * might have multi-threading issues. |
| 223 | */ |
| 224 | |
| 225 | if (write_in_full(fd_out, header, 4) < 0 || |
| 226 | write_in_full(fd_out, buf, size) < 0) { |
| 227 | strbuf_addf(err, _("packet write failed: %s"), strerror(errno)); |
| 228 | return -1; |
| 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | static int packet_write_gently(const int fd_out, const char *buf, size_t size) |
| 234 | { |
no test coverage detected