History

stream: enable caching for sockets, pipes and FIFOs

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.

bptato committed 2 years ago

Commit 801306a1 parent 830f6cc1 file · +5 −1Browse files

Unified · Split

stream/stream_file.c+5−1
@@ -307,6 +307,7 @@ static int open_f(stream_t *stream, const struct stream_open_args *args) · 306 unmodified lines
307307 }
308308
309309 struct stat st;
310+ bool is_sock_or_fifo = false;
310311 if (fstat(p->fd, &st) == 0) {
311312 if (S_ISDIR(st.st_mode)) {
312313 stream->is_directory = true;
@@ -320,6 +321,9 @@ static int open_f(stream_t *stream, const struct stream_open_args *args) · 7 unmodified lines
320321 fcntl(p->fd, F_SETFL, val);
321322 #endif
322323 } else {
324+#ifndef __MINGW32__
325+ is_sock_or_fifo = S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode);
326+#endif
323327 p->use_poll = true;
324328 }
325329 }
@@ -341,7 +345,7 @@ static int open_f(stream_t *stream, const struct stream_open_args *args) · 15 unmodified lines
341345 stream->get_size = get_size;
342346 stream->close = s_close;
343347
344− if (check_stream_network(p->fd)) {
348+ if (is_sock_or_fifo || check_stream_network(p->fd)) {
345349 stream->streaming = true;
346350 #if HAVE_COCOA
347351 if (fcntl(p->fd, F_RDAHEAD, 0) < 0) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t