Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
Icecast-Server
Commits
08cf0c12
Commit
08cf0c12
authored
Jul 05, 2018
by
Philipp Schafft
🦁
Browse files
Feature: Emit a range of basic connection and client events
parent
23e7069d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/client.c
View file @
08cf0c12
...
...
@@ -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
;
}
...
...
@@ -205,6 +208,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
)
{
...
...
@@ -289,6 +294,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
;
}
...
...
@@ -632,6 +639,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
;
}
...
...
@@ -667,6 +676,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
;
}
...
...
src/connection.c
View file @
08cf0c12
...
...
@@ -60,6 +60,7 @@
#include
"acl.h"
#include
"refobject.h"
#include
"listensocket.h"
#include
"fastevent.h"
#define CATMODULE "connection"
...
...
@@ -209,6 +210,7 @@ static int connection_send_tls(connection_t *con, const void *buf, size_t len)
}
else
{
con
->
sent_bytes
+=
bytes
;
}
return
bytes
;
}
#else
...
...
@@ -245,6 +247,7 @@ static int connection_send(connection_t *con, const void *buf, size_t len)
}
else
{
con
->
sent_bytes
+=
bytes
;
}
return
bytes
;
}
...
...
@@ -271,6 +274,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
;
}
...
...
@@ -299,10 +304,14 @@ void connection_uses_tls(connection_t *con)
ssize_t
connection_send_bytes
(
connection_t
*
con
,
const
void
*
buf
,
size_t
len
)
{
return
con
->
send
(
con
,
buf
,
len
);
ssize_t
ret
=
con
->
send
(
con
,
buf
,
len
);
fastevent_emit
(
FASTEVENT_TYPE_CONNECTION_WRITE
,
FASTEVENT_FLAG_MODIFICATION_ALLOWED
,
FASTEVENT_DATATYPE_OBRD
,
con
,
buf
,
len
,
ret
);
return
ret
;
}
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
;
...
...
@@ -344,10 +353,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
)
...
...
@@ -1650,6 +1670,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
);
...
...
src/fastevent.h
View file @
08cf0c12
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment