diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_dgram.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_dgram.c | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bio/bss_dgram.c b/src/lib/libcrypto/bio/bss_dgram.c index ea2c3fff63..c3da6dc82f 100644 --- a/src/lib/libcrypto/bio/bss_dgram.c +++ b/src/lib/libcrypto/bio/bss_dgram.c | |||
@@ -82,7 +82,7 @@ static int dgram_new(BIO *h); | |||
82 | static int dgram_free(BIO *data); | 82 | static int dgram_free(BIO *data); |
83 | static int dgram_clear(BIO *bio); | 83 | static int dgram_clear(BIO *bio); |
84 | 84 | ||
85 | int BIO_dgram_should_retry(int s); | 85 | static int BIO_dgram_should_retry(int s); |
86 | 86 | ||
87 | static BIO_METHOD methods_dgramp= | 87 | static BIO_METHOD methods_dgramp= |
88 | { | 88 | { |
@@ -345,30 +345,90 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
345 | 345 | ||
346 | memcpy(&(data->peer), to, sizeof(struct sockaddr)); | 346 | memcpy(&(data->peer), to, sizeof(struct sockaddr)); |
347 | break; | 347 | break; |
348 | #if defined(SO_RCVTIMEO) | ||
348 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: | 349 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: |
350 | #ifdef OPENSSL_SYS_WINDOWS | ||
351 | { | ||
352 | struct timeval *tv = (struct timeval *)ptr; | ||
353 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; | ||
354 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
355 | (void*)&timeout, sizeof(timeout)) < 0) | ||
356 | { perror("setsockopt"); ret = -1; } | ||
357 | } | ||
358 | #else | ||
349 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr, | 359 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr, |
350 | sizeof(struct timeval)) < 0) | 360 | sizeof(struct timeval)) < 0) |
351 | { perror("setsockopt"); ret = -1; } | 361 | { perror("setsockopt"); ret = -1; } |
362 | #endif | ||
352 | break; | 363 | break; |
353 | case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT: | 364 | case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT: |
365 | #ifdef OPENSSL_SYS_WINDOWS | ||
366 | { | ||
367 | int timeout, sz = sizeof(timeout); | ||
368 | struct timeval *tv = (struct timeval *)ptr; | ||
369 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
370 | (void*)&timeout, &sz) < 0) | ||
371 | { perror("getsockopt"); ret = -1; } | ||
372 | else | ||
373 | { | ||
374 | tv->tv_sec = timeout / 1000; | ||
375 | tv->tv_usec = (timeout % 1000) * 1000; | ||
376 | ret = sizeof(*tv); | ||
377 | } | ||
378 | } | ||
379 | #else | ||
354 | if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 380 | if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
355 | ptr, (void *)&ret) < 0) | 381 | ptr, (void *)&ret) < 0) |
356 | { perror("getsockopt"); ret = -1; } | 382 | { perror("getsockopt"); ret = -1; } |
383 | #endif | ||
357 | break; | 384 | break; |
385 | #endif | ||
386 | #if defined(SO_SNDTIMEO) | ||
358 | case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT: | 387 | case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT: |
388 | #ifdef OPENSSL_SYS_WINDOWS | ||
389 | { | ||
390 | struct timeval *tv = (struct timeval *)ptr; | ||
391 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; | ||
392 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | ||
393 | (void*)&timeout, sizeof(timeout)) < 0) | ||
394 | { perror("setsockopt"); ret = -1; } | ||
395 | } | ||
396 | #else | ||
359 | if ( setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr, | 397 | if ( setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr, |
360 | sizeof(struct timeval)) < 0) | 398 | sizeof(struct timeval)) < 0) |
361 | { perror("setsockopt"); ret = -1; } | 399 | { perror("setsockopt"); ret = -1; } |
400 | #endif | ||
362 | break; | 401 | break; |
363 | case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT: | 402 | case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT: |
403 | #ifdef OPENSSL_SYS_WINDOWS | ||
404 | { | ||
405 | int timeout, sz = sizeof(timeout); | ||
406 | struct timeval *tv = (struct timeval *)ptr; | ||
407 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | ||
408 | (void*)&timeout, &sz) < 0) | ||
409 | { perror("getsockopt"); ret = -1; } | ||
410 | else | ||
411 | { | ||
412 | tv->tv_sec = timeout / 1000; | ||
413 | tv->tv_usec = (timeout % 1000) * 1000; | ||
414 | ret = sizeof(*tv); | ||
415 | } | ||
416 | } | ||
417 | #else | ||
364 | if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | 418 | if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, |
365 | ptr, (void *)&ret) < 0) | 419 | ptr, (void *)&ret) < 0) |
366 | { perror("getsockopt"); ret = -1; } | 420 | { perror("getsockopt"); ret = -1; } |
421 | #endif | ||
367 | break; | 422 | break; |
423 | #endif | ||
368 | case BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP: | 424 | case BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP: |
369 | /* fall-through */ | 425 | /* fall-through */ |
370 | case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP: | 426 | case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP: |
427 | #ifdef OPENSSL_SYS_WINDOWS | ||
428 | if ( data->_errno == WSAETIMEDOUT) | ||
429 | #else | ||
371 | if ( data->_errno == EAGAIN) | 430 | if ( data->_errno == EAGAIN) |
431 | #endif | ||
372 | { | 432 | { |
373 | ret = 1; | 433 | ret = 1; |
374 | data->_errno = 0; | 434 | data->_errno = 0; |
@@ -403,7 +463,7 @@ static int dgram_puts(BIO *bp, const char *str) | |||
403 | return(ret); | 463 | return(ret); |
404 | } | 464 | } |
405 | 465 | ||
406 | int BIO_dgram_should_retry(int i) | 466 | static int BIO_dgram_should_retry(int i) |
407 | { | 467 | { |
408 | int err; | 468 | int err; |
409 | 469 | ||