diff --git a/http.c b/http.c index a04cbb1..e0b71b0 100644 --- a/http.c +++ b/http.c @@ -104,22 +104,21 @@ top:; /* Send out request */ result = NETWORK_ERROR; unsigned int netErrors = 0; - do { - if (!sess->tcpLoggedIn || netErrors) { - if (StartTCPConnection(sess) != 0) - goto errorReturn; +netRetry: + if (!sess->tcpLoggedIn || netErrors) { + if (StartTCPConnection(sess) != 0) + goto errorReturn; + } + tcpError = TCPIPWriteTCP(sess->ipid, sess->httpRequest, + sess->httpRequestLen, TRUE, FALSE); + if (tcpError || toolerror()) { + if (netErrors == 0) { + netErrors++; + goto netRetry; + } else { + goto errorReturn; } - tcpError = TCPIPWriteTCP(sess->ipid, sess->httpRequest, - sess->httpRequestLen, TRUE, FALSE); - if (tcpError || toolerror()) { - if (netErrors == 0) { - netErrors++; - continue; - } else { - goto errorReturn; - } - } - } while (0); + } /* Get response status line & headers */ LongWord startTime = GetTick(); @@ -129,8 +128,14 @@ top:; (void*)((LongWord)"\p\r\n\r\n" | 0x80000000), buffTypeNewHandle, (Ref)NULL, 0xFFFFFF, &rlrBuff); - if (tcpError || toolerror()) - goto errorReturn; + if (tcpError || toolerror()) { + if (netErrors == 0) { + netErrors++; + goto netRetry; + } else { + goto errorReturn; + } + } } while (rlrBuff.rlrBuffCount == 0 && GetTick() - startTime < HTTP_RESPONSE_TIMEOUT * 60); diff --git a/main.c b/main.c index 7b1c876..55b3c05 100644 --- a/main.c +++ b/main.c @@ -11,6 +11,7 @@ #include "seturl.h" #include "hostname.h" #include "tcpconnection.h" +#include "readtcp.h" /* http://archive.org/download/a2gs_System_1.0_1986_Apple_FW/System_1.0_1986_Apple_FW.2mg @@ -20,6 +21,7 @@ http://ia800505.us.archive.org/16/items/a2gs_System_1.0_1986_Apple_FW/System_1.0 char *defaultURL = "http://archive.org/download/a2gs_System_1.0_1986_Apple_FW/System_1.0_1986_Apple_FW.2mg"; +char buf[512]; int main(int argc, char **argv) { TLStartUp(); @@ -71,6 +73,27 @@ int main(int argc, char **argv) { printf("totalLength = %lu\n", sess.totalLength); printf("contentLength = %lu\n", sess.contentLength); } + + InitReadTCP(&sess, sess.rangeEnd - sess.rangeStart + 1, buf); + while (TryReadTCP(&sess) == rsWaiting) + /* keep reading */ ; + + LongWord startTime = GetTick(); + while (GetTick() - startTime < 70) + /* wait */ ; + + printf("Request 2:\n"); + requestResult = DoHTTPRequest(&sess, startByte + 512, startByte + 1023); + printf("RequestResult %i\n", requestResult); + printf("Response code %lu\n", sess.responseCode); + + if (requestResult == REQUEST_SUCCESSFUL) { + printf("rangeStart = %lu\n", sess.rangeStart); + printf("rangeEnd = %lu\n", sess.rangeEnd); + printf("totalLength = %lu\n", sess.totalLength); + printf("contentLength = %lu\n", sess.contentLength); + } + EndTCPConnection(&sess);