diff options
| author | [email protected] <[email protected]> | 2011-08-20 14:34:05 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-08-20 14:34:05 +0000 |
| commit | 3dcb78d3e09224443d7536e0692835418c2d2a02 (patch) | |
| tree | c6802ada73757da3d296f542de762f1b46f95aba /components/net | |
| parent | e1e75c4572cb1e1971d5c636e582d6608ca4aa22 (diff) | |
optimize netio code.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1674 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/net')
| -rw-r--r-- | components/net/lwip/apps/netio.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/components/net/lwip/apps/netio.c b/components/net/lwip/apps/netio.c index 48d016bf7b..0466cc5f6d 100644 --- a/components/net/lwip/apps/netio.c +++ b/components/net/lwip/apps/netio.c @@ -183,6 +183,7 @@ netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) } } else if (ns->state == NETIO_STATE_RECV_DATA) { + int chunk_length; if(ns->cntr == 0){ /* save the first byte of this new round of data @@ -191,13 +192,18 @@ netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) */ ns->first_byte = *data_ptr; } + + if (ns->cntr + (data_cntr + 1) < ns->data_len) chunk_length = data_cntr + 1; + else chunk_length = (ns->data_len - ns->cntr); + + ns->buf_pos += chunk_length; + data_ptr += chunk_length; + ns->cntr += chunk_length; + data_cntr -= (chunk_length - 1); - ns->buf_ptr[ns->buf_pos++] = *data_ptr++; - ns->cntr++; - - if (ns->buf_pos == NETIO_BUF_SIZE) { + if (ns->buf_pos >= NETIO_BUF_SIZE) { /* circularize the buffer */ - ns->buf_pos = 0; + ns->buf_pos %= NETIO_BUF_SIZE; } if(ns->cntr == ns->data_len){ |
