eis: pass the disconnect reason around when disconnecting a client

No real functional changes right now, but allows for future multiple errors
This commit is contained in:
Peter Hutterer 2023-02-16 12:10:32 +10:00
parent 8a52cbbe10
commit 5631b54b96

View file

@ -164,14 +164,6 @@ eis_client_send_message(struct eis_client *client, const struct brei_object *obj
return rc < 0 ? rc : 0;
}
static int
client_send_disconnect(struct eis_client *client, const char *reason)
{
return eis_connection_event_disconnected(client->connection,
reason ? EIS_CONNECTION_DISCONNECT_REASON_ERROR : EIS_CONNECTION_DISCONNECT_REASON_DISCONNECTED,
reason);
}
static int
client_send_seat_added(struct eis_client *client, struct eis_seat *seat)
{
@ -200,7 +192,9 @@ eis_client_connect(struct eis_client *client)
}
static void
client_disconnect(struct eis_client *client, const char *reason)
client_disconnect(struct eis_client *client,
enum eis_connection_disconnect_reason reason,
const char *explanation)
{
switch(client->state) {
case EIS_CLIENT_STATE_DISCONNECTED:
@ -216,7 +210,7 @@ client_disconnect(struct eis_client *client, const char *reason)
}
}
eis_queue_disconnect_event(client);
client_send_disconnect(client, reason);
eis_connection_event_disconnected(client->connection, reason, explanation);
client->connection = eis_connection_unref(client->connection);
_fallthrough_;
case EIS_CLIENT_STATE_NEW:
@ -231,7 +225,7 @@ client_disconnect(struct eis_client *client, const char *reason)
_public_ void
eis_client_disconnect(struct eis_client *client)
{
client_disconnect(client, NULL);
client_disconnect(client, EIS_CONNECTION_DISCONNECT_REASON_DISCONNECTED, NULL);
}
void
@ -261,7 +255,7 @@ static int
client_msg_disconnect(struct eis_connection *connection)
{
struct eis_client * client = eis_connection_get_client(connection);
client_disconnect(client, NULL);
client_disconnect(client, EIS_CONNECTION_DISCONNECT_REASON_DISCONNECTED, NULL);
return 0;
}
@ -338,7 +332,9 @@ client_dispatch(struct source *source, void *userdata)
int rc = brei_dispatch(client->brei, source_get_fd(source), lookup_object, client);
if (rc < 0) {
brei_drain_fd(source_get_fd(source));
client_disconnect(client, strerror(-rc));
client_disconnect(client,
EIS_CONNECTION_DISCONNECT_REASON_ERROR,
strerror(-rc));
}
static const char *client_states[] = {