public void WriteWhenClosedAfterRead() { // Write when closed. using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "11a"); PeerSendsData(pair); PeerCloses(pair); Assert.IsTrue(sock.Connected, "11b"); ReadSomeBytes(strm, 5); Assert.IsTrue(sock.Connected, "11c"); if (!m_connectedMayBeFalseEarlier) { WriteSomeBytes(strm); Assert.IsTrue(sock.Connected, "11d"); } int count = 0; while (true) { bool didFail = WriteSomeBytesExpectError(strm); ++count; if (didFail) { break; } Assert.IsTrue(sock.Connected, "11e_" + count); } Assert.IsFalse(sock.Connected, "11f"); } }
public void ReadWhenClosedAfterWrite() { // Read when closed (no data pending etc), after state refreshed by Write. using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "10a"); PeerCloses(pair); if (!m_connectedMayBeFalseEarlier) { Assert.IsTrue(sock.Connected, "10b"); WriteSomeBytes(strm); } int count = 0; while (true) { bool didFail = WriteSomeBytesExpectError(strm); ++count; if (didFail) { break; } Assert.IsTrue(sock.Connected, "11c_" + count); } Assert.IsFalse(sock.Connected, "10d"); ReadSomeBytesExpectError(strm); Assert.IsFalse(sock.Connected, "10e"); } }
public void LocalCloseOnSocket() { // Local close (Socket). using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "2a"); sock.Close(); Assert.IsFalse(sock.Connected, "2b"); } }
public void LocalCloseOnSocketAndWrite() { // Local close (Socket). using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "2a"); sock.Close(); Assert.IsFalse(sock.Connected, "2b"); WriteSomeBytesExpectError(strm, typeof(ObjectDisposedException)); } }
public void LocalShutdownBothOnSocket() { // Local shutdown_Both (Socket). if (m_spFactory.SocketSupportsShutdown) { using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "6a"); sock.Shutdown(SocketShutdown.Both); Assert.IsFalse(sock.Connected, "6b"); } } }
public void LocalCloseIntOnSocket() { // Local close(int) (Socket). if (m_spFactory.SocketSupportsCloseInt32) { using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "3a"); sock.Close(1); Thread.Sleep(1200); Assert.IsFalse(sock.Connected, "3b"); } } }
public void AsyncReadWhenClosed() { // Read when closed (no data pending etc). using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "10a"); PeerCloses(pair); Assert.IsTrue(sock.Connected, "10b"); // Eek, reading to EoF doesn't set Connected=false!! AsyncReadSomeBytesButExpectZeroOf(strm, sock, true); Assert.IsTrue(sock.Connected, "10c"); AsyncReadSomeBytesButExpectZeroOf(strm, sock, true); Assert.IsTrue(sock.Connected, "10d"); } }
public void AsyncWriteWhenClosed() { // Write when closed. using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "11a"); PeerCloses(pair); Assert.IsTrue(sock.Connected, "11b"); if (!m_connectedMayBeFalseEarlier) { AsyncWriteSomeBytes(strm, sock); Assert.IsTrue(sock.Connected, "11c"); } bool didFail = AsyncWriteSomeBytesExpectErrorInBegin(strm, sock); Assert.IsFalse(sock.Connected, "11d"); } }
public void AsyncReadWhenClosedAfterAsyncWrite() { // Read when closed (no data pending etc), when state refreshed by Write. using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "10a"); PeerCloses(pair); Assert.IsTrue(sock.Connected, "10b"); if (!m_connectedMayBeFalseEarlier) { AsyncWriteSomeBytes(strm, sock); Assert.IsTrue(sock.Connected, "10c"); } AsyncWriteSomeBytesExpectErrorInBegin(strm, sock); Assert.IsFalse(sock.Connected, "10d"); AsyncReadSomeBytesExpectErrorInBegin(strm, sock); Assert.IsFalse(sock.Connected, "10e"); } }
public void AsyncReadWhenClosedWhenPendingData() { // Read when closed when pending data. using (ITestSocketPair pair = m_spFactory.CreateSocketPair()) { ISocketWrapper sock = pair.SocketA; NetworkStream strm = sock.GetStream(); Assert.IsTrue(sock.Connected, "12a"); // PeerSendsData(pair); ReadSomeBytes(strm, 5); PeerCloses(pair); Assert.IsTrue(sock.Connected, "12b"); AsyncReadSomeBytes(strm, sock, 5, true); Assert.IsTrue(sock.Connected, "12c"); // Eek, reading to EoF doesn't set Connected=false!! AsyncReadSomeBytesButExpectZeroOf(strm, sock, true); Assert.IsTrue(sock.Connected, "12d"); AsyncReadSomeBytesButExpectZeroOf(strm, sock, true); Assert.IsTrue(sock.Connected, "12e"); } }
private static void PeerCloses(ITestSocketPair pair) { pair.PeerCloses(); }
//---- private static void PeerSendsData(ITestSocketPair pair) { byte[] data = Encoding.ASCII.GetBytes("abcdefhijk"); pair.PeerSendsData(data); }