diff options
-rw-r--r-- | captain/api.f90 | 14 | ||||
-rw-r--r-- | captain/external.f90 | 14 | ||||
-rw-r--r-- | captain/response.f90 | 20 |
3 files changed, 34 insertions, 14 deletions
diff --git a/captain/api.f90 b/captain/api.f90 index 7b99ec7..665ff8d 100644 --- a/captain/api.f90 +++ b/captain/api.f90 @@ -227,11 +227,17 @@ contains ! Write the file call write_log("Storing titan file to "//trim(fullpath), LOG_DEBUG) - call req%write_to(fullpath) + if(req%write_to(fullpath)) then - resp%code = GEMINI_CODE_SUCCESS - call resp%set_body_contents(RESPONSE_JSON_OKAY) - resp%body_mimetype = "text/plain" + resp%code = GEMINI_CODE_SUCCESS + call resp%set_body_contents(RESPONSE_JSON_OKAY) + resp%body_mimetype = "text/plain" + + else + + resp%code = GEMINI_CODE_TEMPFAIL + + end if else diff --git a/captain/external.f90 b/captain/external.f90 index f5ba409..61184f1 100644 --- a/captain/external.f90 +++ b/captain/external.f90 @@ -718,11 +718,17 @@ contains ! Write the file call write_log("Storing titan file to "//trim(fullpath), LOG_DEBUG) - call req%write_to(fullpath) + if(req%write_to(fullpath)) then - resp%code = GEMINI_CODE_SUCCESS - call resp%set_body_contents(RESPONSE_JSON_OKAY) - resp%body_mimetype = "text/plain" + resp%code = GEMINI_CODE_SUCCESS + call resp%set_body_contents(RESPONSE_JSON_OKAY) + resp%body_mimetype = "text/plain" + + else + + resp%code = GEMINI_CODE_TEMPFAIL + + end if else diff --git a/captain/response.f90 b/captain/response.f90 index b091a42..0506125 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -27,6 +27,7 @@ implicit none integer, parameter::GEMINI_CODE_INPUT = 10 integer, parameter::GEMINI_CODE_SUCCESS = 20 integer, parameter::GEMINI_CODE_REDIRECT = 30 + integer, parameter::GEMINI_CODE_TEMPFAIL = 40 integer, parameter::GEMINI_CODE_PERMFAIL = 50 character(*), parameter::RESPONSE_JSON_OKAY = '{"status": "okay"}' @@ -567,7 +568,7 @@ contains end subroutine titan_request_destroy - subroutine titan_write_to_filename(self, filename) + function titan_write_to_filename(self, filename) result(success) use jessl, only: ssl_read use logging implicit none @@ -580,16 +581,21 @@ contains integer::bufread integer(kind=8)::bytes_to_go, written - integer::i + integer::i, istat + + logical::success !character(128)::msg - open(newunit=unum, file=filename, status="unknown", action="write", access='stream') + success = .false. + + open(newunit=unum, file=filename, status="unknown", & + action="write", access='stream', iostat=istat) bytes_to_go = self%size written = 0 - do while(bytes_to_go > 0) + do while(bytes_to_go > 0 .and. istat == 0) bufread = ssl_read(self%ssl_connection, buf) bytes_to_go = bytes_to_go - bufread @@ -598,7 +604,7 @@ contains do i = 1, bufread !write(unum, '(A1)', advance='no') buf(i) - write(unum) buf(i) + write(unum, iostat=istat) buf(i) written = written + 1 end do end do @@ -607,6 +613,8 @@ contains !call write_log(trim(msg)) close(unum) - end subroutine titan_write_to_filename + success = (istat == 0) + + end function titan_write_to_filename end module server_response |