Needed by the following changes.
void (*die_callback)(void);
struct timeout *to_die;
- void (*avail_overflow_callback)(void);
+ master_service_avail_overflow_callback_t *avail_overflow_callback;
struct timeout *to_overflow_state;
struct master_login *login;
}
void master_service_set_avail_overflow_callback(struct master_service *service,
- void (*callback)(void))
+ master_service_avail_overflow_callback_t *callback)
{
service->avail_overflow_callback = callback;
}
{
struct master_service *service = l->service;
struct master_service_connection conn;
+ struct timeval created;
if (service->master_status.available_count == 0) {
/* we are full. stop listening for now, unless overflow
callback destroys one of the existing connections */
if (service->call_avail_overflow &&
service->avail_overflow_callback != NULL)
- service->avail_overflow_callback();
+ service->avail_overflow_callback(TRUE, &created);
if (service->master_status.available_count == 0) {
master_service_io_listeners_remove(service);
typedef void
master_service_connection_callback_t(struct master_service_connection *conn);
+/* If kill==TRUE, the callback should kill one of the existing connections
+ (likely the oldest). If kill==FALSE, it's just a request to check what is
+ the creation timestamp for the connection to be killed. Returns TRUE if
+ a connection was/could be killed, FALSE if not. */
+typedef bool
+master_service_avail_overflow_callback_t(bool kill, struct timeval *created_r);
+
extern struct master_service *master_service;
const char *master_service_getopt_string(void);
void master_service_set_idle_die_callback(struct master_service *service,
bool (*callback)(void));
/* Call the given callback when there are no available connections and master
- has indicated that it can't create any more processes to handle requests.
- The callback could decide to kill one of the existing connections. */
+ has indicated that it can't create any more processes to handle requests. */
void master_service_set_avail_overflow_callback(struct master_service *service,
- void (*callback)(void));
+ master_service_avail_overflow_callback_t *callback);
/* Set maximum number of clients we can handle. Default is given by master. */
void master_service_set_client_limit(struct master_service *service,
{
}
-void client_destroy_oldest(void)
+bool client_destroy_oldest(bool kill, struct timeval *created_r)
{
struct client *client;
if (last_client == NULL) {
/* we have no clients */
- return;
+ return FALSE;
}
/* destroy the last client that hasn't successfully authenticated yet.
if (client == NULL)
client = last_client;
+ *created_r = client->created;
+ if (!kill)
+ return TRUE;
+
client_notify_disconnect(client, CLIENT_DISCONNECT_RESOURCE_CONSTRAINT,
"Connection queue full");
client_destroy(client, "Connection queue full");
+ return TRUE;
}
void clients_destroy_all_reason(const char *reason)
const char *client_proxy_get_state(struct client *client);
void clients_notify_auth_connected(void);
-void client_destroy_oldest(void);
+bool client_destroy_oldest(bool kill, struct timeval *created_r);
void clients_destroy_all(void);
void clients_destroy_all_reason(const char *reason);