Detect errors and timeouts when reading data from server.

This commit is contained in:
Stephen Heumann 2018-08-15 21:05:09 -05:00
parent 64ad28a740
commit 8532c14ee1
4 changed files with 29 additions and 8 deletions

View File

@ -264,11 +264,16 @@ static Word DoMountURL(struct GSOSDP *dp) {
return drvrIOError;
}
ReadStatus readStatus;
InitReadTCP(sess, sizeof(sess->fileHeader.buf), &sess->fileHeader.buf);
while (TryReadTCP(sess) == rsWaiting)
// TODO timeout
while ((readStatus = TryReadTCP(sess)) == rsWaiting)
/* keep reading */ ;
//TODO detect errors
if (readStatus != rsDone) {
EndNetDiskSession(sess);
dp->transferCount = 0;
mountURLRec->result = NETWORK_ERROR;
return drvrIOError;
}
err = CheckTwoImg(sess);
if (err != OPERATION_SUCCESSFUL) {
@ -318,13 +323,17 @@ static Word DoRead(struct GSOSDP *dp) {
return drvrIOError;
}
ReadStatus readStatus;
InitReadTCP(sess, dp->requestCount, dp->bufferPtr);
while (TryReadTCP(sess) == rsWaiting)
// TODO timeout
while ((readStatus = TryReadTCP(sess)) == rsWaiting)
/* keep reading */ ;
//TODO detect errors
dp->transferCount = dp->requestCount - sess->readCount;
if (readStatus != rsDone) {
return drvrIOError;
}
return 0;
}

View File

@ -3,15 +3,20 @@
#include "readtcp.h"
#include "session.h"
#include <tcpip.h>
#include <misctool.h>
#include <orca.h>
#define buffTypePointer 0x0000 /* For TCPIPReadTCP() */
#define buffTypeHandle 0x0001
#define buffTypeNewHandle 0x0002
/* Time out if no new data is received for this long */
#define READ_TIMEOUT 15 /* seconds */
void InitReadTCP(Session *sess, LongWord readCount, void *readPtr) {
sess->readCount = readCount;
sess->readPtr = readPtr;
sess->lastReadTime = GetTick();
}
@ -23,7 +28,6 @@ ReadStatus TryReadTCP(Session *sess) {
sess->readCount, &rrBuff);
sess->toolerr = toolerror();
if (sess->tcperr || sess->toolerr) {
/*sess->dsiStatus = error;*/
return rsError;
}
@ -33,6 +37,12 @@ ReadStatus TryReadTCP(Session *sess) {
if (sess->readCount == 0) {
return rsDone;
} else {
if (rrBuff.rrBuffCount != 0) {
sess->lastReadTime = GetTick();
} else if (GetTick() - sess->lastReadTime > READ_TIMEOUT * 60) {
return rsTimedOut;
}
return rsWaiting;
}
}

View File

@ -6,7 +6,8 @@
typedef enum ReadStatus {
rsDone,
rsWaiting,
rsError
rsError,
rsTimedOut
} ReadStatus;
void InitReadTCP(Session *sess, LongWord readCount, void *readPtr);

View File

@ -12,6 +12,7 @@ typedef struct Session {
/* ReadTCP status */
LongWord readCount;
Byte *readPtr;
LongWord lastReadTime;
/* Marinetti error codes, both the tcperr* value and any tool error */
Word tcperr;