diff --git a/ChangeLog b/ChangeLog index 7f8a2d48..18474609 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,8 @@ v0.39.1 22-Oct-2003 Added hydra rpos id -1 indicator for compression stop that Alex and I agreed to use. Compression log fixed and added percentage compression. + Added dynamic optimum sendbuffer size with a maximum of 8192 + bytes with an average size of 2048 bytes. mbsetup: In node editor, fixed error message when there was no more diff --git a/mbcico/hydra.c b/mbcico/hydra.c index 95bccf12..fe5c6135 100644 --- a/mbcico/hydra.c +++ b/mbcico/hydra.c @@ -343,7 +343,7 @@ enum HyPktTypes hyrxpkt(char *rxbuf, int *rxlen, int tot) } } - Syslog('h', "GETCHAR returned %i", c); + Syslog('h', "Hydra: GETCHAR returned %i", c); if ((c == TERROR) || (c == EOFILE) || (c == HANGUP)) { return H_CARRIER; @@ -362,7 +362,7 @@ void hytxpkt(enum HyPktTypes pkttype, char *txbuf, int txlen) enum HyPktFormats format; if (pkttype == HPKT_DATAACK) - Syslog('h', "ACK 0x%02x%02x%02x%02x", txbuf[0], txbuf[1], txbuf[2], txbuf[3]); + Syslog('h', "Hydra: ACK 0x%02x%02x%02x%02x", txbuf[0], txbuf[1], txbuf[2], txbuf[3]); /* * some packets have to be transferred in HEX mode @@ -530,13 +530,11 @@ int resync(off_t off) int hydra_batch(int role, file_list *to_send) { static char txbuf[H_ZIPBUFLEN], rxbuf[H_ZIPBUFLEN]; - static char txzbuf[H_ZIPBUFLEN], rxzbuf[H_ZIPBUFLEN]; struct stat txstat; /* file stat being transmitted */ FILE *txfp = NULL; /* file currently being transmitted */ FILE *rxfp = NULL; /* file currently being received */ char *inbuf, *outbuf; int rxlen, txlen; /* length of receive/transmit buffer */ - unsigned long rxzlen, txzlen; /* length of receive/transmit compressed buffer */ long txwindow, rxwindow; /* window sizes */ long txpos; off_t rxpos; /* file positions */ @@ -560,8 +558,13 @@ int hydra_batch(int role, file_list *to_send) struct timeval rxstarttime, rxendtime; struct timezone tz; int sverr; - int rcz, txcompressed, rxctries; - + int txcompressed, rxctries; +#ifdef HAVE_ZLIB_H + static char txzbuf[H_ZIPBUFLEN], rxzbuf[H_ZIPBUFLEN]; + unsigned long rxzlen, txzlen; /* length of receive/transmit compressed buffer */ + int rcz, cmpblksize; +#endif + Syslog('h', "Hydra: resettimers"); RESETTIMERS(); @@ -573,6 +576,7 @@ int hydra_batch(int role, file_list *to_send) rxlastsync = rxsyncid = 0; rxlastdatalen = 0; blksize = 512; + cmpblksize = H_UNCBLKLEN; goodbytes = 0; goodneeded = 1024; Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); @@ -624,8 +628,13 @@ int hydra_batch(int role, file_list *to_send) pkttype = hyrxpkt(rxbuf, &rxlen, -1); } - if ((pkttype == H_CARRIER) || (EXPIRED(TIMERNO_BRAIN))) { - Syslog('h', "Hydra: BRAIN timer expired"); + if (EXPIRED(TIMERNO_BRAIN)) { + Syslog('+', "Hydra: BRAIN timer expired"); + txstate = HTX_Abort; + break; + } + if (pkttype == H_CARRIER) { + Syslog('+', "Hydra: lost CARRIER"); txstate = HTX_Abort; break; } @@ -650,6 +659,12 @@ int hydra_batch(int role, file_list *to_send) if ((rpos_id == -1) && (compstate != HCMP_NONE)) { Syslog('+', "Hydra: remote asked stop compression"); compstate = HCMP_NONE; + /* + * Adjust blocksize for normal uncompressed transfers + */ + if (blksize > H_UNCBLKLEN) { + blksize = H_UNCBLKLEN; + } } #endif @@ -663,7 +678,7 @@ int hydra_batch(int role, file_list *to_send) txpos = -2; txstate = HTX_EOF; } else { - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); txstate = HTX_SkipFile; } @@ -695,7 +710,7 @@ int hydra_batch(int role, file_list *to_send) if (txstate == HTX_EOFACK) txstate = HTX_DATA; - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); } } @@ -934,7 +949,7 @@ int hydra_batch(int role, file_list *to_send) Syslog('h', "SM 'HTX' entering 'FINFOACK'"); if ((pkttype == HPKT_FINFOACK) && (rxlen == 4)) { txpos = get_long(rxbuf); - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); if (to_send == NULL) { @@ -996,7 +1011,7 @@ int hydra_batch(int role, file_list *to_send) Syslog('h', "Hydra: set TX timer %d", H_MINTIMER/2); SETTIMER(TIMERNO_TX, H_MINTIMER/2); } else { - Syslog('H', "HYDRA: SET TX TIMER %D", H_MINTIMER); + Syslog('h', "Hydra: set TX timer %d", H_MINTIMER); SETTIMER(TIMERNO_TX, H_MINTIMER); } txstate = HTX_DATAACK; @@ -1023,6 +1038,8 @@ int hydra_batch(int role, file_list *to_send) txstate = HTX_EOF; } } else { + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); // 03-11-2003 MB. + SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); // 03-11-2003 MB. #ifdef HAVE_ZLIB_H if (compstate == HCMP_GZ) { txzlen = H_ZIPBUFLEN - 4; @@ -1038,6 +1055,18 @@ int hydra_batch(int role, file_list *to_send) goodbytes += txlen; txzlen += 4; hytxpkt(HPKT_ZIPDATA, txzbuf, txzlen); + /* + * Calculate the perfect blocksize for the next block + * using the current compression ratio. This gives + * a dynamic optimal blocksize. The average maximum + * blocksize on the line will be 2048 bytes. + */ + cmpblksize = ((txlen * 4) / txzlen) * 512; + if (cmpblksize < H_UNCBLKLEN) + cmpblksize = H_UNCBLKLEN; + if (cmpblksize > H_MAXBLKLEN) + cmpblksize = H_MAXBLKLEN; + Syslog('h', "Hydra: adjusting next blocksize to %d bytes", cmpblksize); } else { txpos += txlen; sentbytes += txlen; @@ -1066,20 +1095,31 @@ int hydra_batch(int role, file_list *to_send) txlen += 4; hytxpkt(HPKT_DATA, txbuf, txlen); } + if (goodbytes > goodneeded) { + blksize *= 2; + if (compstate != HCMP_NONE) { + if (blksize > cmpblksize) { + blksize = cmpblksize; + } + } else { + if (blksize > H_UNCBLKLEN) { + blksize = H_UNCBLKLEN; + } + } + } #else txpos += txlen; sentbytes += txlen; goodbytes += txlen; txlen += 4; hytxpkt(HPKT_DATA, txbuf, txlen); -#endif -// FIXME: here to decide in PLZ mode to use larger blocks. if (goodbytes > goodneeded) { blksize *= 2; if (blksize > H_UNCBLKLEN) { blksize = H_UNCBLKLEN; } } +#endif } } break; @@ -1180,7 +1220,7 @@ int hydra_batch(int role, file_list *to_send) case HTX_EOFACK: Syslog('h', "SM 'HTX' entering 'EOFACK'"); if ((pkttype == HPKT_EOFACK) && (rxlen == 0)) { - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); /* @@ -1352,7 +1392,7 @@ int hydra_batch(int role, file_list *to_send) put_long(txbuf, 0); hytxpkt(HPKT_FINFOACK, txbuf, 4); - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); rxstate = HRX_DONE; } @@ -1417,7 +1457,7 @@ int hydra_batch(int role, file_list *to_send) } hytxpkt(HPKT_FINFOACK, txbuf, 4); - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); } } @@ -1510,7 +1550,7 @@ int hydra_batch(int role, file_list *to_send) } } else { if (rxpos >= 0) { - Syslog('+', "Hydra: received bad rxpos"); + Syslog('+', "Hydra: received bad rxpos %d", rxpos); } rxstate = HRX_BadPos; } @@ -1574,7 +1614,7 @@ int hydra_batch(int role, file_list *to_send) pkttype = H_NOPKT; /* packet has already been processed */ } else if ((pkttype == HPKT_IDLE) && (rxlen == 0) && (hdxlink == FALSE)) { - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); pkttype = H_NOPKT; /* packet has already been processed */ @@ -1675,7 +1715,7 @@ int hydra_batch(int role, file_list *to_send) pkttype = H_NOPKT; /* packet has already been processed */ } else if ((pkttype == HPKT_IDLE) && (rxlen == 0)) { - Syslog('h', "Hydra: set BRAIN timer", H_BRAINDEAD); + Syslog('h', "Hydra: set BRAIN timer %d", H_BRAINDEAD); SETTIMER(TIMERNO_BRAIN, H_BRAINDEAD); pkttype = H_NOPKT; /* packet has already been processed */ diff --git a/mbcico/ttyio.c b/mbcico/ttyio.c index 5ada839e..5d25d7b7 100644 --- a/mbcico/ttyio.c +++ b/mbcico/ttyio.c @@ -64,6 +64,17 @@ char *ttystat[]= {(char *)"Ok", (char *)"Hangup", (char *)"Empty"}; +int tty_resettimer(int tno); +void tty_resettimers(void); +int tty_settimer(int,int); +int tty_expired(int); +int tty_running(int); + +#define RESETTIMER(x) tty_resettimer(x) +#define RESETTIMERS() tty_resettimers() +#define SETTIMER(x,y) tty_settimer(x,y) +#define EXPIRED(x) tty_expired(x) +#define RUNNING(x) tty_running(x) @@ -153,7 +164,6 @@ int tty_running(int tno) /* * private r/w functions */ - static int tty_read(char *buf, int size, int tot) { time_t timeout, now; @@ -168,7 +178,7 @@ static int tty_read(char *buf, int size, int tot) now = time(NULL); timeout = (time_t)300; /* maximum of 5 minutes */ - for (i = 0; i < TIMERNO_TX; i++) { + for (i = 0; i < 2; i++) { if (timer[i]) { if (now >= timer[i]) { tty_status=STAT_TIMEOUT; diff --git a/mbcico/ttyio.h b/mbcico/ttyio.h index 1178c203..1494f9f4 100644 --- a/mbcico/ttyio.h +++ b/mbcico/ttyio.h @@ -3,12 +3,9 @@ #ifndef TTYIO_H #define TTYIO_H -/* - * Timer numbers for Hydra - */ -#define TIMERNO_BRAIN 0 -#define TIMERNO_RX 1 -#define TIMERNO_TX 2 +#define TIMERNO_BRAIN 0 /* BRAIN timerno */ +#define TIMERNO_RX 1 /* Receiver timerno */ +#define TIMERNO_TX 2 /* Transmitter timerno */ #define RESETTIMER(x) tty_resettimer(x) #define RESETTIMERS() tty_resettimers() @@ -164,6 +161,11 @@ extern int tty_status; +extern int tty_resettimer(int tno); +extern void tty_resettimers(void); +extern int tty_settimer(int,int); +extern int tty_expired(int); +extern int tty_running(int); extern int tty_check(void); extern int tty_waitputget(int); extern int tty_ungetc(int); @@ -176,10 +178,5 @@ extern int tty_putget(char**,int*,char**,int*); extern void tty_flushout(void); extern void tty_flushin(void); extern void sendbrk(void); -extern int tty_resettimer(int tno); -extern void tty_resettimers(void); -extern int tty_settimer(int,int); -extern int tty_expired(int); -extern int tty_running(int); #endif