soread(so)

	struct socket *so;

{

	int n, nn, lss, total;

	struct sbuf *sb = &so->so_snd;

	int len = sb->sb_datalen - sb->sb_cc;

	struct iovec iov[2];

	int mss = so->so_tcpcb->t_maxseg;



	DEBUG_CALL("soread");

	DEBUG_ARG("so = %lx", (long )so);



	/*

	 * No need to check if there's enough room to read.

	 * soread wouldn't have been called if there weren't

	 */



	len = sb->sb_datalen - sb->sb_cc;



	iov[0].iov_base = sb->sb_wptr;



	if (sb->sb_wptr < sb->sb_rptr) {

		iov[0].iov_len = sb->sb_rptr - sb->sb_wptr;

		/* Should never succeed, but... */

		if (iov[0].iov_len > len)

		   iov[0].iov_len = len;

		if (iov[0].iov_len > mss)

		   iov[0].iov_len -= iov[0].iov_len%mss;

		n = 1;

	} else {

		iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr;

		/* Should never succeed, but... */

		if (iov[0].iov_len > len) iov[0].iov_len = len;

		len -= iov[0].iov_len;

		if (len) {

			iov[1].iov_base = sb->sb_data;

			iov[1].iov_len = sb->sb_rptr - sb->sb_data;

			if(iov[1].iov_len > len)

			   iov[1].iov_len = len;

			total = iov[0].iov_len + iov[1].iov_len;

			if (total > mss) {

				lss = total%mss;

				if (iov[1].iov_len > lss) {

					iov[1].iov_len -= lss;

					n = 2;

				} else {

					lss -= iov[1].iov_len;

					iov[0].iov_len -= lss;

					n = 1;

				}

			} else

				n = 2;

		} else {

			if (iov[0].iov_len > mss)

			   iov[0].iov_len -= iov[0].iov_len%mss;

			n = 1;

		}

	}



#ifdef HAVE_READV

	nn = readv(so->s, (struct iovec *)iov, n);

	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));

#else

	nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);

#endif

	if (nn <= 0) {

		if (nn < 0 && (errno == EINTR || errno == EAGAIN))

			return 0;

		else {

			DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));

			sofcantrcvmore(so);

			tcp_sockclosed(sototcpcb(so));

			return -1;

		}

	}



#ifndef HAVE_READV

	/*

	 * If there was no error, try and read the second time round

	 * We read again if n = 2 (ie, there's another part of the buffer)

	 * and we read as much as we could in the first read

	 * We don't test for <= 0 this time, because there legitimately

	 * might not be any more data (since the socket is non-blocking),

	 * a close will be detected on next iteration.

	 * A return of -1 wont (shouldn't) happen, since it didn't happen above

	 */

	if (n == 2 && nn == iov[0].iov_len) {

            int ret;

            ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0);

            if (ret > 0)

                nn += ret;

        }



	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));

#endif



	/* Update fields */

	sb->sb_cc += nn;

	sb->sb_wptr += nn;

	if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen))

		sb->sb_wptr -= sb->sb_datalen;

	return nn;

}
soread(so)

	struct socket *so;

{

	int n, nn, lss, total;

	struct sbuf *sb = &so->so_snd;

	int len = sb->sb_datalen - sb->sb_cc;

	struct iovec iov[2];

	int mss = so->so_tcpcb->t_maxseg;



	DEBUG_CALL("soread");

	DEBUG_ARG("so = %lx", (long )so);



	









	len = sb->sb_datalen - sb->sb_cc;



	iov[0].iov_base = sb->sb_wptr;



	if (sb->sb_wptr < sb->sb_rptr) {

		iov[0].iov_len = sb->sb_rptr - sb->sb_wptr;

		

		if (iov[0].iov_len > len)

		   iov[0].iov_len = len;

		if (iov[0].iov_len > mss)

		   iov[0].iov_len -= iov[0].iov_len%mss;

		n = 1;

	} else {

		iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr;

		

		if (iov[0].iov_len > len) iov[0].iov_len = len;

		len -= iov[0].iov_len;

		if (len) {

			iov[1].iov_base = sb->sb_data;

			iov[1].iov_len = sb->sb_rptr - sb->sb_data;

			if(iov[1].iov_len > len)

			   iov[1].iov_len = len;

			total = iov[0].iov_len + iov[1].iov_len;

			if (total > mss) {

				lss = total%mss;

				if (iov[1].iov_len > lss) {

					iov[1].iov_len -= lss;

					n = 2;

				} else {

					lss -= iov[1].iov_len;

					iov[0].iov_len -= lss;

					n = 1;

				}

			} else

				n = 2;

		} else {

			if (iov[0].iov_len > mss)

			   iov[0].iov_len -= iov[0].iov_len%mss;

			n = 1;

		}

	}



#ifdef HAVE_READV

