summaryrefslogtreecommitdiff
path: root/src/sbearssl
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-11-22 21:49:58 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-11-22 21:49:58 +0000
commitbae11b88357db72b19413cd05c62ac9242b9b597 (patch)
treee797f9d4ba09ece0b41cab424052915bee03052a /src/sbearssl
parent4fb917263ac30373cb3e5dfe3e207369eb238def (diff)
downloads6-networking-bae11b88357db72b19413cd05c62ac9242b9b597.tar.xz
Fix a few bugs. sbearssl appears to be working.
Diffstat (limited to 'src/sbearssl')
-rw-r--r--src/sbearssl/sbearssl_run.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/sbearssl/sbearssl_run.c b/src/sbearssl/sbearssl_run.c
index c8ff2fe..44dbe88 100644
--- a/src/sbearssl/sbearssl_run.c
+++ b/src/sbearssl/sbearssl_run.c
@@ -19,7 +19,13 @@ void sbearssl_run (br_ssl_engine_context *ctx, int *fds, tain_t const *tto, uint
iopause_fd x[4] ;
unsigned int xindex[4] ;
int markedforflush = 0 ;
- int handshake_done = 0 ;
+ int handshake_notdone = 1 ;
+
+ if (ndelay_on(fds[0]) < 0
+ || ndelay_on(fds[1]) < 0
+ || ndelay_on(fds[2]) < 0
+ || ndelay_on(fds[3]) < 0)
+ strerr_diefu1sys(111, "set fds non-blocking") ;
for (;;)
{
@@ -35,24 +41,17 @@ void sbearssl_run (br_ssl_engine_context *ctx, int *fds, tain_t const *tto, uint
break ;
}
- if (!handshake_done)
- {
- size_t dummy ;
- if (br_ssl_engine_recvapp_buf(ctx, &dummy))
- {
- if (!(*cb)(ctx, cbarg))
- strerr_diefu1sys(111, "post-handshake callback failed") ;
- handshake_done = 1 ;
- }
- }
-
- tain_add_g(&deadline, fds[0] >= 0 && fds[2] >= 0 && state & (BR_SSL_SENDAPP | BR_SSL_RECVREC) ? tto : &tain_infinite_relative) ;
-
if (fds[0] >= 0 && state & BR_SSL_SENDAPP)
{
x[j].fd = fds[0] ;
x[j].events = IOPAUSE_READ ;
xindex[0] = j++ ;
+ if (handshake_notdone)
+ {
+ if (!(*cb)(ctx, cbarg))
+ strerr_diefu1sys(111, "post-handshake callback failed") ;
+ handshake_notdone = 0 ;
+ }
}
else xindex[0] = 4 ;
if (fds[1] >= 0 && state & BR_SSL_RECVAPP)
@@ -77,7 +76,8 @@ void sbearssl_run (br_ssl_engine_context *ctx, int *fds, tain_t const *tto, uint
}
else xindex[3] = 4 ;
- if (xindex[0] == 4 && xindex[1] == 4 && xindex[3] == 4) break ;
+ if (!j) break ;
+ tain_add_g(&deadline, fds[0] >= 0 && fds[2] >= 0 && state & (BR_SSL_SENDAPP | BR_SSL_RECVREC) ? tto : &tain_infinite_relative) ;
r = iopause_g(x, j, &deadline) ;
if (r < 0) strerr_diefu1sys(111, "iopause") ;
else if (!r) break ;