From 462715e11037739722457e48084a73daa9e5d889 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Mon, 2 Jan 2023 11:50:39 -0500 Subject: Added a timeout to read functions such that failures don't occur immediately. Seems to be a culprit in the upload failures. --- common/jessl.f90 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'common/jessl.f90') diff --git a/common/jessl.f90 b/common/jessl.f90 index 5ad90fd..1974082 100644 --- a/common/jessl.f90 +++ b/common/jessl.f90 @@ -203,19 +203,39 @@ implicit none contains - function ssl_read(ssl, buf) + ! The timeout is specified in milliseconds, fyi + function ssl_read(ssl, buf, timeout) use iso_c_binding + use utilities, only: sleep_ms implicit none type(c_ptr)::ssl character(len=1), dimension(:), intent(out)::buf + integer, intent(in), optional::timeout integer::ssl_read integer::bufsize + integer(kind=8)::start_time, current_time, count_rate, dt + character(kind=c_char), dimension(:), allocatable::cbuf bufsize = size(buf) allocate(cbuf(bufsize)) + if(present(timeout)) then + + call system_clock(start_time, count_rate=count_rate) + current_time = start_time + + dt = 0 + + do while(ssl_pending(ssl) <= 0 .and. dt < timeout .and. dt >= 0) + call sleep_ms(timeout / 10) + call system_clock(current_time) + dt = ((current_time - start_time)*1000)/count_rate + end do + + end if + ssl_read = read_c(ssl, cbuf, bufsize) buf = cbuf -- cgit v1.2.3