static int get_line(RemoteSource *source, char **line, size_t *size) {
ssize_t n, remain;
- char *c;
+ char *c = NULL;
char *newbuf = NULL;
size_t newsize = 0;
assert(source->filled <= source->size);
assert(source->buf == NULL || source->size > 0);
- c = memchr(source->buf, '\n', source->filled);
+ if (source->buf)
+ c = memchr(source->buf, '\n', source->filled);
+
if (c != NULL)
goto docopy;
resize:
+ if (source->fd < 0)
+ /* we have to wait for some data to come to us */
+ return -EWOULDBLOCK;
+
if (source->size - source->filled < LINE_CHUNK) {
// XXX: add check for maximum line length
return 1;
}
+int push_data(RemoteSource *source, const char *data, size_t size) {
+ assert(source);
+ assert(source->state != STATE_EOF);
+
+ if (!GREEDY_REALLOC(source->buf, source->size,
+ source->filled + size))
+ return log_oom();
+
+ memcpy(source->buf + source->filled, data, size);
+ source->filled += size;
+
+ return 0;
+}
+
static int fill_fixed_size(RemoteSource *source, void **data, size_t size) {
int n;
char *newbuf = NULL;
assert(data);
while(source->filled < size) {
+ if (source->fd < 0)
+ /* we have to wait for some data to come to us */
+ return -EWOULDBLOCK;
+
if (!GREEDY_REALLOC(source->buf, source->size, size))
return log_oom();