	nn = readv(so->s, (struct iovec *)iov, n);

	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));

#else

	nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);

#endif

	if (nn <= 0) {

		if (nn < 0 && (errno == EINTR || errno == EAGAIN))

			return 0;

		else {

			DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));

			sofcantrcvmore(so);

			tcp_sockclosed(sototcpcb(so));

			return -1;

		}

	}



#ifndef HAVE_READV

	

















	if (n == 2 && nn == iov[0].iov_len) {

            int ret;

            ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0);

            if (ret > 0)

                nn += ret;

        }



	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));

#endif



	

	sb->sb_cc += nn;

	sb->sb_wptr += nn;

	if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen))

		sb->sb_wptr -= sb->sb_datalen;

	return nn;

}
FUNC_0(VAR_0)

	struct socket *VAR_0;

{

	int VAR_1, VAR_2, VAR_3, VAR_4;

	struct sbuf *VAR_5 = &VAR_0->so_snd;

	int VAR_6 = VAR_5->sb_datalen - VAR_5->sb_cc;

	struct iovec VAR_7[2];

	int VAR_8 = VAR_0->so_tcpcb->t_maxseg;



	DEBUG_CALL("FUNC_0");

	DEBUG_ARG("VAR_0 = %lx", (long )VAR_0);



	









	VAR_6 = VAR_5->sb_datalen - VAR_5->sb_cc;



	VAR_7[0].iov_base = VAR_5->sb_wptr;



	if (VAR_5->sb_wptr < VAR_5->sb_rptr) {

		VAR_7[0].iov_len = VAR_5->sb_rptr - VAR_5->sb_wptr;

		

		if (VAR_7[0].iov_len > VAR_6)

		   VAR_7[0].iov_len = VAR_6;

		if (VAR_7[0].iov_len > VAR_8)

		   VAR_7[0].iov_len -= VAR_7[0].iov_len%VAR_8;

		VAR_1 = 1;

	} else {

		VAR_7[0].iov_len = (VAR_5->sb_data + VAR_5->sb_datalen) - VAR_5->sb_wptr;

		

		if (VAR_7[0].iov_len > VAR_6) VAR_7[0].iov_len = VAR_6;

		VAR_6 -= VAR_7[0].iov_len;

		if (VAR_6) {

			VAR_7[1].iov_base = VAR_5->sb_data;

			VAR_7[1].iov_len = VAR_5->sb_rptr - VAR_5->sb_data;

			if(VAR_7[1].iov_len > VAR_6)

			   VAR_7[1].iov_len = VAR_6;

			VAR_4 = VAR_7[0].iov_len + VAR_7[1].iov_len;

			if (VAR_4 > VAR_8) {

				VAR_3 = VAR_4%VAR_8;

				if (VAR_7[1].iov_len > VAR_3) {

					VAR_7[1].iov_len -= VAR_3;

					VAR_1 = 2;

				} else {

					VAR_3 -= VAR_7[1].iov_len;

					VAR_7[0].iov_len -= VAR_3;

					VAR_1 = 1;

				}

			} else

				VAR_1 = 2;

		} else {

			if (VAR_7[0].iov_len > VAR_8)

			   VAR_7[0].iov_len -= VAR_7[0].iov_len%VAR_8;

			VAR_1 = 1;

		}

	}



#ifdef HAVE_READV

	VAR_2 = readv(VAR_0->s, (struct iovec *)VAR_7, VAR_1);

	DEBUG_MISC((dfd, " ... read VAR_2 = %d bytes\VAR_1", VAR_2));

#else

	VAR_2 = recv(VAR_0->s, VAR_7[0].iov_base, VAR_7[0].iov_len,0);

#endif

	if (VAR_2 <= 0) {

		if (VAR_2 < 0 && (errno == EINTR || errno == EAGAIN))

			return 0;

		else {

			DEBUG_MISC((dfd, " --- FUNC_0() disconnected, VAR_2 = %d, errno = %d-%s\VAR_1", VAR_2, errno,strerror(errno)));

			sofcantrcvmore(VAR_0);

			tcp_sockclosed(sototcpcb(VAR_0));

			return -1;

		}

	}



#ifndef HAVE_READV

	

















