public ServiceApp() { _started = false; _address = new RpcAddress(); Native.dsn_address_get_invalid(out _address.addr); _gch = GCHandle.Alloc(this); }
public static void Read(this Stream rs, out RpcAddress val) { using (var reader = new BinaryReader(rs)) { val = new RpcAddress(reader.ReadUInt64()); } }
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 ); }
public static void Write(this Stream ws, RpcAddress val) { using (var writer = new BinaryWriter(ws)) { writer.Write(val); } }
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 ); }
public override ErrorCode Start(string[] args) { if (args.Length < 2) { throw new Exception("wrong usage: server-host server-port or service-url"); } if (args.Length >= 3) { _server.addr = Native.dsn_address_build(args[1], ushort.Parse(args[2])); } else { if (args[1].Contains("dsn://")) _server = new RpcAddress(args[1]); else { var addrs = args[1].Split(new char[] { ':'}, StringSplitOptions.RemoveEmptyEntries); _server.addr = Native.dsn_address_build(addrs[0], ushort.Parse(addrs[1])); } } _echoClient = new echoClient(_server); _timer = Clientlet.CallAsync2(echoHelper.LPC_ECHO_TEST_TIMER, null, this.OnTestTimer, 0, 0, 1000); return ErrorCode.ERR_OK; }
// // 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); }
// 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()); }
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)); }
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); }
// ---------- 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; } }
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); } }
// // 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; }
public echoClient(RpcAddress server) { _server = server; }
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); }
public ServiceApp() { _started = false; _address = new RpcAddress(); _gch = GCHandle.Alloc(this); }