Skip to content

Commit

Permalink
stream: enable caching for sockets, pipes and FIFOs
Browse files Browse the repository at this point in the history
This is useful e.g. when the caller dup2's a socket into stdin, or
passes a socket/pipe as /dev/fd/{fd}, because it is impossible to seek
on sockets and pipes.
  • Loading branch information
bptato authored and sfan5 committed Mar 16, 2024
1 parent 830f6cc commit 801306a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion stream/stream_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ static int open_f(stream_t *stream, const struct stream_open_args *args)
}

struct stat st;
bool is_sock_or_fifo = false;
if (fstat(p->fd, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
stream->is_directory = true;
Expand All @@ -320,6 +321,9 @@ static int open_f(stream_t *stream, const struct stream_open_args *args)
fcntl(p->fd, F_SETFL, val);
#endif
} else {
#ifndef __MINGW32__
is_sock_or_fifo = S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode);
#endif
p->use_poll = true;
}
}
Expand All @@ -341,7 +345,7 @@ static int open_f(stream_t *stream, const struct stream_open_args *args)
stream->get_size = get_size;
stream->close = s_close;

if (check_stream_network(p->fd)) {
if (is_sock_or_fifo || check_stream_network(p->fd)) {
stream->streaming = true;
#if HAVE_COCOA
if (fcntl(p->fd, F_RDAHEAD, 0) < 0) {
Expand Down

0 comments on commit 801306a

Please sign in to comment.