Beispiel #1
0
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf = new byte[3];
     inPos = 0;
 }
Beispiel #2
0
        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;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        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;
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public void flushRecv()
 {
     inState = InState.NoMsg;
 }
Beispiel #5
0
 public C(InState inState, ExState exState)
 {
     TheInState = inState;
     TheExState = exState;
 }
Beispiel #6
0
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf = new byte[AnpMsg.HdrSize];
     inPos = 0;
 }
Beispiel #7
0
        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;
                        }
                    }
                }
            }
        }
Beispiel #8
0
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf   = new byte[AnpMsg.HdrSize];
     inPos   = 0;
 }
Beispiel #9
0
 public void flushRecv()
 {
     inState = InState.NoMsg;
 }
Beispiel #10
0
        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;
                        }
                    }
                }
            }
        }
Beispiel #11
0
 public void beginRecv()
 {
     inState = InState.RecvHdr;
     inBuf   = new byte[3];
     inPos   = 0;
 }