| 236 | } |
| 237 | |
| 238 | ssize_t |
| 239 | pqsecure_raw_read(PGconn *conn, void *ptr, size_t len) |
| 240 | { |
| 241 | ssize_t n; |
| 242 | int result_errno = 0; |
| 243 | char sebuf[PG_STRERROR_R_BUFLEN]; |
| 244 | |
| 245 | n = recv(conn->sock, ptr, len, 0); |
| 246 | |
| 247 | if (n < 0) |
| 248 | { |
| 249 | result_errno = SOCK_ERRNO; |
| 250 | |
| 251 | /* Set error message if appropriate */ |
| 252 | switch (result_errno) |
| 253 | { |
| 254 | #ifdef EAGAIN |
| 255 | case EAGAIN: |
| 256 | #endif |
| 257 | #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN)) |
| 258 | case EWOULDBLOCK: |
| 259 | #endif |
| 260 | case EINTR: |
| 261 | /* no error message, caller is expected to retry */ |
| 262 | break; |
| 263 | |
| 264 | case EPIPE: |
| 265 | case ECONNRESET: |
| 266 | appendPQExpBufferStr(&conn->errorMessage, |
| 267 | libpq_gettext("server closed the connection unexpectedly\n" |
| 268 | "\tThis probably means the server terminated abnormally\n" |
| 269 | "\tbefore or while processing the request.\n")); |
| 270 | break; |
| 271 | |
| 272 | default: |
| 273 | appendPQExpBuffer(&conn->errorMessage, |
| 274 | libpq_gettext("could not receive data from server: %s\n"), |
| 275 | SOCK_STRERROR(result_errno, |
| 276 | sebuf, sizeof(sebuf))); |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | /* ensure we return the intended errno to caller */ |
| 282 | SOCK_ERRNO_SET(result_errno); |
| 283 | |
| 284 | return n; |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Write data to a secure connection. |
no test coverage detected