Пример #1
0
 protected Channel CreateChannel(string path, ChannelMode mode)
 {
     Channel channel = new Channel();
     bindChannel(channel);
     channel.Connect(URL + "/" + path, mode);
     return channel;
 }
Пример #2
0
        protected override void Data(Channel channel, ChannelDataEventArgs e)
        {
			Assert.IsTrue(Compare(payload, e.Payload));
            if (++count == 1000) {
                channel.Close();
            }
        }
Пример #3
0
        internal static Connection create (Channel channel, Uri uri)
        {
            Connection connection = null;
            string connurl = null;

            connurl = uri.Scheme + "://" + uri.Host + ":" + uri.Port;

            if (_connections.ContainsKey(connurl)) {
                List<Connection> all = _connections[connurl];
                foreach (Connection conn in all) {
                    if (conn._channels.ContainsKey(uri.AbsolutePath) == false) {
                        connection = conn;
                        break;
                    }
                }
                
            }

            if (connection == null) {
                connection = new Connection(connurl, uri);

                if (_connections.ContainsKey(connurl) == false) {
                    _connections.Add(connurl, new List<Connection>());
                }

                _connections[connurl].Add(connection);
            }

            connection.allocChannel(channel);

            return connection;
        }
Пример #4
0
        public void TestWithMessage()
        {
            Timeout(5000);

            open = CreateChannel("test-token?TOKEN", ChannelMode.ReadWrite);

            Wait();
        }
Пример #5
0
        public void TestWithDeny()
        {
            Timeout(5000);

            deny = CreateChannel("open-deny", ChannelMode.ReadWrite);

            Wait();
        }
Пример #6
0
 protected override void Closed(Channel channel, ChannelCloseEventArgs e)
 {
     Assert.IsTrue(e.WasClean);
     Assert.IsFalse(e.WasDenied);
     
     if (channel == emitListener) {
         Done();
     }
 }
Пример #7
0
        public void Test()
        {
            Timeout(10000);

            emitListener = CreateChannel("", ChannelMode.Read);

            closingChannel = CreateChannel("emit-back-on-close",
                                           ChannelMode.Read);

            Wait();
        }
Пример #8
0
        public static void Main(string[] args) 
        {
            channel = new Channel();

            channel.Connect("http://public.hydna.net/", ChannelMode.ReadWrite);

            channel.Open += c_Open;
            channel.Data += c_Data;
            channel.Closed += c_Closed;

            while (channel != null)
                Thread.SpinWait(1);
        }
Пример #9
0
     protected override void Closed(Channel channel, ChannelCloseEventArgs e)
     {
         if (channel == deny) {
             Assert.IsTrue(e.WasDenied);
             Assert.IsFalse(e.WasClean);
 			Assert.AreEqual(e.Text, "DENIED");
         }
         else {
             Assert.IsTrue(e.WasClean);
             Assert.IsFalse(e.WasDenied);
         }
         
         Done();
     }
Пример #10
0
        protected override void Open(Channel channel, ChannelEventArgs e)
        {
            Assert.AreEqual(channel, open);
			Assert.AreEqual(e.Text, "TOKEN");
            channel.Close();
        }
Пример #11
0
 static void c_Closed(object sender, ChannelCloseEventArgs e)
 {
     Console.WriteLine("Channel is now closed, bye..");
     channel = null;
 }
Пример #12
0
 protected virtual void Closed(Channel channel, ChannelCloseEventArgs e){}
Пример #13
0
 protected virtual void Signal(Channel channel, ChannelEventArgs e){}
Пример #14
0
        protected override void Signal(Channel channel, ChannelEventArgs e)
        {
			Assert.AreEqual(e.Text, Message);
            channel.Close();
        }
Пример #15
0
 protected Channel CreateRandomChannel(ChannelMode mode, bool secure)
 {
     Channel channel = new Channel();
     bindChannel(channel);
     channel.Connect((secure ? "https://" : "") + UniqueUrl(), mode);
     return channel;
 }
Пример #16
0
        void bindChannel (Channel channel)
        {
            channel.Open += delegate(object sender, ChannelEventArgs e) {
                try {
                    Open((Channel) sender, e);
                }
                catch (Exception ex) {
                    error = ex;
                }
            };

            channel.Signal += delegate(object sender, ChannelEventArgs e) {
                try {
                    Signal((Channel) sender, e);
                }
                catch (Exception ex) {
                    error = ex;
                }
            };

            channel.Data += delegate(object sender, ChannelDataEventArgs e) {
                try {
                    Data((Channel) sender, e);
                }
                catch (Exception ex) {
                    error = ex;
                }
            };

            channel.Closed += delegate(object sender, ChannelCloseEventArgs e) {
                try {
                    Closed((Channel) sender, e);
                }
                catch (Exception ex) {
                    error = ex;
                }
            };
        }
Пример #17
0
 protected override void Open(Channel channel, ChannelEventArgs e)
 {
     if (channel == closingChannel) {
         channel.Close(Message);
     }
 }
Пример #18
0
 protected virtual void Data(Channel channel, ChannelDataEventArgs e){}
Пример #19
0
        void deallocChannel(Channel channel, Frame frame, string reason)
        {
            if (channel.AbsolutePath == null)
                return;

            if (_channels.ContainsKey(channel.AbsolutePath))
                _channels.Remove(channel.AbsolutePath);

            if (channel.Ptr != 0)
                _routes.Remove(channel.Ptr);

            _refcount--;
            if (_refcount == 0) {
                close();
            }

            channel.handleClose(frame, reason);
        }
Пример #20
0
        void allocChannel(Channel channel)
        {
            string path;

            path = channel.AbsolutePath == null ? "/"
                                                : channel.AbsolutePath;

            if (_channels.ContainsKey(path)) {
                throw new Exception("Channel already created");
            }

            _channels.Add(path, channel);
            _refcount++;

            if (_handshaked) {
                byte[] pathbuff = Encoding.UTF8.GetBytes(channel.AbsolutePath);
                Frame frame = Frame.Resolve(pathbuff);
                _adapter.Send(frame);
            }
            else {
                _openQueue.Enqueue(channel);
            }
        }
Пример #21
0
 protected override void Open(Channel channel, ChannelEventArgs e)
 {
     for (int i = 0; i < 1000; i++) {
         channel.Send(payload);
     }
 }
Пример #22
0
 protected override void Open(Channel channel, ChannelEventArgs e)
 {
     channel.Emit("ping");
 }
Пример #23
0
 void deallocChannel(Channel channel)
 {
     deallocChannel(channel, null, null);
 }
Пример #24
0
 protected override void Open(Channel channel, ChannelEventArgs e)
 {
     channel.Send(payload);
 }
Пример #25
0
 protected override void Closed(Channel channel, ChannelCloseEventArgs e)
 {
     Assert.IsTrue(e.WasClean);
     Assert.IsFalse(e.WasDenied);
     Done();
 }
Пример #26
0
 protected virtual void Open(Channel channel, ChannelEventArgs e){}