comparison src/indexer/indexer-client.c @ 13192:af8c5e56d098

indexer: If verbose_proctitle=yes, show how many clients/requests there are.
author Timo Sirainen <tss@iki.fi>
date Tue, 09 Aug 2011 19:42:23 +0300
parents 268f76a75e51
children 8dcb7c7f66d5
comparison
equal deleted inserted replaced
13191:c705f4fa7a77 13192:af8c5e56d098
37 struct indexer_client *client; 37 struct indexer_client *client;
38 unsigned int tag; 38 unsigned int tag;
39 }; 39 };
40 40
41 struct indexer_client *clients = NULL; 41 struct indexer_client *clients = NULL;
42 static unsigned int clients_count = 0;
42 43
43 static void indexer_client_destroy(struct indexer_client *client); 44 static void indexer_client_destroy(struct indexer_client *client);
44 static void indexer_client_ref(struct indexer_client *client); 45 static void indexer_client_ref(struct indexer_client *client);
45 static void indexer_client_unref(struct indexer_client *client); 46 static void indexer_client_unref(struct indexer_client *client);
46 47
171 client->queue = queue; 172 client->queue = queue;
172 client->fd = fd; 173 client->fd = fd;
173 client->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); 174 client->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
174 client->output = o_stream_create_fd(fd, (size_t)-1, FALSE); 175 client->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
175 client->io = io_add(fd, IO_READ, indexer_client_input, client); 176 client->io = io_add(fd, IO_READ, indexer_client_input, client);
177
176 DLLIST_PREPEND(&clients, client); 178 DLLIST_PREPEND(&clients, client);
179 clients_count++;
180 indexer_refresh_proctitle();
177 return client; 181 return client;
178 } 182 }
179 183
180 static void indexer_client_destroy(struct indexer_client *client) 184 static void indexer_client_destroy(struct indexer_client *client)
181 { 185 {
191 if (close(client->fd) < 0) 195 if (close(client->fd) < 0)
192 i_error("close(client) failed: %m"); 196 i_error("close(client) failed: %m");
193 client->fd = -1; 197 client->fd = -1;
194 indexer_client_unref(client); 198 indexer_client_unref(client);
195 199
200 clients_count--;
196 master_service_client_connection_destroyed(master_service); 201 master_service_client_connection_destroyed(master_service);
202 indexer_refresh_proctitle();
197 } 203 }
198 204
199 static void indexer_client_ref(struct indexer_client *client) 205 static void indexer_client_ref(struct indexer_client *client)
200 { 206 {
201 i_assert(client->refcount > 0); 207 i_assert(client->refcount > 0);
212 i_stream_destroy(&client->input); 218 i_stream_destroy(&client->input);
213 o_stream_destroy(&client->output); 219 o_stream_destroy(&client->output);
214 i_free(client); 220 i_free(client);
215 } 221 }
216 222
223 unsigned int indexer_clients_get_count(void)
224 {
225 return clients_count;
226 }
227
217 void indexer_clients_destroy_all(void) 228 void indexer_clients_destroy_all(void)
218 { 229 {
219 while (clients != NULL) 230 while (clients != NULL)
220 indexer_client_destroy(clients); 231 indexer_client_destroy(clients);
221 } 232 }