Example #1
0
        public void ServeInput(IAsyncResult ar)
        {
            if (!client.Connected)
            {
                CloseSession();
            }
            int readed = client.EndReceive(ar);

            // try to decode data
            IStyxMessage result = new StyxErrorMessage("Unknown message");
            StyxMessage message = new StyxMessage();
            message.SetBinary(iobuf);
            try
            {
                switch (message.Type)
                {
                    case StyxMessage.MessageType.Tversion:
                        result = HandleVersion((StyxVersionMessage)message.GetMessage());
                        break;
                    case StyxMessage.MessageType.Tauth:
                        {
                            StyxAuthMessage msg = new StyxAuthMessage();
                            msg.SetBinary(iobuf);
                            result = HandleAuth(msg);
                        }
                        break;
                    case StyxMessage.MessageType.Tattach:
                        result = HandleAttach((StyxAttachMessage)message.GetMessage());
                        break;
                    case StyxMessage.MessageType.Tstat:
                        result = HandleStat((StyxStatMessage)message.GetMessage());
                        break;
                    case StyxMessage.MessageType.Twalk:
                        result = HandleWalk((StyxWalkMessage)message.GetMessage());
                        break;
                    case StyxMessage.MessageType.Tclunk:
                        result = HandleClunk((StyxClunkMessage)message.GetMessage());
                        break;
                    case StyxMessage.MessageType.Topen:
                        result = HandleOpen((StyxOpenMessage)message.GetMessage());
                        break;
                    case StyxMessage.MessageType.Tread:
                        result = HandleRead((StyxReadMessage)message.GetMessage());
                        break;
                }
            }
            catch (Exception err)
            {
                result = new StyxErrorMessage(err.ToString());
            }
            // continue receiving
            client.BeginReceive(iobuf, 0, (int)iobuf_size, SocketFlags.None,
                new AsyncCallback(ServeInput), null);

            if ( result != null )
            {
                result.SetTag( message.Tag );
                PushToQueue(result);
            }
        }
Example #2
0
 /// <summary>
 /// message decoder
 /// </summary>
 /// <param name="data"></param>
 public new void SetBinary(byte[] data)
 {
     base.SetBinary(data);
     if (this.Type == MessageType.Rread)
     {
         SetRBinary(data);
         return;
     }
     if (this.Type == MessageType.Tread)
     {
         SetTBinary(data);
         return;
     }
     if (this.Type == MessageType.Rerror)
     {
         StyxErrorMessage error = new StyxErrorMessage();
         error.SetBinary(data);
         throw new StyxErrorMessageException(error);
         return;
     }
     throw new Exception("Incorrect message type");
 }
        /// <summary>
        /// Remove message decoder
        /// </summary>
        /// <exception cref="StyxErrorMessageException">Throws StyxErrorMessageException when Rerror received</exception>
        /// <exception cref="Exception">Throws Exception when unsupported message received</exception>
        public new void SetBinary(byte[] data)
        {
            base.SetBinary(data);
            if (this.Type == MessageType.Rremove)
                return; // ok, Rremove have no extra fields, so we can just return

            if (this.Type == MessageType.Rerror)
            {
                StyxErrorMessage error = new StyxErrorMessage();
                error.SetBinary(data);
                throw new StyxErrorMessageException(error);
                return;
            }
            throw new Exception("Incorrect message type");
        }
        /// <summary>
        /// message decoder
        /// </summary>
        /// <param name="data"></param>
        public new void SetBinary(byte[] data)
        {
            base.SetBinary(data);
            if (this.Type == MessageType.Rerror)
            {
                StyxErrorMessage error = new StyxErrorMessage();
                error.SetBinary(data);
                throw new StyxErrorMessageException(error);
                return;
            }
            if ((this.Type != MessageType.Tversion) && (this.Type != MessageType.Rversion))
                throw new Exception("Incorrect message type");
            int pos = (int)base.GetBinarySize();
            this.max_packet_size = BitConverter.ToUInt32(data, pos);
            pos += sizeof(uint);
            ushort protocol_size = BitConverter.ToUInt16(data, pos);
            pos += sizeof(ushort);

            protocol_version = Encoding.UTF8.GetString(data, pos, protocol_size);
        }