| 318 | } |
| 319 | |
| 320 | ssize_t |
| 321 | pqsecure_raw_write(PGconn *conn, const void *ptr, size_t len) |
| 322 | { |
| 323 | ssize_t n; |
| 324 | int flags = 0; |
| 325 | int result_errno = 0; |
| 326 | char sebuf[PG_STRERROR_R_BUFLEN]; |
| 327 | |
| 328 | DECLARE_SIGPIPE_INFO(spinfo); |
| 329 | |
| 330 | #ifdef MSG_NOSIGNAL |
| 331 | if (conn->sigpipe_flag) |
| 332 | flags |= MSG_NOSIGNAL; |
| 333 | |
| 334 | retry_masked: |
| 335 | #endif /* MSG_NOSIGNAL */ |
| 336 | |
| 337 | DISABLE_SIGPIPE(conn, spinfo, return -1); |
| 338 | |
| 339 | n = send(conn->sock, ptr, len, flags); |
| 340 | |
| 341 | if (n < 0) |
| 342 | { |
| 343 | result_errno = SOCK_ERRNO; |
| 344 | |
| 345 | /* |
| 346 | * If we see an EINVAL, it may be because MSG_NOSIGNAL isn't available |
| 347 | * on this machine. So, clear sigpipe_flag so we don't try the flag |
| 348 | * again, and retry the send(). |
| 349 | */ |
| 350 | #ifdef MSG_NOSIGNAL |
| 351 | if (flags != 0 && result_errno == EINVAL) |
| 352 | { |
| 353 | conn->sigpipe_flag = false; |
| 354 | flags = 0; |
| 355 | goto retry_masked; |
| 356 | } |
| 357 | #endif /* MSG_NOSIGNAL */ |
| 358 | |
| 359 | /* Set error message if appropriate */ |
| 360 | switch (result_errno) |
| 361 | { |
| 362 | #ifdef EAGAIN |
| 363 | case EAGAIN: |
| 364 | #endif |
| 365 | #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN)) |
| 366 | case EWOULDBLOCK: |
| 367 | #endif |
| 368 | case EINTR: |
| 369 | /* no error message, caller is expected to retry */ |
| 370 | break; |
| 371 | |
| 372 | case EPIPE: |
| 373 | /* Set flag for EPIPE */ |
| 374 | REMEMBER_EPIPE(spinfo, true); |
| 375 | |
| 376 | /* FALL THRU */ |
| 377 |
no test coverage detected