projects
/
paraslash.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move gengetopt targets to own Makefile.
[paraslash.git]
/
chunk_queue.c
diff --git
a/chunk_queue.c
b/chunk_queue.c
index 0b1e300026c94d60d7d55e6172ed8f338cf0b069..fa31718590dd73fad6f034d69ce2a8d7fc299e86 100644
(file)
--- a/
chunk_queue.c
+++ b/
chunk_queue.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007
-2009
Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
@@
-8,6
+8,7
@@
#include "para.h"
#include "list.h"
#include "para.h"
#include "list.h"
+#include "afh.h"
#include "vss.h"
#include "string.h"
#include "error.h"
#include "vss.h"
#include "string.h"
#include "error.h"
@@
-17,23
+18,23
@@
* allows them to enqueue chunks if they can not be sent out immediately.
*
* Chunk queues are "cheap" in the sense that only reference to the audio file
* allows them to enqueue chunks if they can not be sent out immediately.
*
* Chunk queues are "cheap" in the sense that only reference to the audio file
- * data is stored, but not the data its
s
elf.
+ * data is stored, but not the data itself.
*/
struct chunk_queue {
/** The list of pending chunks for this client. */
struct list_head q;
/** The number of pending bytes for this client. */
unsigned long num_pending;
*/
struct chunk_queue {
/** The list of pending chunks for this client. */
struct list_head q;
/** The number of pending bytes for this client. */
unsigned long num_pending;
- /**
Enqueueing more than that many bytes is
an error. */
+ /**
More than that many bytes in the queue is considered
an error. */
unsigned long max_pending;
};
/** Describes one queued chunk in a chunk queue. */
struct queued_chunk {
unsigned long max_pending;
};
/** Describes one queued chunk in a chunk queue. */
struct queued_chunk {
- /**
The number of the queued chunk, -1U means header
. */
-
unsigned chunk_num
;
- /** The number of bytes
already sent
. */
-
unsigned sent
;
+ /**
Pointer to the data to be queued
. */
+
const char *buf
;
+ /** The number of bytes
of this chunk
. */
+
size_t num_bytes
;
/** Position of the chunk in the chunk queue. */
struct list_head node;
};
/** Position of the chunk in the chunk queue. */
struct list_head node;
};
@@
-42,32
+43,21
@@
struct queued_chunk {
* Add a chunk to the given queue.
*
* \param cq the queue to add the chunk to.
* Add a chunk to the given queue.
*
* \param cq the queue to add the chunk to.
- * \param chunk_num The number of the chunk to be queued.
- * \param sent The number of bytes of this chunk that the sender was able to
- * send.
+ * \param buf Pointer to the data to be queued.
+ * \param num_bytes The size of \a buf.
*
*
- * \return
Positive on success, negative on errors
.
+ * \return
Standard
.
*/
*/
-int cq_enqueue(struct chunk_queue *cq, long unsigned chunk_num,
- size_t sent)
+int cq_enqueue(struct chunk_queue *cq, const char *buf, size_t num_bytes)
{
struct queued_chunk *qc;
{
struct queued_chunk *qc;
- char *buf;
- size_t len;
- int ret;
- if (chunk_num != -1U) {
- ret = vss_get_chunk(chunk_num, &buf, &len);
- if (ret < 0)
- return ret;
- } else
- buf = vss_get_header(&len);
- if (cq->num_pending + len > cq->max_pending)
+ if (cq->num_pending + num_bytes > cq->max_pending)
return -E_QUEUE;
qc = para_malloc(sizeof(struct queued_chunk));
return -E_QUEUE;
qc = para_malloc(sizeof(struct queued_chunk));
- cq->num_pending +=
len
;
- qc->
chunk_num = chunk_num
;
- qc->
sent = sent
;
+ cq->num_pending +=
num_bytes
;
+ qc->
buf = buf
;
+ qc->
num_bytes = num_bytes
;
list_add_tail(&qc->node, &cq->q);
PARA_DEBUG_LOG("%lu bytes queued for %p\n", cq->num_pending, &cq->q);
return 1;
list_add_tail(&qc->node, &cq->q);
PARA_DEBUG_LOG("%lu bytes queued for %p\n", cq->num_pending, &cq->q);
return 1;
@@
-78,7
+68,7
@@
int cq_enqueue(struct chunk_queue *cq, long unsigned chunk_num,
*
* \param cq The chunk queue.
*
*
* \param cq The chunk queue.
*
- * \return The next queued chunk, or \p NULL if there is no chunk a
w
ailable.
+ * \return The next queued chunk, or \p NULL if there is no chunk a
v
ailable.
*/
struct queued_chunk *cq_peek(struct chunk_queue *cq)
{
*/
struct queued_chunk *cq_peek(struct chunk_queue *cq)
{
@@
-101,7
+91,7
@@
void cq_dequeue(struct chunk_queue *cq)
}
/**
}
/**
- * Change the number of bytes sen
d
for the current queued chunk.
+ * Change the number of bytes sen
t
for the current queued chunk.
*
* \param cq The chunk queue.
* \param sent Number of bytes successfully sent.
*
* \param cq The chunk queue.
* \param sent Number of bytes successfully sent.
@@
-110,7
+100,8
@@
void cq_update(struct chunk_queue *cq, size_t sent)
{
struct queued_chunk *qc = cq_peek(cq);
assert(qc);
{
struct queued_chunk *qc = cq_peek(cq);
assert(qc);
- qc->sent += sent;
+ qc->num_bytes -= sent;
+ qc->buf += sent;
cq->num_pending -= sent;
}
cq->num_pending -= sent;
}
@@
-119,23
+110,14
@@
void cq_update(struct chunk_queue *cq, size_t sent)
*
* \param qc The queued chunk.
* \param buf Result pointer.
*
* \param qc The queued chunk.
* \param buf Result pointer.
- * \param
len
Number of bytes of \a buf.
+ * \param
num_bytes
Number of bytes of \a buf.
*
* \return Positive on success, negative on errors.
*/
*
* \return Positive on success, negative on errors.
*/
-int cq_get(struct queued_chunk *qc, c
har **buf, size_t *len
)
+int cq_get(struct queued_chunk *qc, c
onst char **buf, size_t *num_bytes
)
{
{
- int ret;
-
- if (qc->chunk_num != -1U) {
- ret = vss_get_chunk(qc->chunk_num, buf, len);
- if (ret < 0)
- return ret;
- } else
- *buf = vss_get_header(len);
- assert(*len > qc->sent);
- *buf += qc->sent;
- *len -= qc->sent;
+ *buf = qc->buf;
+ *num_bytes = qc->num_bytes;
return 1;
}
return 1;
}