mirror of
https://github.com/sheumann/NetDisk.git
synced 2024-12-21 19:29:19 +00:00
Support retrying when reading from the TCP connection gives an error.
This is often what will happen if the server has terminated the connection (which many servers will do after a short time, e.g. one second).
This commit is contained in:
parent
a66b69154e
commit
9883d47517
39
http.c
39
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);
|
||||
|
||||
|
23
main.c
23
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user