Exemplo n.º 1
0
        protected bool RegisterRpcHandler(TaskCode code, string name, RpcRequestHandler handler, UInt64 gpid)
        {
            dsn_rpc_request_handler_t cb = (req, param) =>
            {
                // if handler synchnously processes the incoming request
                // we don't need to add_ref and set owner to true
                // in folloiwng two stmts
                // however, we don't know so we do as follows
                Native.dsn_msg_add_ref(req); // released by RpcReadStream
                var rms = new RpcReadStream(req, true);

                var wms = new RpcWriteStream(Native.dsn_msg_create_response(req));
                handler(rms, wms);
            };

            bool r = Native.dsn_rpc_register_handler(code, name, cb, IntPtr.Zero, gpid);

            Logging.dassert(r, "rpc handler registration failed for " + code.ToString());

            lock (_handlers)
            {
                _handlers.Add(code, cb);
            }
            return(true);
        }
Exemplo n.º 2
0
 public static void Read(this RpcReadStream rs, out string val)
 {
     using (BinaryReader reader = new BinaryReader(rs))
     {
         val = reader.ReadString();
     }
 }
Exemplo n.º 3
0
 public static void Read(this RpcReadStream rs, out bool val)
 {
     using (BinaryReader reader = new BinaryReader(rs))
     {
         val = reader.ReadBoolean();
     }
 }
Exemplo n.º 4
0
        static void c_rpc_response_handler(int err, IntPtr reqc, IntPtr respc, IntPtr h)
        {
            int idx2 = (int)h;
            var hr   = GlobalInterOpLookupTable.GetRelease(idx2) as RpcResponseHandler;

            if (err == 0)
            {
                var rms = new RpcReadStream(respc, false);
                hr(new ErrorCode(err), rms);
            }
            else
            {
                hr(new ErrorCode(err), null);
            }
        }
Exemplo n.º 5
0
        protected bool RegisterRpcHandler(TaskCode code, string name, RpcRequestHandlerOneWay handler, UInt64 gpid)
        {
            dsn_rpc_request_handler_t cb = (req, param) =>
            {
                var rms = new RpcReadStream(req, false);
                handler(rms);
            };

            bool r = Native.dsn_rpc_register_handler(code, name, cb, IntPtr.Zero, gpid);

            Logging.dassert(r, "rpc handler registration failed for " + code.ToString());

            lock (_handlers)
            {
                _handlers.Add(code, cb);
            }
            return(r);
        }
Exemplo n.º 6
0
        protected bool RegisterRpcHandler(TaskCode code, string name, RpcRequestHandler handler)
        {
            dsn_rpc_request_handler_t cb = (dsn_message_t req, IntPtr param) =>
            {
                RpcReadStream  rms = new RpcReadStream(req, false);
                RpcWriteStream wms = new RpcWriteStream(Native.dsn_msg_create_response(req), false);
                handler(rms, wms);
            };

            bool r = Native.dsn_rpc_register_handler(code, name, cb, IntPtr.Zero);

            Logging.dassert(r, "rpc handler registration failed for " + code.ToString());

            lock (_handlers)
            {
                _handlers.Add(code, cb);
            }
            return(true);
        }
Exemplo n.º 7
0
        static void c_rpc_response_handler(int err, IntPtr reqc, IntPtr respc, IntPtr h)
        {
            int idx2 = (int)h;
            var hr = GlobalInterOpLookupTable.GetRelease(idx2) as RpcResponseHandler;

            if (err == 0)
            {
                var rms = new RpcReadStream(respc, false);
                hr(new ErrorCode(err), rms);
            }
            else
            {
                hr(new ErrorCode(err), null);
            }
        }