Ejemplo n.º 1
0
        public void Close(ushort code, string reason)
        {
            if (_state == SocketStat.Closed)
            {
                return;
            }

            if (_state == SocketStat.Closing)
            {
                return;
            }

            _state       = SocketStat.Closed;
            _closeCode   = code;
            _closeReason = reason;

            if (_closeCode >= 1000 && !string.IsNullOrEmpty(_closeReason))
            {
                var buf    = new BufferData();
                var writer = new BufferWriter(buf);
                writer.WriteUInt16(code);
                writer.WriteString(reason);
                writer.Flush();
                SendFrame(0x08, _sendingMaskMode && !_isserver, true, buf);
            }
            else
            {
                SendFrame(0x08, _sendingMaskMode && !_isserver, true, null);
            }
        }
Ejemplo n.º 2
0
        private byte[] writeSetupMetadata()
        {
            var setup  = new ArrayBufferWriter <byte>();
            var writer = new BufferWriter(setup, null);

            new Frames.DestinationSetup(ipAddress, group, accessKey, new ReadOnlySequence <byte>(accessToken), connectionId, additionalFlags, tags).Write(writer);
            writer.Flush();

            return(setup.WrittenMemory.ToArray());
        }
Ejemplo n.º 3
0
        public RSocket.RSocket Shard(string group, ReadOnlySequence <byte> shardKey, SortedDictionary <string, string> tags = default)
        {
            return(new BrokerSocket(client, metadata =>
            {
                var bytes = new ArrayBufferWriter <byte>();
                var writer = new BufferWriter(bytes, null);
                new Frames.Shard(group, metadata, shardKey, tags).Write(writer);
                writer.Flush();

                return new ReadOnlySequence <byte>(bytes.WrittenMemory);
            }));
        }