int ossl_quic_get_error(const SSL *s, int i)
{
QCTX ctx;
+ int net_error, last_error;
if (!expect_quic(s, &ctx))
return 0;
- return ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error;
+ quic_lock(ctx.qc);
+ net_error = ossl_quic_channel_net_error(ctx.qc->ch);
+ last_error = ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error;
+ quic_unlock(ctx.qc);
+
+ if (net_error)
+ return SSL_ERROR_SYSCALL;
+
+ return last_error;
}
/*
* Test that we read what we've written.
* Test 0: Non-blocking
* Test 1: Blocking
+ * Test 2: Blocking, introduce socket error, test error handling.
*/
static int test_quic_write_read(int idx)
{
int ssock = 0, csock = 0;
uint64_t sid = UINT64_MAX;
- if (idx == 1 && !qtest_supports_blocking())
+ if (idx >= 1 && !qtest_supports_blocking())
return TEST_skip("Blocking tests not supported in this build");
if (!TEST_ptr(cctx)
|| !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
goto end;
- if (idx == 1) {
+ if (idx >= 1) {
if (!TEST_true(BIO_get_fd(ossl_quic_tserver_get0_rbio(qtserv), &ssock)))
goto end;
if (!TEST_int_gt(csock = SSL_get_rfd(clientquic), 0))
if (!TEST_true(SSL_write_ex(clientquic, msg, msglen, &numbytes))
|| !TEST_size_t_eq(numbytes, msglen))
goto end;
- if (idx == 1) {
+ if (idx >= 1) {
do {
if (!TEST_true(wait_until_sock_readable(ssock)))
goto end;
goto end;
}
+ if (idx >= 2 && j > 0)
+ /* Introduce permanent socket error */
+ BIO_closesocket(csock);
+
ossl_quic_tserver_tick(qtserv);
if (!TEST_true(ossl_quic_tserver_write(qtserv, sid, (unsigned char *)msg,
msglen, &numbytes)))
goto end;
ossl_quic_tserver_tick(qtserv);
SSL_handle_events(clientquic);
+
+ if (idx >= 2 && j > 0) {
+ if (!TEST_false(SSL_read_ex(clientquic, buf, 1, &numbytes))
+ || !TEST_int_eq(SSL_get_error(clientquic, 0),
+ SSL_ERROR_SYSCALL)
+ || !TEST_false(SSL_write_ex(clientquic, msg, msglen,
+ &numbytes))
+ || !TEST_int_eq(SSL_get_error(clientquic, 0),
+ SSL_ERROR_SYSCALL))
+ goto end;
+ break;
+ }
+
/*
* In blocking mode the SSL_read_ex call will block until the socket is
* readable and has our data. In non-blocking mode we're doing everything
if (privkey == NULL)
goto err;
- ADD_ALL_TESTS(test_quic_write_read, 2);
+ ADD_ALL_TESTS(test_quic_write_read, 3);
ADD_TEST(test_ciphersuites);
ADD_TEST(test_version);
#if defined(DO_SSL_TRACE_TEST)