Beispiel #1
0
        public bool addSocket(Socket s, SocketUpdateFunc update_func, TcpTransport trans)
        {
            SocketInfo info = new SocketInfo {
                sock = s.FD, func = update_func, transport = trans
            };

            lock (socket_info_mutex)
            {
                if (socket_info.ContainsKey(info.sock))
                {
                    return(false);
                }
                socket_info.Add(info.sock, info);
                sockets_changed = true;
            }
            signal();
            return(true);
        }
Beispiel #2
0
 public bool addSocket(Socket s, SocketUpdateFunc update_func, TcpTransport trans)
 {
     SocketInfo info = new SocketInfo {sock = s.FD, func = update_func, transport = trans};
     lock (socket_info_mutex)
     {
         if (socket_info.ContainsKey(info.sock))
             return false;
         socket_info.Add(info.sock, info);
         sockets_changed = true;
     }
     signal();
     return true;
 }
Beispiel #3
0
        public void update(int poll_timeout)
        {
            createNativePollSet();
            int udfscount = ufds.Count;

            //int ret = 0;
            for (int i = 0; i < ufds.Count; i++)
            {
                Socket sock = Socket.Get(ufds[i].sock);
                if (sock == null || !sock.Connected)
                {
                    ufds[i].revents |= POLLHUP;
                }
                else if (sock == null || sock.SafePoll(poll_timeout, SelectMode.SelectError))
                {
                    ufds[i].revents |= POLLERR;
                }
                else
                {
                    if (sock != null && sock.SafePoll(poll_timeout, SelectMode.SelectWrite))
                    {
                        ufds[i].revents |= POLLOUT;
                    }
                    if (sock != null && sock.SafePoll(poll_timeout, SelectMode.SelectRead))
                    {
                        ufds[i].revents |= POLLIN;
                    }
                }
            }
            if (udfscount == 0)
            {
                return;
            }
            for (int i = 0; i < udfscount; i++)
            {
                if (ufds[i].revents == 0)
                {
                    continue;
                }

                SocketUpdateFunc func = null;
                int events            = 0;
                lock (socket_info_mutex)
                {
                    if (!socket_info.ContainsKey(ufds[i].sock))
                    {
                        continue;
                    }
                    SocketInfo info = socket_info[ufds[i].sock];
                    func   = info.func;
                    events = info.events;
                }

                int revents = ufds[i].revents;

                if (func != null &&
                    ((events & revents) != 0 || (revents & POLLERR) != 0 || (revents & POLLHUP) != 0 ||
                     (revents & POLLNVAL) != 0))
                {
                    bool skip = false;
                    if ((revents & (POLLERR | POLLHUP | POLLNVAL)) != 0)
                    {
                        lock (just_deleted_mutex)
                        {
                            if (just_deleted.Contains(Socket.Get(ufds[i].sock)))
                            {
                                skip = true;
                            }
                        }
                    }

                    if (!skip)
                    {
                        func(revents & (events | POLLERR | POLLHUP | POLLNVAL));
                    }
                }

                ufds[i].revents = 0;
            }

            lock (just_deleted_mutex)
            {
                just_deleted.Clear();
            }
        }