36{
37
38 memcpy(&m_rset, &m_allset, sizeof(m_rset));
39 memcpy(&m_wset, &m_allset, sizeof(m_wset));
40
41
42
43
44
45
46 int rc = select(m_maxfd + 1, &m_rset, NULL, NULL, NULL);
47
48
49
50
51
52
53
54
55
56
57
58
59 if (rc < 0)
60 perror("select");
61 else if (rc == 0)
62 return -1;
63
64
65 if (FD_ISSET(m_sock, &m_rset)) {
66
67
68 int t;
69 struct sockaddr_in isa;
70 socklen_t i = sizeof(isa);
71 getsockname(m_sock, (struct sockaddr*)&isa, &i);
72 if ((t =::accept(m_sock, (struct sockaddr*)&isa, &i)) < 0) {
73
74 return (-1);
75 }
76 m_fd.push_back(t);
77 printf("New socket registered t=%d, list size = %lu\n", t, m_fd.size());
78 FD_SET(t, &m_allset);
79 if (t > m_maxfd) m_maxfd = t;
80
81 return 0;
82 } else {
83 return 1;
84 }
85}