From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../thrift/contrib/zeromq/csharp/TZmqClient.cs | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/jaegertracing/thrift/contrib/zeromq/csharp/TZmqClient.cs (limited to 'src/jaegertracing/thrift/contrib/zeromq/csharp/TZmqClient.cs') diff --git a/src/jaegertracing/thrift/contrib/zeromq/csharp/TZmqClient.cs b/src/jaegertracing/thrift/contrib/zeromq/csharp/TZmqClient.cs new file mode 100644 index 000000000..e9ab5166a --- /dev/null +++ b/src/jaegertracing/thrift/contrib/zeromq/csharp/TZmqClient.cs @@ -0,0 +1,78 @@ +using System; +using ZMQ; +using System.IO; +using Thrift.Transport; + +namespace ZmqClient +{ + public class TZmqClient : TTransport + { + Socket _sock; + String _endpoint; + MemoryStream _wbuf = new MemoryStream (); + MemoryStream _rbuf = new MemoryStream (); + + void debug (string msg) + { + //Uncomment to enable debug +// Console.WriteLine (msg); + } + + public TZmqClient (Context ctx, String endpoint, SocketType sockType) + { + _sock = ctx.Socket (sockType); + _endpoint = endpoint; + } + + public override void Open () + { + _sock.Connect (_endpoint); + } + + public override void Close () + { + throw new NotImplementedException (); + } + + public override bool IsOpen { + get { + throw new NotImplementedException (); + } + } + + public override int Read (byte[] buf, int off, int len) + { + debug ("Client_Read"); + if (off != 0 || len != buf.Length) + throw new NotImplementedException (); + + if (_rbuf.Length == 0) { + //Fill the Buffer with the complete ZMQ Message which needs to be(?!) the complete Thrift response + debug ("Client_Read Filling buffer.."); + byte[] tmpBuf = _sock.Recv (); + debug (string.Format("Client_Read filled with {0}b",tmpBuf.Length)); + _rbuf.Write (tmpBuf, 0, tmpBuf.Length); + _rbuf.Position = 0; //For reading + } + int ret = _rbuf.Read (buf, 0, len); + if (_rbuf.Length == _rbuf.Position) //Finished reading + _rbuf.SetLength (0); + debug (string.Format ("Client_Read return {0}b, remaining {1}b", ret, _rbuf.Length - _rbuf.Position)); + return ret; + } + + public override void Write (byte[] buf, int off, int len) + { + debug ("Client_Write"); + _wbuf.Write (buf, off, len); + } + + public override void Flush () + { + debug ("Client_Flush"); + _sock.Send (_wbuf.GetBuffer ()); + _wbuf = new MemoryStream (); + } + } +} + -- cgit v1.2.3