Пример #1
0
        public static bool TryReceiveString(this IRoutingIdSocket socket, TimeSpan timeout,
                                            Encoding encoding, out uint routingId, [NotNullWhen(returnValue: true)] out string?str,
                                            CancellationToken cancellationToken = default)
        {
            var msg = new Msg();

            msg.InitEmpty();

            if (socket.TryReceive(ref msg, timeout, cancellationToken))
            {
                routingId = msg.RoutingId;

                try
                {
                    str = msg.Size > 0
                        ? msg.GetString(encoding)
                        : string.Empty;
                    return(true);
                }
                finally
                {
                    msg.Close();
                }
            }

            str       = null;
            routingId = 0;
            msg.Close();
            return(false);
        }
Пример #2
0
        public static bool TryReceiveBytes(this IRoutingIdSocket socket, TimeSpan timeout, out uint routingId,
                                           [NotNullWhen(returnValue: true)] out byte[]?bytes, CancellationToken cancellationToken = default)
        {
            var msg = new Msg();

            msg.InitEmpty();

            if (!socket.TryReceive(ref msg, timeout, cancellationToken))
            {
                msg.Close();
                bytes     = null;
                routingId = 0;
                return(false);
            }

            bytes     = msg.CloneData();
            routingId = msg.RoutingId;

            msg.Close();
            return(true);
        }