… | |
… | |
59 | : fd (fd), host (strdup (peername)), |
59 | : fd (fd), host (strdup (peername)), |
60 | socket_ev (this, &client::socket_cb), |
60 | socket_ev (this, &client::socket_cb), |
61 | cmd_ev (this, &client::cmd_cb), |
61 | cmd_ev (this, &client::cmd_cb), |
62 | cc_inv (this), cc_other (this) |
62 | cc_inv (this), cc_other (this) |
63 | { |
63 | { |
|
|
64 | refcnt_inc (); // the socket is an external reference |
|
|
65 | |
64 | { |
66 | { |
65 | struct linger linger_opt; |
67 | struct linger linger_opt; |
66 | |
68 | |
67 | linger_opt.l_onoff = 0; |
69 | linger_opt.l_onoff = 0; |
68 | linger_opt.l_linger = 0; |
70 | linger_opt.l_linger = 0; |
… | |
… | |
150 | |
152 | |
151 | // initialisation done, kick it! |
153 | // initialisation done, kick it! |
152 | send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); |
154 | send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); |
153 | flush (); |
155 | flush (); |
154 | |
156 | |
155 | // clients are externally referenced by the socket |
157 | clients.insert (this); |
156 | refcnt_inc (); |
|
|
157 | clients.push_back (this); |
|
|
158 | |
|
|
159 | #if 0//TODO |
|
|
160 | socket_info.nconns++; |
|
|
161 | if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; |
|
|
162 | if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns; |
|
|
163 | #endif |
|
|
164 | } |
158 | } |
165 | |
159 | |
166 | client::~client () |
160 | client::~client () |
167 | { |
161 | { |
168 | sockvec::iterator i = find (clients.begin (), clients.end (), this); |
|
|
169 | if (i != clients.end ()) |
|
|
170 | clients.erase (i); |
162 | clients.erase (this); |
171 | |
163 | |
172 | sfree<uint8> (faces_sent, nrofpixmaps); |
164 | sfree<uint8> (faces_sent, nrofpixmaps); |
173 | free (stats.range); |
165 | free (stats.range); |
174 | free (stats.title); |
166 | free (stats.title); |
175 | free (host); |
167 | free (host); |
… | |
… | |
182 | |
174 | |
183 | if (pl) |
175 | if (pl) |
184 | pl->disconnect (); |
176 | pl->disconnect (); |
185 | |
177 | |
186 | if (fd >= 0) |
178 | if (fd >= 0) |
|
|
179 | { |
|
|
180 | send_packet ("goodbye"); |
|
|
181 | flush (); |
|
|
182 | |
187 | close (fd); |
183 | close (fd); |
|
|
184 | } |
188 | |
185 | |
189 | state = ST_DEAD; |
186 | state = ST_DEAD; |
190 | |
187 | |
191 | socket_ev.suspend (); |
188 | socket_ev.suspend (); |
192 | cmd_ev.suspend (); |
189 | cmd_ev.suspend (); |
193 | |
190 | |
194 | // socket now longer references us |
191 | refcnt_dec (); // socket no longer open |
195 | refcnt_dec (); |
|
|
196 | } |
192 | } |
197 | |
193 | |
198 | /** This sets up the socket and reads all the image information into memory. */ |
194 | /** This sets up the socket and reads all the image information into memory. */ |
199 | void |
195 | void |
200 | init_ericserver (void) |
196 | init_ericserver (void) |