290
290
#ifdef CONFIG_NETWORKING
291
291
if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_read ) {
292
292
len=s->streaming_ctrl->streaming_read(s->fd, buf, len, s->streaming_ctrl);
293
if (s->streaming_ctrl->status == streaming_stopped_e)
295
297
if (s->fill_buffer)
306
308
len= s->fill_buffer ? s->fill_buffer(s, buf, len) : 0;
312
// do not retry if this looks like proper eof
313
if (s->eof || (s->end_pos && pos == s->end_pos))
309
315
// dvdnav has some horrible hacks to "suspend" reads,
310
316
// we need to skip this code or seeks will hang.
311
if (!s->eof && s->type != STREAMTYPE_DVDNAV) {
312
// just in case this is an error e.g. due to network
313
// timeout reset and retry
314
// Seeking is used as a hack to make network streams
315
// reopen the connection, ideally they would implement
316
// e.g. a STREAM_CTRL_RECONNECT to do this
320
stream_seek_internal(s, pos);
321
// make sure EOF is set to ensure no endless loops
323
return stream_read_internal(s, buf, orig_len);
317
if (s->type == STREAMTYPE_DVDNAV)
320
// just in case this is an error e.g. due to network
321
// timeout reset and retry
322
// Seeking is used as a hack to make network streams
323
// reopen the connection, ideally they would implement
324
// e.g. a STREAM_CTRL_RECONNECT to do this
327
if (stream_seek_internal(s, pos) >= 0 || s->pos != pos) // seek failed
329
// make sure EOF is set to ensure no endless loops
331
return stream_read_internal(s, buf, orig_len);
582
* Find a newline character in buffer
591
* Find a termination character in buffer
583
592
* \param buf buffer to search
584
593
* \param len amount of bytes to search in buffer, may not overread
585
594
* \param utf16 chose between UTF-8/ASCII/other and LE and BE UTF-16
586
595
* 0 = UTF-8/ASCII/other, 1 = UTF-16-LE, 2 = UTF-16-BE
588
static const uint8_t *find_newline(const uint8_t *buf, int len, int utf16)
597
static const uint8_t *find_term_char(const uint8_t *buf, int len, uint8_t term, int utf16)
591
600
const uint8_t *end = buf + len;
594
return (uint8_t *)memchr(buf, '\n', len);
603
return (uint8_t *)memchr(buf, term, len);
596
605
while (buf < end - 1) {
597
606
GET_UTF16(c, buf < end - 1 ? get_le16_inc(&buf) : 0, return NULL;)
598
if (buf <= end && c == '\n')
607
if (buf <= end && c == term)
603
612
while (buf < end - 1) {
604
613
GET_UTF16(c, buf < end - 1 ? get_be16_inc(&buf) : 0, return NULL;)
605
if (buf <= end && c == '\n')
614
if (buf <= end && c == term)
654
unsigned char* stream_read_line(stream_t *s,unsigned char* mem, int max, int utf16) {
663
uint8_t *stream_read_until(stream_t *s, uint8_t *mem, int max,
664
uint8_t term, int utf16)
656
667
const unsigned char *end;
657
668
unsigned char *ptr = mem;
664
675
(!cache_stream_fill_buffer(s) ||
665
676
(len = s->buf_len-s->buf_pos) <= 0)) break;
666
end = find_newline(s->buffer+s->buf_pos, len, utf16);
677
end = find_term_char(s->buffer+s->buf_pos, len, term, utf16);
667
678
if(end) len = end - (s->buffer+s->buf_pos) + 1;
668
679
if(len > 0 && max > 0) {
669
680
int l = copy_characters(ptr, max, s->buffer+s->buf_pos, &len, utf16);