summaryrefslogtreecommitdiff
path: root/src/sbearssl/sbearssl_run.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbearssl/sbearssl_run.c')
-rw-r--r--src/sbearssl/sbearssl_run.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/sbearssl/sbearssl_run.c b/src/sbearssl/sbearssl_run.c
index 9f59302..af8b10e 100644
--- a/src/sbearssl/sbearssl_run.c
+++ b/src/sbearssl/sbearssl_run.c
@@ -33,20 +33,19 @@ void sbearssl_run (br_ssl_engine_context *ctx, int *fd, tain const *tto, uint32_
int handshake_done = 0 ;
int closing = 0 ;
tain deadline ;
+ tain_add_g(&deadline, tto) ;
if (ndelay_on(fd[0]) == -1
|| ndelay_on(fd[1]) == -1
|| ndelay_on(fd[2]) == -1
|| ndelay_on(fd[3]) == -1)
strerr_diefu1sys(111, "set fds non-blocking") ;
- tain_add_g(&deadline, tto) ;
- while (fd[0] >= 0 || fd[1] >= 0 || fd[3] >= 0)
+ while ((fd[0] >= 0 || fd[1] >= 0 || fd[3] >= 0) && !(state & BR_SSL_CLOSED))
{
uint8_t y[4] ;
uint8_t j = 0 ;
-
/* Preparation */
if (fd[0] >= 0 && state & BR_SSL_SENDAPP)
@@ -64,10 +63,10 @@ void sbearssl_run (br_ssl_engine_context *ctx, int *fd, tain const *tto, uint32_
}
else y[0] = 4 ;
- if (fd[1] >= 0 && state & BR_SSL_RECVAPP)
+ if (fd[1] >= 0)
{
x[j].fd = fd[1] ;
- x[j].events = IOPAUSE_WRITE ;
+ x[j].events = state & BR_SSL_RECVAPP ? IOPAUSE_WRITE : 0 ;
y[1] = j++ ;
}
else y[1] = 4 ;
@@ -80,16 +79,14 @@ void sbearssl_run (br_ssl_engine_context *ctx, int *fd, tain const *tto, uint32_
}
else y[2] = 4 ;
- if (fd[3] >= 0 && state & BR_SSL_SENDREC)
+ if (fd[3] >= 0)
{
x[j].fd = fd[3] ;
- x[j].events = IOPAUSE_WRITE ;
+ x[j].events = state & BR_SSL_SENDREC ? IOPAUSE_WRITE : 0 ;
y[3] = j++ ;
}
else y[3] = 4 ;
- if (!j) break ;
-
/* Wait for events */
switch (iopause_g(x, j, &deadline))