diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 55f4e4a5ec657a017e3bf75299ad71fd1c968dd3 (patch) | |
tree | 550ce922ea0e125ac6a9738210ce2939bf2fe901 /slirp/sbuf.c | |
parent | 413f05aaf54fa08c0ae7e997327a4f4a473c0a8d (diff) | |
download | external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.zip external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.tar.gz external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.tar.bz2 |
Initial Contribution
Diffstat (limited to 'slirp/sbuf.c')
-rw-r--r-- | slirp/sbuf.c | 91 |
1 files changed, 33 insertions, 58 deletions
diff --git a/slirp/sbuf.c b/slirp/sbuf.c index d6726c9..3d975f8 100644 --- a/slirp/sbuf.c +++ b/slirp/sbuf.c @@ -6,26 +6,17 @@ */ #include <slirp.h> - -/* Done as a macro in socket.h */ -/* int - * sbspace(struct sockbuff *sb) - * { - * return SB_DATALEN - sb->sb_cc; - * } - */ +#define SLIRP_COMPILATION +#include "sockets.h" void -sbfree(sb) - struct sbuf *sb; +sbuf_free(SBuf sb) { free(sb->sb_data); } void -sbdrop(sb, num) - struct sbuf *sb; - int num; +sbuf_drop(SBuf sb, int num) { /* * We can only drop how much we have @@ -41,28 +32,17 @@ sbdrop(sb, num) } void -sbreserve(sb, size) - struct sbuf *sb; - int size; +sbuf_reserve(SBuf sb, int size) { - if (sb->sb_data) { - /* Already alloced, realloc if necessary */ - if (sb->sb_datalen != size) { - sb->sb_wptr = sb->sb_rptr = sb->sb_data = (char *)realloc(sb->sb_data, size); - sb->sb_cc = 0; - if (sb->sb_wptr) - sb->sb_datalen = size; - else - sb->sb_datalen = 0; - } - } else { - sb->sb_wptr = sb->sb_rptr = sb->sb_data = (char *)malloc(size); - sb->sb_cc = 0; - if (sb->sb_wptr) - sb->sb_datalen = size; - else - sb->sb_datalen = 0; - } + if (sb->sb_datalen == size) + return; + + sb->sb_wptr = sb->sb_rptr = sb->sb_data = (char *)realloc(sb->sb_data, size); + sb->sb_cc = 0; + if (sb->sb_wptr) + sb->sb_datalen = size; + else + sb->sb_datalen = 0; } /* @@ -72,20 +52,18 @@ sbreserve(sb, size) * (the socket is non-blocking, so we won't hang) */ void -sbappend(so, m) - struct socket *so; - struct mbuf *m; +sbuf_append(struct socket *so, MBuf m) { int ret = 0; - - DEBUG_CALL("sbappend"); + + DEBUG_CALL("sbuf_append"); DEBUG_ARG("so = %lx", (long)so); DEBUG_ARG("m = %lx", (long)m); DEBUG_ARG("m->m_len = %d", m->m_len); /* Shouldn't happen, but... e.g. foreign host closes connection */ if (m->m_len <= 0) { - m_free(m); + mbuf_free(m); return; } @@ -95,8 +73,8 @@ sbappend(so, m) * (The rest of this function is just an optimisation) */ if (so->so_urgc) { - sbappendsb(&so->so_rcv, m); - m_free(m); + sbuf_appendsb(&so->so_rcv, m); + mbuf_free(m); sosendoob(so); return; } @@ -105,9 +83,12 @@ sbappend(so, m) * We only write if there's nothing in the buffer, * ottherwise it'll arrive out of order, and hence corrupt */ - if (!so->so_rcv.sb_cc) - ret = send(so->s, m->m_data, m->m_len, 0); - + if (!so->so_rcv.sb_cc) { + do { + ret = send(so->s, m->m_data, m->m_len, 0); + } while (ret == 0 && socket_errno == EINTR); + } + if (ret <= 0) { /* * Nothing was written @@ -115,18 +96,18 @@ sbappend(so, m) * we don't need to check because if it has closed, * it will be detected in the normal way by soread() */ - sbappendsb(&so->so_rcv, m); + sbuf_appendsb(&so->so_rcv, m); } else if (ret != m->m_len) { /* * Something was written, but not everything.. - * sbappendsb the rest + * sbuf_appendsb the rest */ m->m_len -= ret; m->m_data += ret; - sbappendsb(&so->so_rcv, m); + sbuf_appendsb(&so->so_rcv, m); } /* else */ /* Whatever happened, we free the mbuf */ - m_free(m); + mbuf_free(m); } /* @@ -134,9 +115,7 @@ sbappend(so, m) * The caller is responsible to make sure there's enough room */ void -sbappendsb(sb, m) - struct sbuf *sb; - struct mbuf *m; +sbuf_appendsb(SBuf sb, MBuf m) { int len, n, nn; @@ -161,7 +140,7 @@ sbappendsb(sb, m) } } - sb->sb_cc += n; + sb->sb_cc += n; sb->sb_wptr += n; if (sb->sb_wptr >= sb->sb_data + sb->sb_datalen) sb->sb_wptr -= sb->sb_datalen; @@ -173,11 +152,7 @@ sbappendsb(sb, m) * done in sbdrop when the data is acked */ void -sbcopy(sb, off, len, to) - struct sbuf *sb; - int off; - int len; - char *to; +sbuf_copy(SBuf sb, int off, int len, char* to) { char *from; |