Skip to content

Commit a96b29f

Browse files
committed
Fix FIONREAD for pipes
Fixes: #26711
1 parent fcfc013 commit a96b29f

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/audio_worklet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ var port = globalThis.port || {};
273273
class BootstrapMessages extends AudioWorkletProcessor {
274274
constructor(arg) {
275275
super();
276+
console.log("BootstrapMessages CTOR", arg);
276277
startWasmWorker(arg.processorOptions)
277278
// Listen to messages from the main thread. These messages will ask this
278279
// scope to create the real AudioWorkletProcessors that call out to Wasm to

src/lib/libpipefs.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ addToLibrary({
117117
dup(stream) {
118118
stream.node.pipe.refcnt++;
119119
},
120-
ioctl(stream, request, varargs) {
120+
ioctl(stream, request, argp) {
121+
if (request == {{{ cDefs.FIONREAD }}}) {
122+
var pipe = stream.node.pipe;
123+
var currentLength = 0;
124+
for (var bucket of pipe.buckets) {
125+
currentLength += bucket.offset - bucket.roffset;
126+
}
127+
{{{ makeSetValue('argp', 0, 'currentLength', 'i32') }}};
128+
return 0;
129+
}
121130
return {{{ cDefs.EINVAL }}};
122131
},
123132
fsync(stream) {

src/lib/libwebaudio.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ var LibraryWebAudio = {
227227
audioWorklet['port'] = {
228228
postMessage: (msg) => {
229229
if (msg['_boot']) {
230+
console.log("creating em-bootstrap", Object.keys(msg));
230231
audioWorklet.bootstrapMessage = new AudioWorkletNode(audioContext, 'em-bootstrap', {
231232
processorOptions: msg
232233
});

test/core/test_pipe_select.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <sys/select.h>
2+
#include <sys/ioctl.h>
23
#include <time.h>
34
#include <assert.h>
45
#include <stdio.h>
@@ -7,18 +8,29 @@
78

89
int pipe_a[2];
910

11+
int get_available(int fd) {
12+
int avail = 0;
13+
assert(ioctl(fd, FIONREAD, &avail) == 0);
14+
printf("FIONREAD %d -> %d\n", fd, avail);
15+
return avail;
16+
}
17+
1018
int main() {
1119
fd_set readfds;
1220
const char *t = "test\n";
1321

1422
assert(pipe(pipe_a) == 0);
23+
assert(get_available(pipe_a[0]) == 0);
24+
assert(get_available(pipe_a[1]) == 0);
25+
1526
FD_ZERO(&readfds);
1627
FD_SET(pipe_a[0], &readfds);
1728
write(pipe_a[1], t, strlen(t));
1829
assert(select(pipe_a[0] + 1, &readfds, NULL, NULL, NULL) == 1);
1930
assert(FD_ISSET(pipe_a[0], &readfds));
31+
assert(get_available(pipe_a[0]) == strlen(t));
32+
assert(get_available(pipe_a[1]) == strlen(t));
2033

2134
close(pipe_a[0]); close(pipe_a[1]);
22-
2335
return 0;
2436
}

0 commit comments

Comments
 (0)