version 1.1, 2014/08/26 17:47:24 |
version 1.2, 2014/12/02 19:39:16 |
|
|
*/ |
*/ |
#ifndef OPENSSL_NO_OCSP |
#ifndef OPENSSL_NO_OCSP |
|
|
#include <sys/select.h> |
#include <sys/types.h> |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <limits.h> |
#include <limits.h> |
#include <string.h> |
#include <string.h> |
|
#include <poll.h> |
#include <time.h> |
#include <time.h> |
|
|
/* Needs to be included before the openssl headers! */ |
/* Needs to be included before the openssl headers! */ |
|
|
int i; |
int i; |
OCSP_REQ_CTX *ctx = NULL; |
OCSP_REQ_CTX *ctx = NULL; |
OCSP_RESPONSE *rsp = NULL; |
OCSP_RESPONSE *rsp = NULL; |
fd_set confds; |
struct pollfd pfd[1]; |
struct timeval tv; |
|
|
|
if (req_timeout != -1) |
if (req_timeout != -1) |
BIO_set_nbio(cbio, 1); |
BIO_set_nbio(cbio, 1); |
|
|
goto err; |
goto err; |
} |
} |
if (req_timeout != -1 && rv <= 0) { |
if (req_timeout != -1 && rv <= 0) { |
FD_ZERO(&confds); |
pfd[0].fd = fd; |
FD_SET(fd, &confds); |
pfd[0].events = POLLOUT; |
tv.tv_usec = 0; |
rv = poll(pfd, 1, req_timeout * 1000); |
tv.tv_sec = req_timeout; |
|
rv = select(fd + 1, NULL, &confds, NULL, &tv); |
|
if (rv == 0) { |
if (rv == 0) { |
BIO_puts(err, "Timeout on connect\n"); |
BIO_puts(err, "Timeout on connect\n"); |
return NULL; |
return NULL; |
} |
} |
|
if (rv == -1) { |
|
BIO_puts(err, "Poll error\n"); |
|
return NULL; |
|
} |
} |
} |
ctx = OCSP_sendreq_new(cbio, path, NULL, -1); |
ctx = OCSP_sendreq_new(cbio, path, NULL, -1); |
if (!ctx) |
if (!ctx) |
|
|
break; |
break; |
if (req_timeout == -1) |
if (req_timeout == -1) |
continue; |
continue; |
FD_ZERO(&confds); |
pfd[0].fd = fd; |
FD_SET(fd, &confds); |
|
tv.tv_usec = 0; |
|
tv.tv_sec = req_timeout; |
|
if (BIO_should_read(cbio)) |
if (BIO_should_read(cbio)) |
rv = select(fd + 1, &confds, NULL, NULL, &tv); |
pfd[0].events = POLLIN; |
else if (BIO_should_write(cbio)) |
else if (BIO_should_write(cbio)) |
rv = select(fd + 1, NULL, &confds, NULL, &tv); |
pfd[0].events = POLLOUT; |
else { |
else { |
BIO_puts(err, "Unexpected retry condition\n"); |
BIO_puts(err, "Unexpected retry condition\n"); |
goto err; |
goto err; |
} |
} |
|
rv = poll(pfd, 1, req_timeout * 1000); |
if (rv == 0) { |
if (rv == 0) { |
BIO_puts(err, "Timeout on request\n"); |
BIO_puts(err, "Timeout on request\n"); |
break; |
break; |
} |
} |
if (rv == -1) { |
if (rv == -1 || (pfd[0].revents & (POLLERR|POLLNVAL))) { |
BIO_puts(err, "Select error\n"); |
BIO_puts(err, "Poll error\n"); |
break; |
break; |
} |
} |
} |
} |