コード例 #1
0
ファイル: K3pTransport.cs プロジェクト: tmbx/kwm-ng
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf = new byte[3];
     inPos = 0;
 }
コード例 #2
0
ファイル: K3pTransport.cs プロジェクト: tmbx/kwm-ng
        public void doXfer()
        {
            bool loop = true;

            while (loop)
            {
                loop = false;

                if (inState == InState.RecvHdr)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg = new K3pElement();

                            inMsg.ParseType(inBuf);

                            switch (inMsg.Type)
                            {
                                case K3pElement.K3pType.INS:
                                    inState = InState.RecvIns;
                                    inPos = 0;
                                    inBuf = new byte[8];
                                    break;
                                case K3pElement.K3pType.INT:
                                    inState = InState.RecvInt;
                                    inPos = 0;
                                    inBuf = new byte[20];
                                    break;
                                case K3pElement.K3pType.STR:
                                    inState = InState.RecvStrSize;
                                    inBuf = new byte[20];
                                    inPos = 0;
                                    break;
                            }
                        }
                    }
                }

                if (inState == InState.RecvIns)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg.ParseIns(inBuf);
                            inState = InState.Received;
                        }
                    }
                }

                if (inState == InState.RecvInt || inState == InState.RecvStrSize)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, 1);

                    if (r > 0)
                    {
                        loop = true;
                        inPos += r;

                        if ((char)inBuf[inPos - 1] == '>')
                        {
                            byte[] tmpInBuf = new byte[inPos];
                            for (int i = 0; i < inPos; i++)
                            {
                                tmpInBuf[i] = inBuf[i];
                            }
                            inMsg.ParseInt(tmpInBuf);
                            if (inState == InState.RecvStrSize)
                            {
                                inState = InState.RecvStr;
                                inBuf = new byte[inMsg.Int];
                                inPos = 0;

                                if (inMsg.Int == 0)
                                {
                                    inMsg.ParseStr(inBuf);
                                    inState = InState.Received;
                                }
                            }
                            else
                                inState = InState.Received;
                        }
                        else if (inPos == inBuf.Length)
                        {
                            throw new K3pException("Expecting a '>' to end an INT in k3p message");
                        }
                    }
                }

                if (inState == InState.RecvStr)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg.ParseStr(inBuf);
                            inState = InState.Received;
                        }
                    }
                }

                if (outState == OutState.Sending)
                {
                    int r = KSocket.SockWrite(sock, outBuf, outPos, outBuf.Length - outPos);

                    if (r > 0)
                    {
                        loop = true;
                        outPos += r;

                        if (outPos == outBuf.Length)
                        {
                            outState = OutState.NoPacket;
                            break;
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: AnpTransport.cs プロジェクト: tmbx/csutils
        public void doXfer()
        {
            bool loop = true;

            while (loop)
            {
                loop = false;

                if (inState == InState.RecvHdr)
                {
                    int r = Base.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg = new AnpMsg();

                            UInt32 size = 0;
                            AnpMsg.ParseHdr(inBuf, ref inMsg.Major, ref inMsg.Minor, ref inMsg.Type, ref inMsg.ID, ref size);

                            if (size > AnpMsg.MaxSize)
                            {
                                throw new AnpException("ANP message is too large");
                            }

                            if (size > 0)
                            {
                                inState = InState.RecvPayload;
                                inBuf = new byte[size];
                                inPos = 0;
                            }

                            else
                            {
                                inState = InState.Received;
                            }
                        }
                    }
                }

                if (inState == InState.RecvPayload)
                {
                    int r = Base.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg.Elements = AnpMsg.ParsePayload(inBuf);
                            inState = InState.Received;
                        }
                    }
                }

                if (outState == OutState.Sending)
                {
                    int r = Base.SockWrite(sock, outBuf, outPos, outBuf.Length - outPos);

                    if (r > 0)
                    {
                        loop = true;
                        outPos += r;

                        if (outPos == outBuf.Length)
                        {
                            outState = OutState.NoPacket;
                            break;
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: K3pTransport.cs プロジェクト: tmbx/kwm-ng
 public void flushRecv()
 {
     inState = InState.NoMsg;
 }
コード例 #5
0
ファイル: C.cs プロジェクト: perl-easj/OOProg
 public C(InState inState, ExState exState)
 {
     TheInState = inState;
     TheExState = exState;
 }
コード例 #6
0
ファイル: AnpTransport.cs プロジェクト: tmbx/csutils
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf = new byte[AnpMsg.HdrSize];
     inPos = 0;
 }
コード例 #7
0
ファイル: AnpTransport.cs プロジェクト: fdgonthier/TbxUtils
        public void doXfer()
        {
            bool loop = true;

            while (loop)
            {
                loop = false;

                if (inState == InState.RecvHdr)
                {
                    int r = Base.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop   = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg = new AnpMsg();

                            UInt32 size = 0;
                            AnpMsg.ParseHdr(inBuf, ref inMsg.Major, ref inMsg.Minor, ref inMsg.Type, ref inMsg.ID, ref size);

                            if (size > AnpMsg.MaxSize)
                            {
                                throw new AnpException("ANP message is too large");
                            }

                            if (size > 0)
                            {
                                inState = InState.RecvPayload;
                                inBuf   = new byte[size];
                                inPos   = 0;
                            }

                            else
                            {
                                inState = InState.Received;
                            }
                        }
                    }
                }

                if (inState == InState.RecvPayload)
                {
                    int r = Base.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop   = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg.Elements = AnpMsg.ParsePayload(inBuf);
                            inState        = InState.Received;
                        }
                    }
                }

                if (outState == OutState.Sending)
                {
                    int r = Base.SockWrite(sock, outBuf, outPos, outBuf.Length - outPos);

                    if (r > 0)
                    {
                        loop    = true;
                        outPos += r;

                        if (outPos == outBuf.Length)
                        {
                            outState = OutState.NoPacket;
                            break;
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: AnpTransport.cs プロジェクト: fdgonthier/TbxUtils
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf   = new byte[AnpMsg.HdrSize];
     inPos   = 0;
 }
コード例 #9
0
ファイル: AnpTransport.cs プロジェクト: fdgonthier/TbxUtils
 public void flushRecv()
 {
     inState = InState.NoMsg;
 }
コード例 #10
0
ファイル: K3pTransport.cs プロジェクト: tmbx/kwm-ng
        public void doXfer()
        {
            bool loop = true;

            while (loop)
            {
                loop = false;

                if (inState == InState.RecvHdr)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop   = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg = new K3pElement();

                            inMsg.ParseType(inBuf);

                            switch (inMsg.Type)
                            {
                            case K3pElement.K3pType.INS:
                                inState = InState.RecvIns;
                                inPos   = 0;
                                inBuf   = new byte[8];
                                break;

                            case K3pElement.K3pType.INT:
                                inState = InState.RecvInt;
                                inPos   = 0;
                                inBuf   = new byte[20];
                                break;

                            case K3pElement.K3pType.STR:
                                inState = InState.RecvStrSize;
                                inBuf   = new byte[20];
                                inPos   = 0;
                                break;
                            }
                        }
                    }
                }

                if (inState == InState.RecvIns)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop   = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg.ParseIns(inBuf);
                            inState = InState.Received;
                        }
                    }
                }

                if (inState == InState.RecvInt || inState == InState.RecvStrSize)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, 1);

                    if (r > 0)
                    {
                        loop   = true;
                        inPos += r;

                        if ((char)inBuf[inPos - 1] == '>')
                        {
                            byte[] tmpInBuf = new byte[inPos];
                            for (int i = 0; i < inPos; i++)
                            {
                                tmpInBuf[i] = inBuf[i];
                            }
                            inMsg.ParseInt(tmpInBuf);
                            if (inState == InState.RecvStrSize)
                            {
                                inState = InState.RecvStr;
                                inBuf   = new byte[inMsg.Int];
                                inPos   = 0;

                                if (inMsg.Int == 0)
                                {
                                    inMsg.ParseStr(inBuf);
                                    inState = InState.Received;
                                }
                            }
                            else
                            {
                                inState = InState.Received;
                            }
                        }
                        else if (inPos == inBuf.Length)
                        {
                            throw new K3pException("Expecting a '>' to end an INT in k3p message");
                        }
                    }
                }

                if (inState == InState.RecvStr)
                {
                    int r = KSocket.SockRead(sock, inBuf, inPos, inBuf.Length - inPos);

                    if (r > 0)
                    {
                        loop   = true;
                        inPos += r;

                        if (inPos == inBuf.Length)
                        {
                            inMsg.ParseStr(inBuf);
                            inState = InState.Received;
                        }
                    }
                }

                if (outState == OutState.Sending)
                {
                    int r = KSocket.SockWrite(sock, outBuf, outPos, outBuf.Length - outPos);

                    if (r > 0)
                    {
                        loop    = true;
                        outPos += r;

                        if (outPos == outBuf.Length)
                        {
                            outState = OutState.NoPacket;
                            break;
                        }
                    }
                }
            }
        }
コード例 #11
0
ファイル: K3pTransport.cs プロジェクト: tmbx/kwm-ng
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf   = new byte[3];
     inPos   = 0;
 }