コード例 #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()));
            }
        }
コード例 #2
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));
            }
        }