示例#1
0
文件: Serverlet.cs 项目: zmyer/rDSN
        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);
        }
示例#2
0
文件: Serverlet.cs 项目: zmyer/rDSN
        protected void Reply(RpcWriteStream response)
        {
            Logging.dassert(response.IsFlushed(),
                            "RpcWriteStream must be flushed after write in the same thread");

            Native.dsn_rpc_reply(response.DangerousGetHandle(), ErrorCode.ERR_OK);
        }
示例#3
0
 public SafeTaskHandle ping2(
     string val, 
     pingCallback callback,
     int timeout_milliseconds = 0, 
     int reply_hash = 0,
     int request_hash = 0,
     RpcAddress server = null)
 {
     RpcWriteStream s = new RpcWriteStream(echoHelper.RPC_ECHO_ECHO_PING,timeout_milliseconds, request_hash);
     s.Write(val);
     s.Flush();
     
     return RpcCallAsync2(
                 server != null ? server : _server, 
                 s,
                 this, 
                 (err, rs) => 
                     { 
                         string resp;
                         rs.Read(out resp);
                         callback(err, resp);
                     },
                 reply_hash
                 );
 }       
示例#4
0
文件: RpcStream.cs 项目: whiker/rDSN
 public static void Write(this RpcWriteStream ws, string val)
 {
     using (BinaryWriter writer = new BinaryWriter(ws))
     {
         writer.Write(val);
     }
 }
示例#5
0
 public void ping(
     string val, 
     pingCallback callback,
     int timeout_milliseconds = 0, 
     int reply_thread_hash = 0,
     ulong request_hash = 0,
     RpcAddress server = null)
 {
     var s = new RpcWriteStream(echoHelper.RPC_ECHO_ECHO_PING, timeout_milliseconds, request_hash);
     s.Write(val);
     s.Flush();
     
     RpcCallAsync(
                 server ?? _server, 
                 s,
                 this, 
                 (err, rs) => 
                     { 
                         string resp;
                         rs.Read(out resp);
                         callback(err, resp);
                     },
                 reply_thread_hash
                 );
 }        
示例#6
0
文件: Clientlet.cs 项目: zmyer/rDSN
        //
        // this gives you the task handle so you can wait or cancel
        // the task, with the cost of add/ref the task handle
        //
        public static SafeTaskHandle RpcCallAsync2(
            RpcAddress server,
            RpcWriteStream requestStream,
            Clientlet callbackOwner,
            RpcResponseHandler callback,
            int replyHash = 0
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                            "RpcWriteStream must be flushed after write in the same thread");

            var idx  = GlobalInterOpLookupTable.Put(callback);
            var task = Native.dsn_rpc_create_response_task(
                requestStream.DangerousGetHandle(),
                _c_rpc_response_handler_holder,
                (IntPtr)idx,
                replyHash,
                callbackOwner?.tracker() ?? IntPtr.Zero
                );

            var ret = new SafeTaskHandle(task, idx);

            Native.dsn_rpc_call(server.addr, task);
            return(ret);
        }
示例#7
0
        // no callback
        public static void RpcCallOneWay(
            RpcAddress server,
            RpcWriteStream requestStream
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                            "RpcWriteStream must be flushed after write in the same thread");

            Native.dsn_rpc_call_one_way(server, requestStream.DangerousGetHandle());
        }
示例#8
0
文件: Clientlet.cs 项目: zmyer/rDSN
        public static RpcReadStream RpcCallSync(
            RpcAddress server,
            RpcWriteStream requestStream
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                            "RpcWriteStream must be flushed after write in the same thread");

            var respMsg = Native.dsn_rpc_call_wait(server.addr, requestStream.DangerousGetHandle());

            return(IntPtr.Zero == respMsg ? null : new RpcReadStream(respMsg, true));
        }
示例#9
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);
        }
