124 #include <sys/time.h>
128 #define timersub(a, b, res) do { \
129 (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
130 (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
131 if ((res)->tv_usec < 0) { \
133 (res)->tv_usec += 1000000; \
152 int tls_bio(
int fd,
int timeout, TLS_SESS_STATE *TLScontext,
153 int (*hsfunc) (SSL *),
154 int (*rfunc) (SSL *,
void *,
int),
155 int (*wfunc) (SSL *,
const void *,
int),
158 const char *myname =
"tls_bio";
162 struct timeval time_left;
163 struct timeval time_deadline;
164 struct timeval time_now;
186 if (enable_deadline) {
187 GETTIMEOFDAY(&time_deadline);
188 time_deadline.tv_sec += timeout;
198 status = hsfunc(TLScontext->con);
200 status = rfunc(TLScontext->con, buf, num);
202 status = wfunc(TLScontext->con, buf, num);
204 msg_panic(
"%s: nothing to do here", myname);
205 err = SSL_get_error(TLScontext->con, status);
237 case SSL_ERROR_WANT_WRITE:
238 case SSL_ERROR_WANT_READ:
239 if (enable_deadline) {
240 GETTIMEOFDAY(&time_now);
241 timersub(&time_deadline, &time_now, &time_left);
242 timeout = time_left.tv_sec + (time_left.tv_usec > 0);
248 if (err == SSL_ERROR_WANT_WRITE) {
264 msg_warn(
"%s: unexpected SSL_ERROR code %d", myname, err);
279 case SSL_ERROR_ZERO_RETURN:
283 case SSL_ERROR_SYSCALL:
NORETURN msg_panic(const char *fmt,...)
#define write_wait(fd, timeout)
#define read_wait(fd, timeout)
void msg_warn(const char *fmt,...)
#define VSTREAM_FLAG_DEADLINE
#define timersub(a, b, res)
#define vstream_fstat(vp, fl)