コード例 #1
0
ファイル: ZYSocketSuper.cs プロジェクト: Mrwch/ZYSOCKET-V
        void BeginAccep(ZYSocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                System.Threading.WaitHandle.WaitAll(reset);

                if (this.Connetions != null)
                {
                    if (!this.Connetions(e))
                    {
                        try
                        {
                            e.AcceptSocket?.Shutdown(SocketShutdown.Both);
                        }
                        catch { }

                        e.AcceptSocket = null;
                        Accept(e);
                        return;
                    }
                }

                e.SetBuffer(MaxBufferSize);
                BinaryInput?.Invoke(e);
                e.StreamInit();
                StartReceive(e);
            }
            else
            {
                Accept(e);
            }
        }
コード例 #2
0
        private void SocketClient_BinaryInput(byte[] data,int offset,int lengt)
        {
            RingBuffer.Write(data,offset,lengt);

            while (RingBuffer.Read(out byte[] pdata))            
                    BinaryInput?.Invoke(pdata);
            
        }
コード例 #3
0
        void ECompleted(SocketAsyncEventArgs e)
        {
            switch (e.LastOperation)
            {
            case SocketAsyncOperation.Connect:

                if (e.SocketError == SocketError.Success)
                {
                    IsConn = true;
                    wait?.Set();
                    Connection?.Invoke("Connect success", true);

                    byte[] data = new byte[4096];
                    e.SetBuffer(data, 0, data.Length);      //设置数据包

                    try
                    {
                        if (!_sock.ReceiveAsync(e))     //开始读取数据包
                        {
                            ECompleted(e);
                        }
                    }
                    catch (ObjectDisposedException)
                    {
                        IsConn = false;
                        Disconnect?.Invoke("Disconnect to socket");
                    }
                }
                else
                {
                    IsConn = false;
                    wait?.Set();
                    Connection?.Invoke("connect fail", false);
                }
                break;

            case SocketAsyncOperation.Receive:
                if (e.SocketError == SocketError.Success && e.BytesTransferred > 0)
                {
                    BinaryInput?.Invoke(e.Buffer, e.Offset, e.BytesTransferred);

                    try
                    {
                        if (!_sock.ReceiveAsync(e))
                        {
                            ECompleted(e);
                        }
                    }
                    catch (ObjectDisposedException)
                    {
                        IsConn = false;
                        Disconnect?.Invoke("Disconnect to socket");
                    }
                }
                else
                {
                    IsConn = false;
                    Disconnect?.Invoke("Disconnect to socket");
                }
                break;
            }
        }
コード例 #4
0
        public static void Binary(string path)
        {
            byte[] data = BinaryInput.Invoke(path);
            if (data.Length < 16)
            {
                return;
            }

            if (GetStr2(data, 0) != "NS")
            {
                return;
            }
            if (GetUint16(data, 2) != 0xFFFF)
            {
                return;
            }

            ushort sum = 0;

            for (int i = 0; i < data.Length - 2; i++)
            {
                sum += data[i];
            }
            if (sum != GetUint16(data, data.Length - 2))
            {
                return;
            }

            ushort heap, stack, regs, segCnt;

            heap   = GetUint16(data, 4);
            stack  = GetUint16(data, 6);
            regs   = GetUint16(data, 8);
            segCnt = GetUint16(data, 10);

            int offset = 12, segPos = -1;

            string[][] code = new string[segCnt][];
            for (int i = 0; i < segCnt; i++)
            {
                code[i] = new string[2];
            }

            const int SEG_NAME = 0, SEG_CODE = 1;
            int       state = SEG_NAME, offmax = data.Length - 1;

            while (offset <= offmax - 4)
            {
                if (GetUint16(data, offset) == 0xA5A5)
                {
                    if (segPos >= segCnt - 1)
                    {
                        return;
                    }
                    segPos         += 1; offset += 2;
                    state           = SEG_NAME;
                    code[segPos][0] = "";
                }
                else if (GetUint16(data, offset) == 0xAAAA)
                {
                    offset         += 2;
                    state           = SEG_CODE;
                    code[segPos][1] = "";
                }
                else
                {
                    if (state == SEG_NAME)
                    {
                        code[segPos][0] += (char)data[offset];
                    }
                    else if (state == SEG_CODE)
                    {
                        code[segPos][1] += (char)data[offset];
                    }
                    offset += 1;
                }
            }

            if (GetUint16(data, offset) != 0xFFFF)
            {
                return;
            }

            NSASM nsasm = new NSASM(heap, stack, regs, code);

            nsasm.Run();
            Print("\nNSASM running finished.\n\n");
        }