?? zsend.c
字號:
if (maxblklen>WAZOOMAX) maxblklen = WAZOOMAX;
if (!wazoo && maxblklen>KSIZE) maxblklen = KSIZE;
if (Rxbuflen && maxblklen>Rxbuflen) maxblklen = Rxbuflen;
blklen = maxblklen;
SomeMore:
if (CHAR_AVAIL())
begin
WaitAck:
switch (c = ZS_SyncWithReceiver())
begin
default: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
z_log(Cancelled_msg);
errno = 0;
fclose(Infile);
had_error(CLOSE_msg,Filename);
return ERROR;
case ZSKIP: /*-----------------------------------------*/
/* Skip this file */
/*-----------------------------------------*/
return c;
case ZACK: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
break;
case ZRPOS: /*-----------------------------------------*/
/* Resume at this position */
/*-----------------------------------------*/
blklen = (blklen>>2 > 64) ? blklen>>2 : 64;
goodblks = 0;
goodneeded = (goodneeded<<1) | 1;
break;
case ZRINIT: /*-----------------------------------------*/
/* Receive init */
/*-----------------------------------------*/
throughput(1,Txpos-Strtpos);
return OK;
end /* switch */
while (CHAR_AVAIL())
begin
switch (MODEM_IN())
begin
case CAN:
case RCDO:
case ZPAD: goto WaitAck;
end /* switch */
end /* while */
end /* while */
newcnt = Rxbuflen;
Z_PutLongIntoHeader(Txpos);
ZS_SendBinaryHeader(ZDATA, Txhdr);
do
begin
if (((KEYPRESS()) and (READKB()==27)))
begin
send_can();
z_log( KBD_msg );
goto oops;
end
if (!CARRIER) goto oops;
if ((c=fread(Txbuf,1,blklen,Infile))!=z_size)
begin
gotoxy( locate_x+10, locate_y );
cputs( ultoa(((unsigned long )(z_size=c)),e_input,10) );
putch(' ');
end
if (c < blklen) e = ZCRCE;
else if (Rxbuflen && (newcnt -= c) <= 0) e = ZCRCW;
else e = ZCRCG;
ZS_SendData(Txbuf, c, e);
gotoxy( locate_x, locate_y );
cputs( ultoa(((unsigned long )Txpos),e_input,10) );
putch(' ');
Txpos += c;
if (blklen<maxblklen && ++goodblks>goodneeded)
begin
blklen = (blklen<<1 < maxblklen) ? blklen<<1 : maxblklen;
goodblks = 0;
end
if (e == ZCRCW) goto WaitAck;
while (CHAR_AVAIL())
begin
switch (MODEM_IN())
begin
case CAN:
case RCDO:
case ZPAD: /*--------------------------------------*/
/* Interruption detected; */
/* stop sending and process complaint */
/*--------------------------------------*/
z_message("Trouble?");
CLEAR_OUTBOUND();
ZS_SendData(Txbuf, 0, ZCRCE);
goto WaitAck;
end /* switch */
end /* while */
end /* do */
while (e == ZCRCG);
while(1)
begin
Z_PutLongIntoHeader(Txpos);
ZS_SendBinaryHeader(ZEOF, Txhdr);
switch (ZS_SyncWithReceiver())
begin
case ZACK: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
continue;
case ZRPOS: /*-----------------------------------------*/
/* Resume at this position... */
/*-----------------------------------------*/
goto SomeMore;
case ZRINIT: /*-----------------------------------------*/
/* Receive init */
/*-----------------------------------------*/
throughput(1,Txpos-Strtpos);
return OK;
case ZSKIP: /*-----------------------------------------*/
/* Request to skip the current file */
/*-----------------------------------------*/
z_log(Skip_msg);
CLEAR_IOERR();
fclose(Infile);
had_error(CLOSE_msg,Filename);
return c;
default: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
oops: z_log(Cancelled_msg);
errno = 0;
fclose(Infile);
had_error(CLOSE_msg,Filename);
return ERROR;
end /* switch */
end /* while */
end /* ZS_SendFileData */
/*--------------------------------------------------------------------------*/
/* ZS SYNC WITH RECEIVER */
/* Respond to receiver's complaint, get back in sync with receiver */
/*--------------------------------------------------------------------------*/
static int pascal ZS_SyncWithReceiver()
begin
register int c;
int num_errs = 7;
while(1)
begin
c = Z_GetHeader(Rxhdr);
CLEAR_INBOUND();
switch (c)
begin
case TIMEOUT: z_message( TIME_msg );
if ((num_errs--) >= 0) break;
case ZCAN:
case ZABORT:
case ZFIN:
case RCDO:
/*-----------------------------------------*/
/* */
/*-----------------------------------------*/
z_log("Err");
return ERROR;
case ZRPOS: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
rewind(Infile); /* In case file EOF seen */
fseek(Infile, Rxpos, SEEK_SET);
Txpos = Rxpos;
z_message(NULL);
cputs("Resending from ");
cputs( ultoa(((unsigned long )(Txpos)),e_input,10) );
return c;
case ZSKIP: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
z_log(Skip_msg);
case ZRINIT: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
CLEAR_IOERR();
fclose(Infile);
had_error(CLOSE_msg,Filename);
return c;
case ZACK: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
z_message( NULL );
return c;
default: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
z_message( IDUNNO_msg );
ZS_SendBinaryHeader(ZNAK, Txhdr);
continue;
end /* switch */
end /* while */
end /* ZS_SyncWithReceiver */
/*--------------------------------------------------------------------------*/
/* ZS END SEND */
/* Say BIBI to the receiver, try to do it cleanly */
/*--------------------------------------------------------------------------*/
static void pascal ZS_EndSend()
begin
while(1)
begin
Z_PutLongIntoHeader(0L);
ZS_SendBinaryHeader(ZFIN, Txhdr);
switch (Z_GetHeader(Rxhdr))
begin
case ZFIN: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
SENDBYTE('O');
SENDBYTE('O');
wait_for_clear();
/* fallthrough... */
case ZCAN:
case RCDO:
case TIMEOUT: /*-----------------------------------------*/
/* */
/*-----------------------------------------*/
return;
end /* switch */
end /* while */
end /* ZS_EndSend */
/* END OF FILE: z_send.c */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -