Skip to content
Snippets Groups Projects
Commit 9ca97049 authored by rswindell's avatar rswindell
Browse files

Improved timeout calculation in recv_byte() - using millisecond clock instead

of time().
Changed default X/Ymodem byte receive timeout to 3 seconds (to account
for occasional Internet latency).
parent ce957838
No related branches found
No related tags found
No related merge requests found
......@@ -202,7 +202,7 @@ void send_telnet_cmd(SOCKET sock, uchar cmd, uchar opt)
/****************************************************************************/
/* Receive a byte from remote */
/****************************************************************************/
uint recv_byte(SOCKET sock, int timeout, long mode)
uint recv_byte(SOCKET sock, unsigned timeout, long mode)
{
int i;
long t;
......@@ -213,13 +213,13 @@ uint recv_byte(SOCKET sock, int timeout, long mode)
static uchar telnet_cmd;
static int telnet_cmdlen;
end=time(NULL)+timeout;
end=msclock()+(timeout*MSCLOCKS_PER_SEC);
while(1) {
FD_ZERO(&socket_set);
FD_SET(sock,&socket_set);
if((t=end-time(NULL))<0) t=0;
tv.tv_sec=t;
if((t=end-msclock())<0) t=0;
tv.tv_sec=t/MSCLOCKS_PER_SEC;
tv.tv_usec=0;
if(select(sock+1,&socket_set,NULL,NULL,&tv)<1) {
......@@ -288,7 +288,7 @@ uint recv_byte(SOCKET sock, int timeout, long mode)
/*************************/
/* Send a byte to remote */
/*************************/
int send_byte(SOCKET sock, uchar ch, int timeout, long mode)
int send_byte(SOCKET sock, uchar ch, unsigned timeout, long mode)
{
uchar buf[2] = { TELNET_IAC, TELNET_IAC };
int len=1;
......@@ -1129,6 +1129,9 @@ int main(int argc, char **argv)
}
#endif
xm.byte_timeout=3; /* seconds */
xm.ack_timeout=10; /* seconds */
for(i=1;i<argc;i++) {
if(sock==INVALID_SOCKET && isdigit(argv[i][0])) {
......
......@@ -78,7 +78,7 @@
#define NOINP 0x0100 /* input buffer empty (incom only) */
uint recv_byte(SOCKET sock, int timeout, long mode);
int send_byte(SOCKET sock, uchar ch, int timeout, long mode);
uint recv_byte(SOCKET sock, unsigned timeout, long mode);
int send_byte(SOCKET sock, uchar ch, unsigned timeout, long mode);
char* chr(uchar ch);
void bail(int code);
\ No newline at end of file
......@@ -45,7 +45,7 @@
void xmodem_put_nak(xmodem_t* xm)
{
while(getcom(1)!=NOINP)
while(getcom(0)!=NOINP)
; /* wait for any trailing data */
putcom(NAK);
}
......@@ -112,7 +112,7 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
xmodem_put_nak(xm);
continue;
}
i=getcom(1);
i=getcom(xm->byte_timeout);
if(i==NOINP) {
if(hdrblock) /* Trying to get Ymodem header block */
return(-1);
......@@ -120,7 +120,7 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
continue;
}
block_num=i;
i=getcom(1);
i=getcom(xm->byte_timeout);
if(i==NOINP) {
if(hdrblock) /* Trying to get Ymodem header block */
return(-1);
......@@ -137,7 +137,7 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
}
calc_crc=calc_chksum=0;
for(b=0;b<xm->block_size;b++) {
i=getcom(1);
i=getcom(xm->byte_timeout);
if(i==NOINP)
break;
block[b]=i;
......@@ -153,11 +153,11 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, BOOL hdrblock)
}
if((*xm->mode)&CRC) {
crc=getcom(1)<<8;
crc|=getcom(1);
crc=getcom(xm->byte_timeout)<<8;
crc|=getcom(xm->byte_timeout);
}
else
chksum=getcom(1);
chksum=getcom(xm->byte_timeout);
if((*xm->mode)&CRC) {
if(crc==calc_crc)
......@@ -243,7 +243,7 @@ int xmodem_get_ack(xmodem_t* xm, int tries)
return(1);
}
i=getcom(10);
i=getcom(xm->ack_timeout);
if(can && i!=CAN)
can=0;
if(i==ACK)
......
......@@ -44,11 +44,13 @@
typedef struct {
SOCKET sock; /* socket descriptor */
long* mode;
FILE* statfp;
FILE* errfp;
uint block_size;
SOCKET sock; /* socket descriptor */
long* mode;
FILE* statfp;
FILE* errfp;
unsigned block_size;
unsigned ack_timeout;
unsigned byte_timeout;
} xmodem_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment