Ejemplo n.º 1
0
static PyObject *
Buffer_read(Buffer *self, PyObject *args, PyObject *kwargs)
{
    int count_bytes;
    char *kwlist[] = {"length", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &count_bytes))
        return NULL;

    int bytes_available_for_read = ring_buffer_count_bytes (self->buffer);
    if (bytes_available_for_read < count_bytes) {
        PyErr_SetString(InsufficientDataError, "Not enough data to read from");
        return NULL;
    }

    PyObject *datagram = PyString_FromStringAndSize(NULL, count_bytes);
    ring_buffer_read (self->buffer, PyString_AsString(datagram), count_bytes);
    return datagram;
}
Ejemplo n.º 2
0
static PyObject *
Buffer_read_piece(Buffer *self, PyObject *args, PyObject *kwargs)
{
    if ( ring_buffer_eof(self->buffer) ) {
        PyErr_SetString (InsufficientDataError, "No data in buffer");
        return NULL;
    }

    int bytes_available_for_read = ring_buffer_count_bytes (self->buffer);
    PyObject *datagram;
    if (bytes_available_for_read < self->buffer->page_size) {
        datagram = PyString_FromStringAndSize(NULL, bytes_available_for_read);
        ring_buffer_read (self->buffer, PyString_AsString(datagram), bytes_available_for_read);
    } else {
        datagram = PyString_FromStringAndSize(NULL, self->buffer->page_size);
        ring_buffer_read (self->buffer, PyString_AsString(datagram), bytes_available_for_read);
    }

    return datagram;
}
Ejemplo n.º 3
0
unsigned long
ring_buffer_count_free_bytes (struct ring_buffer *buffer)
{
    return buffer->count_bytes - ring_buffer_count_bytes (buffer);
}
Ejemplo n.º 4
0
static Py_ssize_t
Buffer_len(Buffer* self)
{
    return ring_buffer_count_bytes (self->buffer);
}