コード例 #1
0
 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");
     }
 }
コード例 #2
0
 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");
     }
 }
コード例 #3
0
 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");
     }
 }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
 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");
         }
     }
 }
コード例 #6
0
 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");
         }
     }
 }
コード例 #7
0
 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");
     }
 }
コード例 #8
0
 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");
     }
 }
コード例 #9
0
 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");
     }
 }
コード例 #10
0
 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");
     }
 }
コード例 #11
0
 private static void PeerCloses(ITestSocketPair pair)
 {
     pair.PeerCloses();
 }
コード例 #12
0
 //----
 private static void PeerSendsData(ITestSocketPair pair)
 {
     byte[] data = Encoding.ASCII.GetBytes("abcdefhijk");
     pair.PeerSendsData(data);
 }