Пример #1
0
 public void Lengthが0の時Dequeueで100バイト取得しても0バイトしか返らない()
 {
     //setUp
     var sut = new SockQueue();
     const int expected = 0;
     //exercise
     var actual = sut.Dequeue(100).Length;
     //verify
     Assert.That(actual, Is.EqualTo(expected));
 }
Пример #2
0
 public void Lengthが200の時Dequeueで100バイト取得すると100バイト返る()
 {
     //setUp
     var sut = new SockQueue();
     sut.Enqueue(new byte[200], 200);
     const int expected = 100;
     //exercise
     var actual = sut.Dequeue(100).Length;
     //verify
     Assert.That(actual, Is.EqualTo(expected));
 }
Пример #3
0
 public void EnqueueしたデータとDequeueしたデータの整合性を確認する()
 {
     //setUp
     var sut = new SockQueue();
     var expected = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     sut.Enqueue(expected, 10);
     //exercise
     var actual = sut.Dequeue(10);
     //verify
     Assert.That(actual, Is.EqualTo(expected));
 }
Пример #4
0
        //接続完了処理(受信待機開始)
        private void BeginReceive()
        {
            //受信バッファは接続完了後に確保される
            _sockQueue = new SockQueue();
            _recvBuf   = new byte[_sockQueue.Space]; //キューが空なので、Spaceはバッファの最大サイズになっている

            // Using the LocalEndPoint property.
            string s = string.Format("My local IpAddress is :" + IPAddress.Parse(((IPEndPoint)_socket.LocalEndPoint).Address.ToString()) + "I am connected on port number " + ((IPEndPoint)_socket.LocalEndPoint).Port.ToString());


            try{
//Ver5.6.0
                Set(SockState.Connect, (IPEndPoint)_socket.LocalEndPoint, (IPEndPoint)_socket.RemoteEndPoint);
            } catch {
                SetError("set IPENdPoint faild.");
                return;
            }

            //受信待機の開始(oneSsl!=nullの場合、受信バイト数は0に設定する)
            //socket.BeginReceive(tcpBuffer, 0, (oneSsl != null) ? 0 : tcpQueue.Space, SocketFlags.None, new AsyncCallback(EndReceive), this);


            try{
                if (_ssl != null)
                {
                    //Ver5.9.2 Java fix
                    _oneSsl.BeginRead(_recvBuf, 0, _sockQueue.Space, EndReceive, this);
                }
                else
                {
                    _socket.BeginReceive(_recvBuf, 0, _sockQueue.Space, SocketFlags.None, EndReceive, this);
                }
            } catch {
                SetError("BeginRecvive() faild.");
            }
        }
Пример #5
0
        //接続完了処理(受信待機開始)
        private void BeginReceive()
        {
            //受信バッファは接続完了後に確保される
            _sockQueue = new SockQueue();
            _recvBuf = new byte[_sockQueue.Space]; //キューが空なので、Spaceはバッファの最大サイズになっている

            // Using the LocalEndPoint property.
            string s = string.Format("My local IpAddress is :" + IPAddress.Parse(((IPEndPoint) _socket.LocalEndPoint).Address.ToString()) + "I am connected on port number " + ((IPEndPoint) _socket.LocalEndPoint).Port.ToString());

            try{
            //Ver5.6.0
                Set(SockState.Connect, (IPEndPoint) _socket.LocalEndPoint, (IPEndPoint) _socket.RemoteEndPoint);
            } catch{
                SetError("set IPENdPoint faild.");
                return;
            }

            //受信待機の開始(oneSsl!=nullの場合、受信バイト数は0に設定する)
            //socket.BeginReceive(tcpBuffer, 0, (oneSsl != null) ? 0 : tcpQueue.Space, SocketFlags.None, new AsyncCallback(EndReceive), this);

            try{
                if (_ssl != null){
                    //Ver5.9.2 Java fix
                    _oneSsl.BeginRead(_recvBuf, 0, _sockQueue.Space, EndReceive, this);
                } else{
                    _socket.BeginReceive(_recvBuf, 0, _sockQueue.Space, SocketFlags.None, EndReceive, this);
                }
            } catch{
                SetError("BeginRecvive() faild.");
            }
        }
Пример #6
0
        public void SockQueueスペース確認()
        {
            const int max = 2000000;

            var sockQueu = new SockQueue();

            var space = sockQueu.Space;
            //キューの空きサイズ
            Assert.That(space, Is.EqualTo(max));

            var buf = new byte[max - 100];
            sockQueu.Enqueue(buf, buf.Length);

            space = sockQueu.Space;
            //キューの空きサイズ
            Assert.That(space, Is.EqualTo(100));

            var len = sockQueu.Enqueue(buf, 200);
            //空きサイズを超えて格納すると失敗する(※0が返る)
            Assert.That(len, Is.EqualTo(0));
        }
Пример #7
0
 public void 生成時のlengthは0になる()
 {
     //setUp
     var sut = new SockQueue();
     const int expected = 0;
     //exercise
     var actual = sut.Length;
     //verify
     Assert.That(actual, Is.EqualTo(expected));
 }
Пример #8
0
        public void SockQueue行取得()
        {
            //int max = 1048560;

            var sockQueu = new SockQueue();

            var lines = new byte[]{0x61, 0x0d, 0x0a, 0x62, 0x0d, 0x0a, 0x63};
            sockQueu.Enqueue(lines, lines.Length);
            //2行と改行なしの1行で初期化

            var buf = sockQueu.DequeueLine();
            //sockQueue.dequeuLine()=\"1/r/n\" 1行目取得
            Assert.That(buf, Is.EqualTo(new byte[]{0x61, 0x0d, 0x0a}));

            //sockQueue.dequeuLine()=\"2/r/n\" 2行目取得
            buf = sockQueu.DequeueLine();
            Assert.That(buf, Is.EqualTo(new byte[]{0x62, 0x0d, 0x0a}));

            buf = sockQueu.DequeueLine();
            //sockQueue.dequeuLine()=\"\" 3行目の取得は失敗する
            Assert.That(buf, Is.EqualTo(new byte[0]));

            lines = new byte[]{0x0d, 0x0a};
            sockQueu.Enqueue(lines, lines.Length);
            //"sockQueue.enqueu(/r/n) 改行のみ追加

            buf = sockQueu.DequeueLine();
            //sockQueue.dequeuLine()=\"3\" 3行目の取得に成功する"
            Assert.That(buf, Is.EqualTo(new byte[]{0x63, 0x0d, 0x0a}));
        }