mirror of
https://github.com/sheumann/NetDisk.git
synced 2024-11-23 22:37:02 +00:00
Detect errors and timeouts when reading data from server.
This commit is contained in:
parent
64ad28a740
commit
8532c14ee1
21
driver.c
21
driver.c
@ -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;
|
||||
}
|
||||
|
||||
|
12
readtcp.c
12
readtcp.c
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
typedef enum ReadStatus {
|
||||
rsDone,
|
||||
rsWaiting,
|
||||
rsError
|
||||
rsError,
|
||||
rsTimedOut
|
||||
} ReadStatus;
|
||||
|
||||
void InitReadTCP(Session *sess, LongWord readCount, void *readPtr);
|
||||
|
Loading…
Reference in New Issue
Block a user