Commit 38436c3f authored by Philipp Schafft's avatar Philipp Schafft 🦁

Update: Abstract body read with client_body_read() and client_body_eof()

parent ece3786a
......@@ -32,6 +32,7 @@
#include "refobject.h"
#include "cfgfile.h"
#include "connection.h"
#include "tls.h"
#include "refbuf.h"
#include "format.h"
#include "stats.h"
......@@ -435,3 +436,22 @@ void client_set_queue(client_t *client, refbuf_t *refbuf)
if (to_release)
refbuf_release(to_release);
}
ssize_t client_body_read(client_t *client, void *buf, size_t len)
{
return client_read_bytes(client, buf, len);
}
int client_body_eof(client_t *client)
{
if (!client->con)
return 0;
if (client->con->tls && tls_got_shutdown(client->con->tls) > 1)
client->con->error = 1;
if (client->con->error)
return 1;
return 0;
}
......@@ -122,5 +122,7 @@ admin_format_t client_get_admin_format_by_content_negotiation(client_t *client);
int client_send_bytes (client_t *client, const void *buf, unsigned len);
int client_read_bytes (client_t *client, void *buf, unsigned len);
void client_set_queue (client_t *client, refbuf_t *refbuf);
ssize_t client_body_read(client_t *client, void *buf, size_t len);
int client_body_eof(client_t *client);
#endif /* __CLIENT_H__ */
......@@ -317,7 +317,7 @@ static refbuf_t *ebml_get_buffer(source_t *source)
} else if(read_bytes == 0) {
/* Feed more bytes into the parser */
write_buffer = ebml_get_write_buffer(ebml_source_state->ebml, &write_bytes);
read_bytes = client_read_bytes (source->client, write_buffer, write_bytes);
read_bytes = client_body_read(source->client, write_buffer, write_bytes);
if (read_bytes <= 0) {
ebml_wrote (ebml_source_state->ebml, 0);
return NULL;
......
......@@ -465,7 +465,7 @@ static void format_mp3_free_plugin(format_plugin_t *self)
*/
static int complete_read(source_t *source)
{
int bytes;
ssize_t bytes;
format_plugin_t *format = source->format;
mp3_state *source_mp3 = format->_state;
char *buf;
......@@ -480,10 +480,11 @@ static int complete_read(source_t *source)
}
buf = source_mp3->read_data->data + source_mp3->read_count;
bytes = client_read_bytes (source->client, buf, REFBUF_SIZE-source_mp3->read_count);
bytes = client_body_read(source->client, buf, REFBUF_SIZE-source_mp3->read_count);
if (bytes < 0)
{
if (source->client->con->error)
/* Why do we do this here (not source.c)? -- ph3-der-loewe, 2018-04-17 */
if (client_body_eof(source->client))
{
refbuf_release (source_mp3->read_data);
source_mp3->read_data = NULL;
......
......@@ -402,7 +402,7 @@ static refbuf_t *ogg_get_buffer(source_t *source)
ogg_state_t *ogg_info = source->format->_state;
format_plugin_t *format = source->format;
char *data = NULL;
int bytes = 0;
ssize_t bytes = 0;
while (1)
{
......@@ -449,7 +449,7 @@ static refbuf_t *ogg_get_buffer(source_t *source)
/* we need more data to continue getting pages */
data = ogg_sync_buffer (&ogg_info->oy, 4096);
bytes = client_read_bytes (source->client, data, 4096);
bytes = client_body_read(source->client, data, 4096);
if (bytes <= 0)
{
ogg_sync_wrote (&ogg_info->oy, 0);
......
......@@ -516,10 +516,7 @@ static refbuf_t *get_next_buffer (source_t *source)
}
source->last_read = current;
refbuf = source->format->get_buffer (source);
if (source->client->con && source->client->con->tls && tls_got_shutdown(source->client->con->tls) > 1)
source->client->con->error = 1;
if (source->client->con && source->client->con->error)
{
if (client_body_eof(source->client)) {
ICECAST_LOG_INFO("End of Stream %s", source->mount);
source->running = 0;
continue;
......
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