From 85a6816e7840e6b8cdff51b7c0cfad36082c01ec Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Wed, 7 Apr 2021 15:40:25 -0400 Subject: Results now posted back correctly using titan protocol --- captain/response.f90 | 24 ++++++++++++++++-------- common/protocol.f90 | 32 +++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/captain/response.f90 b/captain/response.f90 index 1c7a0b5..9cd2d9f 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -140,8 +140,6 @@ contains do while(i /= i_last .and. j < i_component) j = j + 1 - call write_log("RC: "//self%location(i:n)) - i_last = i i = index(self%location(i_last+1:n), "/") i = i_last + i @@ -151,7 +149,6 @@ contains if(j == i_component) then if(i == i_last) then res = self%location(i_last+1:n) - call write_log("Last! "//trim(res)) else res = self%location(i_last+1:i-1) end if @@ -389,8 +386,8 @@ contains self%location = regular_request%location(1:i-1) size_text => titan_get_request_value(regular_request%location, "size") - read(size_text, *, iostat=ierr) self%size - if(ierr <= 0) then + read(size_text, '(I16)', iostat=ierr) self%size + if(ierr /= 0) then self%size = 0 end if deallocate(size_text) @@ -420,6 +417,7 @@ contains subroutine titan_write_to_filename(self, filename) use jessl, only: ssl_read + use logging implicit none class(titan_request)::self @@ -432,16 +430,26 @@ contains integer(kind=8)::bytes_to_go integer::i - open(newunit=unum, file=filename, status="unknown", action="write", access="stream") + character(128)::msg + + open(newunit=unum, file=filename, status="unknown", action="write", access="stream", form="formatted") bytes_to_go = self%size - + call write_log("Writing!") + do while(bytes_to_go > 0) bufread = ssl_read(self%ssl_connection, buf) bytes_to_go = bytes_to_go - bufread + write(msg, *) "read: ", bufread + call write_log(trim(msg)) + + write(msg, *) "remaining: ", bytes_to_go + call write_log(trim(msg)) + + do i = 1, bufread - write(unum, '(A1)', advance='no') buf(i:i) + write(unum, '(A1)', advance='no') buf(i) end do end do diff --git a/common/protocol.f90 b/common/protocol.f90 index 38f2cf1..37e3205 100644 --- a/common/protocol.f90 +++ b/common/protocol.f90 @@ -230,6 +230,11 @@ contains logical, dimension(4)::successes integer::i, ierr, bytes_read, bytes_written, total_written + ! For direct processing of the reponse line + integer::response_line_index, bytes_received + character(1024)::response_line + logical::response_line_completed + returncode = -1 rewind(unit_number) @@ -278,7 +283,32 @@ contains end do if(total_written >= file_length) then - returncode = STATUS_SUCCESS + + response_line_completed = .false. + response_line = " " + response_line_index = 0 + + bytes_received = retrieve_characters(conn%ssl, buffer) + do while(bytes_received > 0) + + do i=1, bytes_received + response_line_index = response_line_index + 1 + response_line(response_line_index:response_line_index) = buffer(i) + + ! If we encountered our first newline, we have a complete status + ! line - handle it here + if(buffer(i) == char(10) .or. response_line_index == 1024) then + response_line_completed = .true. + + returncode = get_return_code(response_line) + + end if + + end do + + bytes_received = retrieve_characters(conn%ssl, buffer) + end do + else returncode = STATUS_LOCALFAIL end if -- cgit v1.2.3