Force blocking stdout
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
8c47f2726c
commit
770deae6cd
2 changed files with 41 additions and 0 deletions
40
shadermeh.c
40
shadermeh.c
|
@ -48,6 +48,39 @@ static void convert_for_ffmpeg(const uint8_t *in, uint8_t *out,
|
|||
}
|
||||
}
|
||||
|
||||
static int wait_fd_event(int fd, int events)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
int ret;
|
||||
|
||||
for (;;) {
|
||||
pfd.fd = fd;
|
||||
pfd.events = events;
|
||||
pfd.revents = 0;
|
||||
|
||||
ret = poll(&pfd, 1, -1);
|
||||
|
||||
if (ret > 0) {
|
||||
if (pfd.revents & events)
|
||||
break;
|
||||
|
||||
if (pfd.revents & (POLLERR | POLLHUP)) {
|
||||
fputs("poll reported error\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
perror("poll");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_retry(int fd, const void *buffer, size_t size)
|
||||
{
|
||||
while (size > 0) {
|
||||
|
@ -56,6 +89,13 @@ static int write_retry(int fd, const void *buffer, size_t size)
|
|||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
||||
if (errno == EAGAIN) {
|
||||
if (wait_fd_event(fd, POLLOUT))
|
||||
return -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
perror("write");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <time.h>
|
||||
|
||||
#define AUDIO_SAMPLES (512)
|
||||
|
|
Loading…
Reference in a new issue