sbuf.c revision 72223d4328cdf84381930e8358c2fe20a054b0da
/*
* Copyright (c) 1995 Danny Gasparovski.
*
* Please read the file COPYRIGHT for the
* terms and conditions of the copyright.
*/
#include <slirp.h>
/* Done as a macro in socket.h */
/* int
* sbspace(struct sockbuff *sb)
* {
* return SB_DATALEN - sb->sb_cc;
* }
*/
void
{
/** @todo bird: I'm seeing double frees here sometimes. This NULL'ing is just a
workaround for that, it doesn't actually fix anything. */
}
void
{
/*
* We can only drop how much we have
* This should never succeed
*/
}
void
{
{
/* Already alloced, realloc if necessary */
{
else
sb->sb_datalen = 0;
}
}
else
{
else
sb->sb_datalen = 0;
}
}
/*
* Try and write() to the socket, whatever doesn't get written
* append to the buffer... for a host with a fast net connection,
* this prevents an unnecessary copy of the data
* (the socket is non-blocking, so we won't hang)
*/
void
{
int ret = 0;
#ifdef VBOX_WITH_SLIRP_BSD_MBUF
int mlen = 0;
#endif
DEBUG_CALL("sbappend");
DEBUG_ARG("m = %lx", (long)m);
/* Shouldn't happen, but... e.g. foreign host closes connection */
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
if (m->m_len <= 0)
#else
if (mlen <= 0)
#endif
{
goto done;
}
/*
* If there is urgent data, call sosendoob
* if not all was sent, sowrite will take care of the rest
* (The rest of this function is just an optimisation)
*/
{
return;
}
/*
* We only write if there's nothing in the buffer,
* ottherwise it'll arrive out of order, and hence corrupt
*/
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
#else
{
ret = 0;
goto no_sent;
}
#endif
if (ret <= 0)
{
/*
* Nothing was written
* It's possible that the socket has closed, but
* we don't need to check because if it has closed,
* it will be detected in the normal way by soread()
*/
goto done;
}
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
#else
#endif
{
/*
* Something was written, but not everything..
* sbappendsb the rest
*/
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
#else
#endif
goto done;
} /* else */
/* Whatever happened, we free the mbuf */
done:
}
/*
* Copy the data from m into sb
* The caller is responsible to make sure there's enough room
*/
void
{
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
#else
#endif
{
if (n > len)
n = len;
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
#else
#endif
}
else
{
/* Do the right edge first */
if (n > len)
n = len;
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
#else
#endif
len -= n;
if (len)
{
/* Now the left edge */
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
#else
#endif
n += nn;
}
}
{
}
}
/*
* Copy data from sbuf to a normal, straight buffer
* Don't update the sbuf rptr, this will be
* done in sbdrop when the data is acked
*/
void
{
char *from;
{
}
else
{
/* re-use off */
if (len)
}
}