	if (VAR_1 == 2 && VAR_2 == VAR_7[0].iov_len) {

            int VAR_9;

            VAR_9 = recv(VAR_0->s, VAR_7[1].iov_base, VAR_7[1].iov_len,0);

            if (VAR_9 > 0)

                VAR_2 += VAR_9;

        }



	DEBUG_MISC((dfd, " ... read VAR_2 = %d bytes\VAR_1", VAR_2));

#endif



	

	VAR_5->sb_cc += VAR_2;

	VAR_5->sb_wptr += VAR_2;

	if (VAR_5->sb_wptr >= (VAR_5->sb_data + VAR_5->sb_datalen))

		VAR_5->sb_wptr -= VAR_5->sb_datalen;

	return VAR_2;

}
FUNC_0(VAR_0)
struct socket *VAR_0; { int VAR_1, VAR_2, VAR_3, VAR_4; struct sbuf *VAR_5 = &VAR_0->so_snd; int VAR_6 = VAR_5->sb_datalen - VAR_5->sb_cc; struct iovec VAR_7[2]; int VAR_8 = VAR_0->so_tcpcb->t_maxseg; DEBUG_CALL("FUNC_0"); DEBUG_ARG("VAR_0 = %lx", (long )VAR_0); VAR_6 = VAR_5->sb_datalen - VAR_5->sb_cc; VAR_7[0].iov_base = VAR_5->sb_wptr; if (VAR_5->sb_wptr < VAR_5->sb_rptr) { VAR_7[0].iov_len = VAR_5->sb_rptr - VAR_5->sb_wptr; if (VAR_7[0].iov_len > VAR_6)
VAR_7[0].iov_len = VAR_6; if (VAR_7[0].iov_len > VAR_8)
VAR_7[0].iov_len -= VAR_7[0].iov_len%VAR_8; VAR_1 = 1; } else { VAR_7[0].iov_len = (VAR_5->sb_data + VAR_5->sb_datalen) - VAR_5->sb_wptr; if (VAR_7[0].iov_len > VAR_6) VAR_7[0].iov_len = VAR_6; VAR_6 -= VAR_7[0].iov_len; if (VAR_6) { VAR_7[1].iov_base = VAR_5->sb_data; VAR_7[1].iov_len = VAR_5->sb_rptr - VAR_5->sb_data; if(VAR_7[1].iov_len > VAR_6)
VAR_7[1].iov_len = VAR_6; VAR_4 = VAR_7[0].iov_len + VAR_7[1].iov_len; if (VAR_4 > VAR_8) { VAR_3 = VAR_4%VAR_8; if (VAR_7[1].iov_len > VAR_3) { VAR_7[1].iov_len -= VAR_3; VAR_1 = 2; } else { VAR_3 -= VAR_7[1].iov_len; VAR_7[0].iov_len -= VAR_3; VAR_1 = 1; } } else VAR_1 = 2; } else { if (VAR_7[0].iov_len > VAR_8)
VAR_7[0].iov_len -= VAR_7[0].iov_len%VAR_8; VAR_1 = 1; } } #ifdef HAVE_READV
VAR_2 = readv(VAR_0->s, (struct iovec *)VAR_7, VAR_1); DEBUG_MISC((dfd, " ... read VAR_2 = %d bytes\VAR_1", VAR_2)); #else
VAR_2 = recv(VAR_0->s, VAR_7[0].iov_base, VAR_7[0].iov_len,0); #endif
if (VAR_2 <= 0) { if (VAR_2 < 0 && (errno == EINTR || errno == EAGAIN))
return 0; else { DEBUG_MISC((dfd, " --- FUNC_0() disconnected, VAR_2 = %d, errno = %d-%s\VAR_1", VAR_2, errno,strerror(errno))); sofcantrcvmore(VAR_0); tcp_sockclosed(sototcpcb(VAR_0)); return -1; } } #ifndef HAVE_READV
if (VAR_1 == 2 && VAR_2 == VAR_7[0].iov_len) { int VAR_9; VAR_9 = recv(VAR_0->s, VAR_7[1].iov_base, VAR_7[1].iov_len,0); if (VAR_9 > 0)
VAR_2 += VAR_9; } DEBUG_MISC((dfd, " ... read VAR_2 = %d bytes\VAR_1", VAR_2)); #endif
VAR_5->sb_cc += VAR_2; VAR_5->sb_wptr += VAR_2; if (VAR_5->sb_wptr >= (VAR_5->sb_data + VAR_5->sb_datalen))
VAR_5->sb_wptr -= VAR_5->sb_datalen; return VAR_2; }