public SafeTaskHandle ping2( 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(); return(RpcCallAsync2( server ?? _server, s, this, (err, rs) => { string resp; rs.Read(out resp); callback(err, resp); }, reply_thread_hash )); }
public void OnTimer2EchoCallback(ErrorCode err, RpcReadStream response) { if (err == ErrorCode.ERR_OK) { string v; response.Read(out v); //Logging.dassert(v == "hi, this is timer2 echo", //"incorrect responsed value"); } var c = ++_count_timer2; if (c % 10000 == 0) { var gap = DateTime.Now - _last_ts; _last_ts = DateTime.Now; Console.WriteLine("Timer2: Cost {0} ms for {1} tasks", gap.TotalMilliseconds, _count_timer2); _count_timer1 = 0; //cancel_all_pending_tasks(); } string cs = new string('v', 1024 * 1024); RpcWriteStream s = new RpcWriteStream(EchoClientApp.RPC_ECHO, 1000, 0); s.Write(cs); s.Flush(); RpcCallAsync(_server, s, this, this.OnTimer2EchoCallback, 0); }
// ---------- call echoHelper.RPC_ECHO_ECHO_PING ------------ // - synchronous public ErrorCode ping( string val, out string resp, int timeout_milliseconds = 0, ulong hash = 0, RpcAddress server = null) { var s = new RpcWriteStream(echoHelper.RPC_ECHO_ECHO_PING, timeout_milliseconds, hash); s.Write(val); s.Flush(); var respStream = RpcCallSync(server ?? _server, s); if (null == respStream) { resp = default(string); return(ErrorCode.ERR_TIMEOUT); } else { respStream.Read(out resp); return(ErrorCode.ERR_OK); } }
public void ping( string val, pingCallback callback, int timeout_milliseconds = 0, int reply_thread_hash = 0, int thread_hash = 0, ulong partition_hash = 0, RpcAddress server = null) { var s = new RpcWriteStream(echoHelper.RPC_ECHO_ECHO_PING, timeout_milliseconds, thread_hash, partition_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 void OnEcho(RpcReadStream request, RpcWriteStream response) { string v; request.Read(out v); response.Write(v); response.Flush(); Reply(response); }
public void OnTimer2(object param) { //Console.WriteLine("on_timer2 " + param.ToString()); RpcWriteStream s = new RpcWriteStream(EchoClientApp.RPC_ECHO, 1000, 0); s.Write("hi, this is timer2 echo"); s.Flush(); RpcCallAsync(_server, s, this, this.OnTimer2EchoCallback, 0); }
// all service handlers to be implemented further // RPC_ECHO_ECHO_PING private void OnpingInternal(RpcReadStream request, RpcWriteStream response) { string val; try { request.Read(out val); } catch (Exception) { // TODO: error handling return; } Onping(val, new RpcReplier <string>(response, (s, r) => { s.Write(r); s.Flush(); })); }
public static void Write(this RpcWriteStream s, string v) { var bytes = Encoding.UTF8.GetBytes(v); s.Write(bytes, 0, bytes.Length); }