Exemple #1
0
        private void Listener()
        {
            this.Node.Listen();
            List <Socket> listenlist;
            bool          end = false;

            while (end != true)
            {
                listenlist = new List <Socket>();
                lock (this.Node.Connectors)
                {
                    foreach (KeyValuePair <string, Connector> keypair in this.Node.Connectors)
                    {
                        listenlist.Add(keypair.Value.ListenSocket);
                    }
                }
                if (listenlist.Count == 0)
                {
                    end = true;
                    continue;
                }
                Socket.Select(listenlist, null, null, 1000);
                foreach (Socket sock in listenlist)
                {
                    IConnection acceptargs = new Native1();
                    lock (this.Node.Connectors)
                    {
                        foreach (KeyValuePair <string, Connector> keypair in this.Node.Connectors)
                        {
                            if (sock == keypair.Value.ListenSocket)
                            {
                                acceptargs.Connector = keypair.Value;
                            }
                        }
                    }
                    acceptargs.Socket = sock.Accept();
                    ThreadPool.QueueUserWorkItem(this.AcceptSocket, acceptargs);
                }
            }
        }
Exemple #2
0
        public int Connect(Node node)
        {
            IConnection conn = new Native1();

            conn.Connector = this;
            IPAddress  ip;
            IPEndPoint ep;

            conn.Node = node;
            IPAddress.TryParse(this.Host, out ip);
            ep = new IPEndPoint(ip, this.Port);
            this.ConnectSocket = this.createsock();
            conn.Socket        = this.ConnectSocket;
            int retval;

            try
            {
                this.ConnectSocket.Connect(ep);
                int authval = conn.Auth();
                if (authval == 0)
                {
                    conn.Connect = true;
                    lock (node.Connections)
                    {
                        node.Connections.Add(conn);
                    }
                    retval = 0;
                    return(retval);
                }
                else
                {
                    return(authval);
                }
            }
            catch
            {
                retval = 2;
            }
            return(retval);
        }