Commit 873f53e3 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Feature: Emit a range of basic connection and client events

parent 79c7a5f3
......@@ -49,6 +49,7 @@
#include "util.h"
#include "acl.h"
#include "listensocket.h"
#include "fastevent.h"
/* for ADMIN_COMMAND_ERROR */
#include "admin.h"
......@@ -100,6 +101,8 @@ int client_create(client_t **c_ptr, connection_t *con, http_parser_t *parser)
client->write_to_client = format_generic_write_to_client;
*c_ptr = client;
fastevent_emit(FASTEVENT_TYPE_CLIENT_CREATE, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CLIENT, client);
return ret;
}
......@@ -153,6 +156,8 @@ void client_destroy(client_t *client)
if (client == NULL)
return;
fastevent_emit(FASTEVENT_TYPE_CLIENT_DESTROY, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CLIENT, client);
if (client->reuse != ICECAST_REUSE_CLOSE) {
/* only reuse the client if we reached the body's EOF. */
if (client_body_eof(client) == 1) {
......@@ -237,6 +242,8 @@ int client_read_bytes(client_t *client, void *buf, unsigned len)
if (bytes == -1 && client->con->error)
ICECAST_LOG_DEBUG("reading from connection has failed");
fastevent_emit(FASTEVENT_TYPE_CLIENT_READ, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_OBRD, client, buf, (size_t)len, (ssize_t)bytes);
return bytes;
}
......@@ -580,6 +587,8 @@ int client_send_bytes(client_t *client, const void *buf, unsigned len)
if (client->con->error)
ICECAST_LOG_DEBUG("Client connection died");
fastevent_emit(FASTEVENT_TYPE_CLIENT_WRITE, FASTEVENT_FLAG_NONE, FASTEVENT_DATATYPE_OBRD, client, buf, (size_t)len, (ssize_t)ret);
return ret;
}
......@@ -615,6 +624,8 @@ ssize_t client_body_read(client_t *client, void *buf, size_t len)
client->request_body_read += ret;
}
fastevent_emit(FASTEVENT_TYPE_CLIENT_READ_BODY, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_OBRD, client, buf, len, ret);
return ret;
}
......
......@@ -60,6 +60,7 @@
#include "acl.h"
#include "refobject.h"
#include "listensocket.h"
#include "fastevent.h"
#define CATMODULE "connection"
......@@ -209,6 +210,9 @@ static int connection_send_tls(connection_t *con, const void *buf, size_t len)
} else {
con->sent_bytes += bytes;
}
fastevent_emit(FASTEVENT_TYPE_CONNECTION_WRITE, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_OBRD, con, buf, len, bytes);
return bytes;
}
#else
......@@ -245,6 +249,9 @@ static int connection_send(connection_t *con, const void *buf, size_t len)
} else {
con->sent_bytes += bytes;
}
fastevent_emit(FASTEVENT_TYPE_CONNECTION_WRITE, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_OBRD, con, buf, len, (ssize_t)bytes);
return bytes;
}
......@@ -271,6 +278,8 @@ connection_t *connection_create(sock_t sock, listensocket_t *listensocket_real,
con->send = connection_send;
}
fastevent_emit(FASTEVENT_TYPE_CONNECTION_CREATE, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CONNECTION, con);
return con;
}
......@@ -297,7 +306,7 @@ void connection_uses_tls(connection_t *con)
#endif
}
ssize_t connection_read_bytes(connection_t *con, void *buf, size_t len)
static inline ssize_t connection_read_bytes_real(connection_t *con, void *buf, size_t len)
{
ssize_t done = 0;
ssize_t ret;
......@@ -338,10 +347,21 @@ ssize_t connection_read_bytes(connection_t *con, void *buf, size_t len)
return done + ret;
}
ssize_t connection_read_bytes(connection_t *con, void *buf, size_t len)
{
ssize_t ret = connection_read_bytes_real(con, buf, len);
fastevent_emit(FASTEVENT_TYPE_CONNECTION_READ, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_OBRD, con, buf, len, ret);
return ret;
}
int connection_read_put_back(connection_t *con, const void *buf, size_t len)
{
void *n;
fastevent_emit(FASTEVENT_TYPE_CONNECTION_PUTBACK, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_OBR, con, buf, len);
if (con->readbufferlen) {
n = realloc(con->readbuffer, con->readbufferlen + len);
if (!n)
......@@ -1688,6 +1708,8 @@ void connection_close(connection_t *con)
if (!con)
return;
fastevent_emit(FASTEVENT_TYPE_CONNECTION_DESTROY, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CONNECTION, con);
tls_unref(con->tls);
if (con->sock != -1) /* TODO: do not use magic */
sock_close(con->sock);
......
......@@ -19,6 +19,16 @@
typedef enum {
FASTEVENT_TYPE_SLOWEVENT = 0,
FASTEVENT_TYPE_CONNECTION_CREATE,
FASTEVENT_TYPE_CONNECTION_DESTROY,
FASTEVENT_TYPE_CONNECTION_READ,
FASTEVENT_TYPE_CONNECTION_PUTBACK,
FASTEVENT_TYPE_CONNECTION_WRITE,
FASTEVENT_TYPE_CLIENT_CREATE,
FASTEVENT_TYPE_CLIENT_DESTROY,
FASTEVENT_TYPE_CLIENT_READ,
FASTEVENT_TYPE_CLIENT_WRITE,
FASTEVENT_TYPE_CLIENT_READ_BODY,
FASTEVENT_TYPE__END /* must be last element */
} fastevent_type_t;
......@@ -26,7 +36,9 @@ typedef enum {
FASTEVENT_DATATYPE_NONE = 0,
FASTEVENT_DATATYPE_EVENT,
FASTEVENT_DATATYPE_CLIENT,
FASTEVENT_DATATYPE_CONNECTION
FASTEVENT_DATATYPE_CONNECTION,
FASTEVENT_DATATYPE_OBR, /* Object, const void *Buffer, size_t Request_length */
FASTEVENT_DATATYPE_OBRD /* Object, const void *Buffer, size_t Request_length, ssize_t Done_length */
} fastevent_datatype_t;
typedef int fastevent_flag_t;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment