2018-07-30 04:40:03 +00:00
|
|
|
#pragma noroot
|
|
|
|
|
|
|
|
#include "readtcp.h"
|
|
|
|
#include "session.h"
|
2019-04-19 22:34:18 +00:00
|
|
|
#include <string.h>
|
2018-07-30 04:40:03 +00:00
|
|
|
#include <tcpip.h>
|
2019-04-19 22:34:18 +00:00
|
|
|
#include <memory.h>
|
2018-08-16 02:05:09 +00:00
|
|
|
#include <misctool.h>
|
2018-07-30 04:40:03 +00:00
|
|
|
#include <orca.h>
|
|
|
|
|
|
|
|
#define buffTypePointer 0x0000 /* For TCPIPReadTCP() */
|
|
|
|
#define buffTypeHandle 0x0001
|
|
|
|
#define buffTypeNewHandle 0x0002
|
|
|
|
|
2018-08-16 02:05:09 +00:00
|
|
|
/* Time out if no new data is received for this long */
|
|
|
|
#define READ_TIMEOUT 15 /* seconds */
|
|
|
|
|
2018-07-30 04:40:03 +00:00
|
|
|
void InitReadTCP(Session *sess, LongWord readCount, void *readPtr) {
|
|
|
|
sess->readCount = readCount;
|
|
|
|
sess->readPtr = readPtr;
|
2018-08-16 02:05:09 +00:00
|
|
|
sess->lastReadTime = GetTick();
|
2018-07-30 04:40:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ReadStatus TryReadTCP(Session *sess) {
|
|
|
|
rrBuff rrBuff;
|
|
|
|
|
|
|
|
TCPIPPoll();
|
2019-04-19 22:34:18 +00:00
|
|
|
sess->tcperr = TCPIPReadTCP(sess->ipid, buffTypeNewHandle, NULL,
|
2018-07-30 04:40:03 +00:00
|
|
|
sess->readCount, &rrBuff);
|
|
|
|
sess->toolerr = toolerror();
|
|
|
|
if (sess->tcperr || sess->toolerr) {
|
|
|
|
return rsError;
|
|
|
|
}
|
|
|
|
|
2019-04-19 22:34:18 +00:00
|
|
|
if (rrBuff.rrBuffCount != 0) {
|
|
|
|
/* Work around Marinetti bug #57 */
|
|
|
|
rrBuff.rrBuffCount = GetHandleSize(rrBuff.rrBuffHandle);
|
|
|
|
|
|
|
|
HLock(rrBuff.rrBuffHandle);
|
|
|
|
memcpy(sess->readPtr, *rrBuff.rrBuffHandle, rrBuff.rrBuffCount);
|
|
|
|
DisposeHandle(rrBuff.rrBuffHandle);
|
|
|
|
|
|
|
|
sess->readCount -= rrBuff.rrBuffCount;
|
|
|
|
sess->readPtr += rrBuff.rrBuffCount;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:40:03 +00:00
|
|
|
|
|
|
|
if (sess->readCount == 0) {
|
|
|
|
return rsDone;
|
|
|
|
} else {
|
2018-08-16 02:05:09 +00:00
|
|
|
if (rrBuff.rrBuffCount != 0) {
|
|
|
|
sess->lastReadTime = GetTick();
|
|
|
|
} else if (GetTick() - sess->lastReadTime > READ_TIMEOUT * 60) {
|
|
|
|
return rsTimedOut;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:40:03 +00:00
|
|
|
return rsWaiting;
|
|
|
|
}
|
|
|
|
}
|