Example #1
0
        private void connect(
            IncomingMessageDispatchCallback incomingMessageDispatchCallback, IOWorker ioWorker)
        {
            if (NetworkUtils.protocolIsTcp(target))
            {
                connection = NetworkUtils.connectTcp(target, options);
            }
            else if (NetworkUtils.protocolIsTcps(target))
            {
                connection = NetworkUtils.connectTcps(target, options, ioWorker);

                // additionally, instruct I/O Worker that blocking sockets
                // are the only ones that should be acted upon

                ioWorker.UseBlockingChannelsOnly();
            }
            else if (NetworkUtils.protocolIsUdp(target))
            {
                connection = NetworkUtils.createUdp(target, options);
            }
            else if (target.Equals("null"))
            {
                // do nothing - this protocol is used for testing only
                channelWriter = new ChannelWriter(
                    null, null, null, LogEventArgs.LogLevel.LOW);
            }
            else
            {
                throw new BadProtocolException(target);
            }

            createReaderWriter(incomingMessageDispatchCallback);
        }
Example #2
0
        public ChannelReader(
            NetworkUtils.TransportChannel connection,
            IncomingMessageDispatchCallback incomingMessageDispatchCallback,
            string target, Options options,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection = connection;
            this.incomingMessageDispatchCallback =
                incomingMessageDispatchCallback;
            this.target      = target;
            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            incomingFrames = new Dictionary <int, IncomingMessageFrames>();

            if (connection != null)
            {
                if (connection.connectedChannel != null || connection.ssl != null)
                {
                    // stream-based connection
                    headerBuffer = new MemoryStream(Frame.FRAME_HEADER_SIZE);
                    setReadingFrameHeaderState();
                }
                else
                {
                    // datagram-based connection
                    wholeFrameBuffer = new byte[options.udpFrameSize];
                    state            = InputState.READING_WHOLE_FRAMES;
                }
            }

            deliverAsRawBinary = options.deliverAsRawBinary;
        }
Example #3
0
        public ChannelReader(
            NetworkUtils.TransportChannel connection, 
            IncomingMessageDispatchCallback incomingMessageDispatchCallback, 
            string target, Options options, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection = connection;
            this.incomingMessageDispatchCallback =
                incomingMessageDispatchCallback;
            this.target = target;
            this.logCallback = logCallback;
            this.logLevel = logLevel;

            incomingFrames = new Dictionary<int, IncomingMessageFrames>();

            if (connection != null)
            {
                if (connection.connectedChannel != null)
                {
                // stream-based connection
                    headerBuffer = new MemoryStream(Frame.FRAME_HEADER_SIZE);
                    setReadingFrameHeaderState();
                }
                else
                {
                // datagram-based connection
                    wholeFrameBuffer = new byte[options.udpFrameSize];
                    state = InputState.READING_WHOLE_FRAMES;
                }
            }

            deliverAsRawBinary = options.deliverAsRawBinary;
        }
Example #4
0
        internal ChannelWriter(
            NetworkUtils.TransportChannel connection, string target, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection = connection;
            this.target = target;
            this.logCallback = logCallback;
            this.logLevel = logLevel;

            outgoingFrames = new List<OutgoingFrame>();
        }
Example #5
0
        internal ChannelWriter(
            NetworkUtils.TransportChannel connection, string target,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection  = connection;
            this.target      = target;
            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            outgoingFrames = new List <OutgoingFrame>();
        }
Example #6
0
        // used by listener when accepting new connections
        internal Channel(Socket acceptedChannel, string sourceTarget,
                         IncomingMessageDispatchCallback incomingMessageDispatchCallback,
                         Options options, LogCallback logCallback,
                         LogEventArgs.LogLevel logLevel)
        {
            this.target  = sourceTarget;
            this.options = options;

            this.connection =
                new NetworkUtils.TransportChannel(acceptedChannel);

            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            createReaderWriter(incomingMessageDispatchCallback);

            if (logCallback != null)
            {
                logCallback.Log(LogEventArgs.LogLevel.LOW,
                                "Accepted connection from " + target);
            }
        }
Example #7
0
        // used by listener when accepting new connections
        internal Channel(Socket acceptedChannel, string sourceTarget, 
            IncomingMessageDispatchCallback incomingMessageDispatchCallback, 
            Options options, LogCallback logCallback, 
            LogEventArgs.LogLevel logLevel)
        {
            this.target = sourceTarget;
            this.options = options;

            this.connection =
                new NetworkUtils.TransportChannel(acceptedChannel);

            this.logCallback = logCallback;
            this.logLevel = logLevel;

            createReaderWriter(incomingMessageDispatchCallback);

            if (logCallback != null)
            {
                logCallback.Log(LogEventArgs.LogLevel.LOW,
                    "Accepted connection from " + target);
            }
        }
Example #8
0
        public virtual void close()
        {
            if (connection != null)
            {
                try
                {
                    connection.close();
                }
                catch (Exception)
                {
                    // ignore
                }
                connection = null;

                channelWriter.notifyCancellation();

                if (logCallback != null)
                {
                    logCallback.Log(LogEventArgs.LogLevel.LOW,
                                    "Closed connection to " + target);
                }
            }
        }
Example #9
0
        private void connect(
            IncomingMessageDispatchCallback incomingMessageDispatchCallback)
        {
            if (NetworkUtils.protocolIsTcp(target))
            {
                connection = NetworkUtils.connectTcp(target, options);
            }
            else if (NetworkUtils.protocolIsUdp(target))
            {
                connection = NetworkUtils.createUdp(target, options);
            }
            else if (target.Equals("null"))
            {
            // do nothing - this protocol is used for testing only
                channelWriter = new ChannelWriter(
                    null, null, null, LogEventArgs.LogLevel.LOW);
            }
            else
            {
                throw new BadProtocolException(target);
            }

            createReaderWriter(incomingMessageDispatchCallback);
        }
Example #10
0
        public virtual void close()
        {
            if (connection != null)
            {
                try
                {
                    connection.close();
                }
                catch(Exception)
                {
                // ignore
                }
                connection = null;

                channelWriter.notifyCancellation();

                if (logCallback != null)
                {
                    logCallback.Log(LogEventArgs.LogLevel.LOW,
                        "Closed connection to " + target);
                }
            }
        }