ucspi-ssl  0.99e
TLS encryption for IPv6 communication
ssl_timeoutaccept.c
Go to the documentation of this file.
1 #include "ucspissl.h"
2 #include "iopause.h"
3 #include "error.h"
4 
5 int ssl_timeoutaccept(SSL *ssl,unsigned int timeout)
6 {
7  struct taia now;
8  struct taia deadline;
9  iopause_fd x;
10  int r;
11  int rfd;
12  int wfd;
13 
14  if (taia_now(&now) == 1) {
15  errno = error_timeout;
16  return -1;
17  }
18  taia_uint(&deadline,timeout);
19  taia_add(&deadline,&now,&deadline);
20 
21  rfd = SSL_get_fd(ssl); /* XXX */
22  wfd = SSL_get_fd(ssl); /* XXX */
23 
24  SSL_set_accept_state(ssl);
25 
26  for (;;) {
27  r = SSL_accept(ssl);
28  if (r == 1) return 0;
29  ssl_errno = SSL_get_error(ssl,r);
30  errno = error_proto;
31  if ((ssl_errno != SSL_ERROR_WANT_READ) && (ssl_errno != SSL_ERROR_WANT_WRITE))
32  return -1;
33  if (ssl_errno == SSL_ERROR_WANT_READ) {
34  x.events = IOPAUSE_READ;
35  x.fd = rfd;
36  if (x.fd == -1) return -1;
37  }
38  else {
39  x.events = IOPAUSE_WRITE;
40  x.fd = wfd;
41  if (x.fd == -1) return -1;
42  }
43  for (;;) {
44  if (taia_now(&now) == 1) {
45  errno = error_timeout;
46  return -1;
47  }
48  iopause(&x,1,&deadline,&now);
49  if (x.revents) break;
50  if (taia_less(&deadline,&now))
51  return -1;
52  }
53  }
54 }
Definition: taia.h:8
int iopause(iopause_fd *x, unsigned int len, struct taia *deadline, struct taia *stamp)
Definition: iopause.c:7
int error_proto
Definition: error.c:106
int ssl_timeoutaccept(SSL *ssl, unsigned int timeout)
Header file to be used with sqmail; previously called ssl.h. (name clash)
int taia_now(struct taia *)
Definition: taia_now.c:8
int taia_less(const struct taia *, const struct taia *)
Definition: taia_less.c:7
void taia_add(struct taia *, const struct taia *, const struct taia *)
Definition: taia_add.c:7
void taia_uint(struct taia *, unsigned int)
Definition: taia_uint.c:7
int error_timeout
Definition: error.c:50
int ssl_errno
Definition: ucspissl.c:3
unsigned long timeout
Definition: sslhandle.c:67