system: zmodem: Improve zmodem send performance
Introduce new configuration of CONFIG_SYSTEM_ZMODEM_SNDFILEBUF, which allocates cache buffer for reading file to be sent. This option can improve the performance of zmodem sending file by multiple bytes read of file, especially when the single read of file is very slow.
This commit is contained in:
parent
221a45879d
commit
01e2b11785
@ -62,6 +62,15 @@ config SYSTEM_ZMODEM_SNDBUFSIZE
|
||||
The size of one transmit buffer used for composing messages sent to
|
||||
the remote peer.
|
||||
|
||||
config SYSTEM_ZMODEM_SNDFILEBUF
|
||||
bool "Use cache buffer for file send"
|
||||
default n
|
||||
---help---
|
||||
Read multiple bytes of file at once and store into a temporal buffer
|
||||
which size is the same as SYSTEM_ZMODEM_SNDBUFSIZE. This is option
|
||||
to improve the performance of file send, especially when the single
|
||||
read of file is very slow.
|
||||
|
||||
config SYSTEM_ZMODEM_MOUNTPOINT
|
||||
string "Zmodem sandbox"
|
||||
default "/tmp"
|
||||
|
@ -358,6 +358,9 @@ struct zm_state_s
|
||||
uint8_t rcvbuf[CONFIG_SYSTEM_ZMODEM_RCVBUFSIZE];
|
||||
uint8_t pktbuf[ZM_PKTBUFSIZE];
|
||||
uint8_t scratch[CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE];
|
||||
#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF
|
||||
uint8_t filebuf[CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE];
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Receive state information */
|
||||
|
@ -872,7 +872,6 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
|
||||
bool wait = false;
|
||||
int sndsize;
|
||||
int pktsize;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Loop, sending packets while we can if the receiver supports streaming
|
||||
@ -977,12 +976,24 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
|
||||
ptr = pzm->scratch;
|
||||
pktsize = 0;
|
||||
|
||||
#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF
|
||||
/* Read multiple bytes of file and store into the temporal buffer */
|
||||
|
||||
zm_read(pzms->infd, pzm->filebuf, CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE);
|
||||
|
||||
i = 0;
|
||||
#endif
|
||||
|
||||
while (pktsize <= (CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE - 10) &&
|
||||
(ret = zm_getc(pzms->infd)) != EOF)
|
||||
(pzms->offset < pzms->filesize))
|
||||
{
|
||||
/* Add the new value to the accumulated CRC */
|
||||
|
||||
uint8_t ch = (uint8_t)ret;
|
||||
#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF
|
||||
uint8_t ch = pzm->filebuf[i++];
|
||||
#else
|
||||
uint8_t ch = zm_getc(pzms->infd);
|
||||
#endif
|
||||
if (!bcrc32)
|
||||
{
|
||||
crc = (uint32_t)crc16part(&ch, 1, (uint16_t)crc);
|
||||
@ -1007,6 +1018,12 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
|
||||
pzms->offset++;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF
|
||||
/* Restore file position to be read next time */
|
||||
|
||||
lseek(pzms->infd, pzms->offset, SEEK_SET);
|
||||
#endif
|
||||
|
||||
/* If we've reached file end, a ZEOF header will follow. If there's
|
||||
* room in the outgoing buffer for it, end the packet with ZCRCE and
|
||||
* append the ZEOF header. If there isn't room, we'll have to do a
|
||||
@ -1014,7 +1031,7 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm)
|
||||
*/
|
||||
|
||||
pzm->flags &= ~ZM_FLAG_EOF;
|
||||
if (ret == EOF)
|
||||
if (pzms->offset == pzms->filesize)
|
||||
{
|
||||
pzm->flags |= ZM_FLAG_EOF;
|
||||
if (wait || (pzms->rcvmax != 0 && pktsize < 24))
|
||||
|
Loading…
x
Reference in New Issue
Block a user