Beispiel #1
0
            void WriteToSock(PseudoTcp.PseudoTcpSocket sock)
            {
                byte[] buf = new byte[1024];
                int    len;
                int    wlen;
                int    total = 0;

                while (true)
                {
                    len = mStream.Read(buf, 0, buf.Length);
                    if (len == 0)
                    {
                        // reading_done = TRUE;
                        PseudoTcp.pseudo_tcp_socket_close(sock, false);
                        break;
                    }

                    wlen   = PseudoTcp.pseudo_tcp_socket_send(sock, buf, (uint)len);
                    total += wlen;
                    mTotalReadFromLeft += wlen;

                    if (wlen < len)
                    {
                        // fseek (in, wlen - len, SEEK_CUR);

                        mStream.Position += wlen - len; // go back to later reread what couldn't be sent

                        // g_assert (!feof (in));
                        // g_debug ("Socket queue full after %d bytes written", total);
                        break;
                    }
                }

                mCommon.AdjustClock(sock);
            }
Beispiel #2
0
            internal void Readable(PseudoTcp.PseudoTcpSocket sock, object data)
            {
                byte[] buf = new byte[1024];
                int    len;

                do
                {
                    len = PseudoTcp.pseudo_tcp_socket_recv(sock, buf, (uint)buf.Length);

                    if (len < 0)
                    {
                        break;
                    }

                    if (len == 0)
                    {
                        PseudoTcp.pseudo_tcp_socket_close(sock, false);

                        break;
                    }

                    Console.WriteLine("Right: Read {0} bytes", len);
                    mStream.Write(buf, 0, len);

                    mTotalWroteToRight += len;

                    Assert.IsTrue(mTotalWroteToRight <= mLeft.TotalReadFromLeft);
                    // g_debug ("Written %d bytes, need %d bytes", total_wrote, total_read);

                    if (mTotalWroteToRight == mLeft.TotalReadFromLeft && mLeft.Eof())
                    {
                        //g_assert (reading_done);
                        PseudoTcp.pseudo_tcp_socket_close(sock, false);
                    }
                } while (len > 0);

                if (len == -1 &&
                    PseudoTcp.pseudo_tcp_socket_get_error(sock) != PseudoTcp.EWOULDBLOCK)
                {
                    Assert.Fail("Error reading from right socket {0}", PseudoTcp.pseudo_tcp_socket_get_error(sock));
                }
            }