… | |
… | |
39 | #include <sys/time.h> |
39 | #include <sys/time.h> |
40 | #include <sys/socket.h> |
40 | #include <sys/socket.h> |
41 | #include <netinet/in.h> |
41 | #include <netinet/in.h> |
42 | #include <netdb.h> |
42 | #include <netdb.h> |
43 | |
43 | |
44 | #ifdef HAVE_UNISTD_H |
|
|
45 | # include <unistd.h> |
44 | #include <unistd.h> |
46 | #endif |
|
|
47 | |
|
|
48 | #ifdef HAVE_ARPA_INET_H |
|
|
49 | # include <arpa/inet.h> |
45 | #include <arpa/inet.h> |
50 | #endif |
|
|
51 | #include <newserver.h> |
|
|
52 | |
46 | |
53 | sockvec client_sockets; |
47 | sockvec clients; |
54 | |
48 | |
55 | /** |
49 | /** |
56 | * Initializes a connection. Really, it just sets up the data structure, |
50 | * Initializes a connection. Really, it just sets up the data structure, |
57 | * socket setup is handled elsewhere. We do send a version to the |
51 | * socket setup is handled elsewhere. We do send a version to the |
58 | * client. |
52 | * client. |
59 | */ |
53 | */ |
60 | client_socket::client_socket (int fd, const char *peername) |
54 | client::client (int fd, const char *peername) |
61 | : fd (fd), host (strdup (peername)), |
55 | : fd (fd), host (strdup (peername)), |
62 | socket_ev (this, &client_socket::socket_cb) |
56 | socket_ev (this, &client::socket_cb) |
63 | { |
57 | { |
64 | { |
58 | { |
65 | struct linger linger_opt; |
59 | struct linger linger_opt; |
66 | |
60 | |
67 | linger_opt.l_onoff = 0; |
61 | linger_opt.l_onoff = 0; |
… | |
… | |
124 | if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; |
118 | if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; |
125 | if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns; |
119 | if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns; |
126 | #endif |
120 | #endif |
127 | } |
121 | } |
128 | |
122 | |
129 | client_socket::~client_socket () |
123 | client::~client () |
130 | { |
124 | { |
131 | status = Ns_Dead; |
125 | status = Ns_Dead; |
132 | } |
126 | } |
133 | |
127 | |
134 | /** This sets up the socket and reads all the image information into memory. */ |
128 | /** This sets up the socket and reads all the image information into memory. */ |
… | |
… | |
169 | * might be associated with the socket. It is up to the caller to |
163 | * might be associated with the socket. It is up to the caller to |
170 | * update the list |
164 | * update the list |
171 | */ |
165 | */ |
172 | |
166 | |
173 | void |
167 | void |
174 | free_newsocket (client_socket *ns) |
168 | free_newsocket (client *ns) |
175 | { |
169 | { |
176 | if (ns->fd >= 0) |
170 | if (ns->fd >= 0) |
177 | close (ns->fd); |
171 | close (ns->fd); |
178 | |
172 | |
179 | if (ns->stats.range) |
173 | if (ns->stats.range) |
… | |
… | |
198 | free_newsocket (pl->socket); |
192 | free_newsocket (pl->socket); |
199 | free_player (pl); |
193 | free_player (pl); |
200 | } |
194 | } |
201 | |
195 | |
202 | bool |
196 | bool |
203 | add_client_socket (int fd, const char *peername) |
197 | add_client (int fd, const char *peername) |
204 | { |
198 | { |
205 | if (checkbanned (NULL, peername)) |
199 | if (checkbanned (NULL, peername)) |
206 | { |
200 | { |
207 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
201 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
208 | return false; |
202 | return false; |
209 | } |
203 | } |
210 | else |
204 | else |
211 | { |
205 | { |
212 | client_socket *ns = new client_socket (dup (fd), peername); |
206 | client *ns = new client (dup (fd), peername); |
213 | client_sockets.push_back (ns); |
207 | clients.push_back (ns); |
214 | return true; |
208 | return true; |
215 | } |
209 | } |
216 | } |
210 | } |
217 | |
211 | |