ucspi-ssl  0.99e
TLS encryption for IPv6 communication
ssl_timeoutconn.c
Go to the documentation of this file.
1 #include "ucspissl.h"
2 #include "iopause.h"
3 #include "error.h"
4 
5 int ssl_timeoutconn(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_connect_state(ssl);
25  for (;;) {
26  r = SSL_connect(ssl);
27  errno = error_proto;
28  if (r == 1) return 0;
29  ssl_errno = SSL_get_error(ssl,r);
30  if ((ssl_errno != SSL_ERROR_WANT_READ) && (ssl_errno != SSL_ERROR_WANT_WRITE))
31  return -1;
32  if (ssl_errno == SSL_ERROR_WANT_READ) {
33  x.events = IOPAUSE_READ;
34  x.fd = rfd;
35  if (x.fd == -1) return -1;
36  }
37  else {
38  x.events = IOPAUSE_WRITE;
39  x.fd = wfd;
40  if (x.fd == -1) return -1;
41  }
42  for (;;) {
43  if (taia_now(&now) == -1) {
44  errno = error_timeout;
45  return -1;
46  }
47  iopause(&x,1,&deadline,&now);
48  if (x.revents) break;
49  if (taia_less(&deadline,&now))
50  return -1;
51  }
52  }
53 }
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
Header file to be used with sqmail; previously called ssl.h. (name clash)
int ssl_timeoutconn(SSL *ssl, unsigned int timeout)
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