示例#10
0
        public static void RpcCallAsync(
            RpcAddress server,
            RpcWriteStream requestStream,
            Servicelet callbackOwner,
            RpcResponseHandler callback,
            int replyHash = 0
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                            "RpcWriteStream must be flushed after write in the same thread");

            var        idx  = GlobalInterOpLookupTable.Put(callback);
            dsn_task_t task = Native.dsn_rpc_create_response_task(
                requestStream.DangerousGetHandle(),
                _c_rpc_response_handler_holder,
                (IntPtr)idx,
                replyHash
                );

            Native.dsn_rpc_call(server, task, callbackOwner != null ? callbackOwner.tracker() : IntPtr.Zero);
        }
示例#11
0
 // ---------- call echoHelper.RPC_ECHO_ECHO_PING ------------
 // - synchronous 
 public ErrorCode ping(
     string val, 
     out string resp, 
     int timeout_milliseconds = 0, 
     int hash = 0,
     RpcAddress server = null)
 {
     RpcWriteStream s = new RpcWriteStream(echoHelper.RPC_ECHO_ECHO_PING, timeout_milliseconds, hash);
     s.Write(val);
     s.Flush();
     
     var respStream = RpcCallSync(server != null ? server : _server, s);
     if (null == respStream)
     {
         resp = default(string);
         return ErrorCode.ERR_TIMEOUT;
     }
     else
     {
         respStream.Read(out resp);
         return ErrorCode.ERR_OK;
     }
 }
示例#12
0
文件: Serverlet.cs 项目: zmyer/rDSN
 public RpcReplier(RpcWriteStream respStream, Marshaller marshal)
 {
     _respStream = respStream;
     _marshaller = marshal;
 }
示例#13
0
        public static RpcReadStream RpcCallSync(
            RpcAddress server,
            RpcWriteStream requestStream
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                "RpcWriteStream must be flushed after write in the same thread");

            IntPtr respMsg = Native.dsn_rpc_call_wait(server, requestStream.DangerousGetHandle());
            if (IntPtr.Zero == respMsg)
            {
                return null;
            }
            else
            {
                return new RpcReadStream(respMsg, true);
            }
        }
示例#14
0
        // no callback
        public static void RpcCallOneWay(
            RpcAddress server,
            RpcWriteStream requestStream
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                "RpcWriteStream must be flushed after write in the same thread");

            Native.dsn_rpc_call_one_way(server, requestStream.DangerousGetHandle());
        }
示例#15
0
        //
        // this gives you the task handle so you can wait or cancel
        // the task, with the cost of add/ref the task handle
        //
        public static SafeTaskHandle RpcCallAsync2(
            RpcAddress server,
            RpcWriteStream requestStream,
            Servicelet callbackOwner,
            RpcResponseHandler callback,
            int replyHash = 0
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                "RpcWriteStream must be flushed after write in the same thread");

            var idx = GlobalInterOpLookupTable.Put(callback);
            dsn_task_t task = Native.dsn_rpc_create_response_task(
                requestStream.DangerousGetHandle(),
                _c_rpc_response_handler_holder,
                (IntPtr)idx,
                replyHash
                );

            var ret = new SafeTaskHandle(task);
            Native.dsn_rpc_call(server, task, callbackOwner != null ? callbackOwner.tracker() : IntPtr.Zero);
            return ret;
        }
示例#16
0
文件: Clientlet.cs 项目: ykwd/rDSN
        public static void RpcCallAsync(
            RpcAddress server,
            RpcWriteStream requestStream,
            Clientlet callbackOwner,
            RpcResponseHandler callback,
            int replyHash = 0
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                "RpcWriteStream must be flushed after write in the same thread");

            var idx = GlobalInterOpLookupTable.Put(callback);
            var task = Native.dsn_rpc_create_response_task(
                requestStream.DangerousGetHandle(),
                _c_rpc_response_handler_holder, 
                (IntPtr)idx, 
                replyHash,
                callbackOwner?.tracker() ?? IntPtr.Zero
                );
            Native.dsn_rpc_call(server.addr, task);
        }