mirror of
https://github.com/sheumann/NetDisk.git
synced 2024-11-27 19:49:38 +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;
|
return drvrIOError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReadStatus readStatus;
|
||||||
InitReadTCP(sess, sizeof(sess->fileHeader.buf), &sess->fileHeader.buf);
|
InitReadTCP(sess, sizeof(sess->fileHeader.buf), &sess->fileHeader.buf);
|
||||||
while (TryReadTCP(sess) == rsWaiting)
|
while ((readStatus = TryReadTCP(sess)) == rsWaiting)
|
||||||
// TODO timeout
|
|
||||||
/* keep reading */ ;
|
/* keep reading */ ;
|
||||||
//TODO detect errors
|
if (readStatus != rsDone) {
|
||||||
|
EndNetDiskSession(sess);
|
||||||
|
dp->transferCount = 0;
|
||||||
|
mountURLRec->result = NETWORK_ERROR;
|
||||||
|
return drvrIOError;
|
||||||
|
}
|
||||||
|
|
||||||
err = CheckTwoImg(sess);
|
err = CheckTwoImg(sess);
|
||||||
if (err != OPERATION_SUCCESSFUL) {
|
if (err != OPERATION_SUCCESSFUL) {
|
||||||
@ -318,13 +323,17 @@ static Word DoRead(struct GSOSDP *dp) {
|
|||||||
return drvrIOError;
|
return drvrIOError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReadStatus readStatus;
|
||||||
InitReadTCP(sess, dp->requestCount, dp->bufferPtr);
|
InitReadTCP(sess, dp->requestCount, dp->bufferPtr);
|
||||||
while (TryReadTCP(sess) == rsWaiting)
|
while ((readStatus = TryReadTCP(sess)) == rsWaiting)
|
||||||
// TODO timeout
|
|
||||||
/* keep reading */ ;
|
/* keep reading */ ;
|
||||||
//TODO detect errors
|
|
||||||
|
|
||||||
dp->transferCount = dp->requestCount - sess->readCount;
|
dp->transferCount = dp->requestCount - sess->readCount;
|
||||||
|
|
||||||
|
if (readStatus != rsDone) {
|
||||||
|
return drvrIOError;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
readtcp.c
12
readtcp.c
@ -3,15 +3,20 @@
|
|||||||
#include "readtcp.h"
|
#include "readtcp.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include <tcpip.h>
|
#include <tcpip.h>
|
||||||
|
#include <misctool.h>
|
||||||
#include <orca.h>
|
#include <orca.h>
|
||||||
|
|
||||||
#define buffTypePointer 0x0000 /* For TCPIPReadTCP() */
|
#define buffTypePointer 0x0000 /* For TCPIPReadTCP() */
|
||||||
#define buffTypeHandle 0x0001
|
#define buffTypeHandle 0x0001
|
||||||
#define buffTypeNewHandle 0x0002
|
#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) {
|
void InitReadTCP(Session *sess, LongWord readCount, void *readPtr) {
|
||||||
sess->readCount = readCount;
|
sess->readCount = readCount;
|
||||||
sess->readPtr = readPtr;
|
sess->readPtr = readPtr;
|
||||||
|
sess->lastReadTime = GetTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -23,7 +28,6 @@ ReadStatus TryReadTCP(Session *sess) {
|
|||||||
sess->readCount, &rrBuff);
|
sess->readCount, &rrBuff);
|
||||||
sess->toolerr = toolerror();
|
sess->toolerr = toolerror();
|
||||||
if (sess->tcperr || sess->toolerr) {
|
if (sess->tcperr || sess->toolerr) {
|
||||||
/*sess->dsiStatus = error;*/
|
|
||||||
return rsError;
|
return rsError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +37,12 @@ ReadStatus TryReadTCP(Session *sess) {
|
|||||||
if (sess->readCount == 0) {
|
if (sess->readCount == 0) {
|
||||||
return rsDone;
|
return rsDone;
|
||||||
} else {
|
} else {
|
||||||
|
if (rrBuff.rrBuffCount != 0) {
|
||||||
|
sess->lastReadTime = GetTick();
|
||||||
|
} else if (GetTick() - sess->lastReadTime > READ_TIMEOUT * 60) {
|
||||||
|
return rsTimedOut;
|
||||||
|
}
|
||||||
|
|
||||||
return rsWaiting;
|
return rsWaiting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
typedef enum ReadStatus {
|
typedef enum ReadStatus {
|
||||||
rsDone,
|
rsDone,
|
||||||
rsWaiting,
|
rsWaiting,
|
||||||
rsError
|
rsError,
|
||||||
|
rsTimedOut
|
||||||
} ReadStatus;
|
} ReadStatus;
|
||||||
|
|
||||||
void InitReadTCP(Session *sess, LongWord readCount, void *readPtr);
|
void InitReadTCP(Session *sess, LongWord readCount, void *readPtr);
|
||||||
|
@ -12,6 +12,7 @@ typedef struct Session {
|
|||||||
/* ReadTCP status */
|
/* ReadTCP status */
|
||||||
LongWord readCount;
|
LongWord readCount;
|
||||||
Byte *readPtr;
|
Byte *readPtr;
|
||||||
|
LongWord lastReadTime;
|
||||||
|
|
||||||
/* Marinetti error codes, both the tcperr* value and any tool error */
|
/* Marinetti error codes, both the tcperr* value and any tool error */
|
||||||
Word tcperr;
|
Word tcperr;
|
||||||
|
Loading…
Reference in New Issue
Block a user