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); } }
private IStyxMessage HandleAuth(StyxAuthMessage message) { StyxFileSystemInterface fitem; server.Auth(message.AFid, message.UserName, message.MountPoint, out fitem); RegisterFID(message.AFid, fitem); return new StyxAuthMessage(message.Tag, fitem.GetQID()); }