Commit 2225738a authored by Michael Smith's avatar Michael Smith

Ensure we don't throw away a buffer after only sending part of it.

svn path=/trunk/icecast/; revision=3290
parent 59b605ec
......@@ -217,14 +217,21 @@ void *source_main(void *arg)
bytes = abuf->len;
sbytes = sock_write_bytes(client->con->sock, &abuf->data[client->pos], bytes);
if (sbytes >= 0) client->con->sent_bytes += sbytes;
if (sbytes >= 0) {
client->con->sent_bytes += sbytes;
if(sbytes != bytes) {
client->pos += sbytes;
refbuf_queue_insert(&client->queue, abuf);
data_done = 1;
break;
}
}
if (sbytes < 0) {
if (!sock_recoverable(sock_error())) {
printf("SOURCE: Client had unrecoverable error catching up (%ld/%ld)\n", sbytes, bytes);
client->con->error = 1;
} else {
printf("SOURCE: client had recoverable error...\n");
client->pos += sbytes>0?sbytes:0;
/* put the refbuf back on top of the queue, since we didn't finish with it */
refbuf_queue_insert(&client->queue, abuf);
}
......@@ -246,7 +253,14 @@ void *source_main(void *arg)
refbuf_queue_add(&client->queue, refbuf);
} else {
sbytes = sock_write_bytes(client->con->sock, refbuf->data, refbuf->len);
if (sbytes >= 0) client->con->sent_bytes += sbytes;
if (sbytes >= 0) {
client->con->sent_bytes += sbytes;
if(sbytes != bytes) {
client->pos = sbytes;
refbuf_addref(refbuf);
refbuf_queue_insert(&client->queue, abuf);
}
}
if (sbytes < 0) {
bytes = sock_error();
if (!sock_recoverable(bytes)) {
......@@ -254,7 +268,7 @@ void *source_main(void *arg)
client->con->error = 1;
} else {
printf("SOURCE: recoverable error %ld\n", bytes);
client->pos = sbytes > 0 ? sbytes : 0;
client->pos = 0;
refbuf_addref(refbuf);
refbuf_queue_insert(&client->queue, refbuf);
}
......
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