MCPcopy Create free account
hub / github.com/apache/cloudberry / pgtls_write

Function pgtls_write

src/interfaces/libpq/fe-secure-openssl.c:280–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278}
279
280ssize_t
281pgtls_write(PGconn *conn, const void *ptr, size_t len)
282{
283 ssize_t n;
284 int result_errno = 0;
285 char sebuf[PG_STRERROR_R_BUFLEN];
286 int err;
287 unsigned long ecode;
288
289 SOCK_ERRNO_SET(0);
290 ERR_clear_error();
291 n = SSL_write(conn->ssl, ptr, len);
292 err = SSL_get_error(conn->ssl, n);
293 ecode = (err != SSL_ERROR_NONE || n < 0) ? ERR_get_error() : 0;
294 switch (err)
295 {
296 case SSL_ERROR_NONE:
297 if (n < 0)
298 {
299 /* Not supposed to happen, so we don't translate the msg */
300 appendPQExpBufferStr(&conn->errorMessage,
301 "SSL_write failed but did not provide error information\n");
302 /* assume the connection is broken */
303 result_errno = ECONNRESET;
304 }
305 break;
306 case SSL_ERROR_WANT_READ:
307
308 /*
309 * Returning 0 here causes caller to wait for write-ready, which
310 * is not really the right thing, but it's the best we can do.
311 */
312 n = 0;
313 break;
314 case SSL_ERROR_WANT_WRITE:
315 n = 0;
316 break;
317 case SSL_ERROR_SYSCALL:
318 if (n < 0)
319 {
320 result_errno = SOCK_ERRNO;
321 if (result_errno == EPIPE || result_errno == ECONNRESET)
322 appendPQExpBufferStr(&conn->errorMessage,
323 libpq_gettext("server closed the connection unexpectedly\n"
324 "\tThis probably means the server terminated abnormally\n"
325 "\tbefore or while processing the request.\n"));
326 else
327 appendPQExpBuffer(&conn->errorMessage,
328 libpq_gettext("SSL SYSCALL error: %s\n"),
329 SOCK_STRERROR(result_errno,
330 sebuf, sizeof(sebuf)));
331 }
332 else
333 {
334 appendPQExpBufferStr(&conn->errorMessage,
335 libpq_gettext("SSL SYSCALL error: EOF detected\n"));
336 /* assume the connection is broken */
337 result_errno = ECONNRESET;

Callers 1

pqsecure_writeFunction · 0.85

Calls 5

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
appendPQExpBufferFunction · 0.85
SSLerrfreeFunction · 0.85
SSLerrmessageFunction · 0.70

Tested by

no test coverage detected