Ejemplo n.º 1
0
        public static NngResult <IRepReqAsyncContext <T> > Create(IMessageFactory <T> factory, IRepSocket socket)
        {
            var context = new RepAsyncCtx <T> {
                Factory = factory, socket = socket
            };
            var res = context.InitAio();

            if (res.IsOk())
            {
                //TODO: when get default interface methods in C#8 move this to ICtx
                var ctx = NngCtx.Create(socket);
                if (ctx.IsOk())
                {
                    context.Ctx = ctx.Ok();
                    // Start receive loop
                    context.AioCallback(IntPtr.Zero);
                    return(NngResult <IRepReqAsyncContext <T> > .Ok(context));
                }
                return(NngResult <IRepReqAsyncContext <T> > .Err(ctx.Err()));
            }
            else
            {
                return(NngResult <IRepReqAsyncContext <T> > .Fail(res.Err()));
            }
        }
Ejemplo n.º 2
0
 public static void TrySetNngError <T>(this CancellationTokenTaskSource <NngResult <T> > socket, int error)
 {
     if (error == 0)
     {
         return;
     }
     socket.TrySetResult(NngResult <T> .Fail(error));
 }
Ejemplo n.º 3
0
 public static void TrySetNngError <T>(this TaskCompletionSource <NngResult <T> > socket, int error)
 {
     if (error == 0)
     {
         return;
     }
     socket.TrySetResult(NngResult <T> .Fail(error));
 }
Ejemplo n.º 4
0
        public static NngResult <INngCtx> Create(ISocket socket)
        {
            var res = nng_ctx_open(out var ctx, socket.NngSocket);

            if (res != 0)
            {
                return(NngResult <INngCtx> .Fail(res));
            }
            return(NngResult <INngCtx> .Ok(new AsyncCtx { NngCtx = ctx }));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a surveyor socket
        /// </summary>
        /// <returns>The open.</returns>
        public static NngResult <ISurveyorSocket> Open()
        {
            int res = nng_surveyor0_open(out var socket);

            if (res != 0)
            {
                return(NngResult <ISurveyorSocket> .Fail(res));
            }
            return(NngResult <ISurveyorSocket> .Ok(new SurveyorSocket { NngSocket = socket }));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create a respondent socket
        /// </summary>
        /// <returns>The open.</returns>
        public static NngResult <IRespondentSocket> Open()
        {
            int res = nng_respondent0_open(out var socket);

            if (res != 0)
            {
                return(NngResult <IRespondentSocket> .Fail(res));
            }
            return(NngResult <IRespondentSocket> .Ok(new RespondentSocket { NngSocket = socket }));
        }
Ejemplo n.º 7
0
        public static NngResult <INngCtx> Create(INngSocket socket)
        {
            var res = nng_ctx_open(out var ctx, socket.NativeNngStruct);

            if (res != 0)
            {
                return(NngResult <INngCtx> .Fail(res));
            }
            return(NngResult <INngCtx> .Ok(new NngCtx { NativeNngStruct = ctx }));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create a pair socket
        /// </summary>
        /// <returns>The open.</returns>
        public static NngResult <IPairSocket> Open()
        {
            int res = nng_pair1_open(out var socket);

            if (res != 0)
            {
                return(NngResult <IPairSocket> .Fail(res));
            }
            return(NngResult <IPairSocket> .Ok(new Pair1Socket { NngSocket = socket }));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Create a reply socket
        /// </summary>
        /// <returns>The open.</returns>
        public static INngResult <IRepSocket> Open()
        {
            var res = nng_rep0_open(out var socket);

            if (res != 0)
            {
                return(NngResult.Fail <IRepSocket>(res));
            }
            return(NngResult.Ok <IRepSocket>(new RepSocket {
                NngSocket = socket
            }));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create a publish socket
        /// </summary>
        /// <returns>The open.</returns>
        public static INngResult <IPubSocket> Open()
        {
            int res = nng_pub0_open(out var socket);

            if (res != 0)
            {
                return(NngResult.Fail <IPubSocket>(res));
            }
            return(NngResult.Ok <IPubSocket>(new PubSocket {
                NngSocket = socket
            }));
        }
Ejemplo n.º 11
0
        public static NngResult <INngStream> From(INngAio aio)
        {
            var ptr = aio.GetOutput(0);

            if (ptr == IntPtr.Zero)
            {
                return(NngResult <INngStream> .Fail(-1));
            }
            else
            {
                var stream = new Stream {
                    stream = new nng_stream(ptr)
                };
                return(NngResult <INngStream> .Ok(stream));
            }
        }
Ejemplo n.º 12
0
        public static INngResult <IRepReqAsyncContext <T> > Create(IMessageFactory <T> factory, ISocket socket)
        {
            var ctx = new RepAsyncCtx <T>();
            var res = ctx.Init(factory, socket, ctx.callback);

            if (res == 0)
            {
                // Start receive loop
                ctx.callback(IntPtr.Zero);
                return(NngResult.Ok <IRepReqAsyncContext <T> >(ctx));
            }
            else
            {
                return(NngResult.Fail <IRepReqAsyncContext <T> >(res));
            }
        }
Ejemplo n.º 13
0
        public static NngResult <IReqRepAsyncContext <T> > Create(IMessageFactory <T> factory, ISocket socket)
        {
            var context = new ReqAsyncCtx <T> {
                Factory = factory, Socket = socket
            };
            var res = context.InitAio();

            if (res == 0)
            {
                //TODO: when get default interface methods in C#8 move this to ICtx
                var ctx = AsyncCtx.Create(socket);
                if (ctx.IsOk())
                {
                    context.Ctx = ctx.Ok();
                    return(NngResult <IReqRepAsyncContext <T> > .Ok(context));
                }
                return(NngResult <IReqRepAsyncContext <T> > .Err(ctx.Err()));
            }
            return(NngResult <IReqRepAsyncContext <T> > .Fail(res));
        }
Ejemplo n.º 14
0
        public static NngResult <ISurveyorAsyncContext <T> > Create(IMessageFactory <T> factory, ISendRecvSocket socket)
        {
            var context = new SurveyAsyncContext <T> {
                Factory = factory, socket = socket
            };
            var res = context.InitAio();

            if (res.IsOk())
            {
                //TODO: when get default interface methods in C#8 move this to ICtx
                var ctx = NngCtx.Create(socket);
                if (ctx.IsOk())
                {
                    context.Ctx = ctx.Ok();
                    return(NngResult <ISurveyorAsyncContext <T> > .Ok(context));
                }
                return(NngResult <ISurveyorAsyncContext <T> > .Err(ctx.Err()));
            }
            else
            {
                return(NngResult <ISurveyorAsyncContext <T> > .Fail(res.Err()));
            }
        }
Ejemplo n.º 15
0
 public static void TrySetNngError <T>(this CancellationTokenTaskSource <NngResult <T> > socket, NngErrno error)
 {
     socket.TrySetResult(NngResult <T> .Fail(error));
 }
Ejemplo n.º 16
0
 public static void TrySetNngError <T>(this TaskCompletionSource <NngResult <T> > socket, NngErrno error)
 {
     socket.TrySetResult(NngResult <T> .Fail(error));
 }