Пример #1
0
            public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
            {
                // Get handle from create response
                ChannelBuffer buf = (ChannelBuffer)e.GetMessage();
                XDR           rsp = new XDR(buf.Array());

                if (rsp.GetBytes().Length == 0)
                {
                    Log.Info("rsp length is zero, why?");
                    return;
                }
                Log.Info("rsp length=" + rsp.GetBytes().Length);
                RpcReply reply = RpcReply.Read(rsp);
                int      xid   = reply.GetXid();

                // Only process the create response
                if (xid != unchecked ((int)(0x8000004c)))
                {
                    return;
                }
                int status = rsp.ReadInt();

                if (status != Nfs3Status.Nfs3Ok)
                {
                    Log.Error("Create failed, status =" + status);
                    return;
                }
                Log.Info("Create succeeded");
                rsp.ReadBoolean();
                // value follow
                handle = new FileHandle();
                handle.Deserialize(rsp);
                channel = e.GetChannel();
            }
Пример #2
0
 // TODO: convert this to Junit
 internal static void TestRequest(XDR request, XDR request2)
 {
     try
     {
         DatagramSocket clientSocket = new DatagramSocket();
         IPAddress      IPAddress    = Sharpen.Extensions.GetAddressByName("localhost");
         byte[]         sendData     = request.GetBytes();
         byte[]         receiveData  = new byte[65535];
         DatagramPacket sendPacket   = new DatagramPacket(sendData, sendData.Length, IPAddress
                                                          , Nfs3Constant.SunRpcbind);
         clientSocket.Send(sendPacket);
         DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.Length
                                                           );
         clientSocket.Receive(receivePacket);
         clientSocket.Close();
     }
     catch (UnknownHostException)
     {
         System.Console.Error.WriteLine("Don't know about host: localhost.");
         System.Environment.Exit(1);
     }
     catch (IOException)
     {
         System.Console.Error.WriteLine("Couldn't get I/O for " + "the connection to: localhost."
                                        );
         System.Environment.Exit(1);
     }
 }
Пример #3
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestRegistration()
        {
            XDR req = new XDR();

            RpcCall.GetInstance(++xid, RpcProgramPortmap.Program, RpcProgramPortmap.Version,
                                RpcProgramPortmap.PmapprocSet, new CredentialsNone(), new VerifierNone()).Write(
                req);
            PortmapMapping sent = new PortmapMapping(90000, 1, PortmapMapping.TransportTcp, 1234
                                                     );

            sent.Serialize(req);
            byte[]         reqBuf = req.GetBytes();
            DatagramSocket s      = new DatagramSocket();
            DatagramPacket p      = new DatagramPacket(reqBuf, reqBuf.Length, pm.GetUdpServerLoAddress
                                                           ());

            try
            {
                s.Send(p);
            }
            finally
            {
                s.Close();
            }
            // Give the server a chance to process the request
            Thread.Sleep(100);
            bool found = false;
            IDictionary <string, PortmapMapping> map = (IDictionary <string, PortmapMapping>)Whitebox
                                                       .GetInternalState(pm.GetHandler(), "map");

            foreach (PortmapMapping m in map.Values)
            {
                if (m.GetPort() == sent.GetPort() && PortmapMapping.Key(m).Equals(PortmapMapping.
                                                                                  Key(sent)))
                {
                    found = true;
                    break;
                }
            }
            Assert.True("Registration failed", found);
        }