Move non-blocking-write code here from rtsp.c

This commit is contained in:
Mike Brady
2015-08-06 14:30:44 +02:00
parent fdbf64e9a6
commit 1b52e26f8f
2 changed files with 28 additions and 0 deletions
+26
View File
@@ -33,6 +33,7 @@
#include <time.h>
#include <unistd.h>
#include <popt.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -510,3 +511,28 @@ uint64_t get_absolute_time_in_fp() {
#endif
return time_now_fp;
}
ssize_t non_blocking_write(int fd, const void *buf, size_t count) {
// debug(1,"writing %u to pipe...",count);
// we are assuming that the count is always smaller than the FIFO's buffer
struct pollfd ufds[1];
ssize_t reply;
do {
ufds[0].fd = fd;
ufds[0].events = POLLOUT;
int rv = poll(ufds, 1, 5000);
if (rv == -1)
debug(1, "error waiting for pipe to unblock...");
if (rv == 0)
debug(1, "timeout waiting for pipe to unblock");
reply = write(fd, buf, count);
if ((reply == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK)))
debug(1, "writing to pipe will block...");
// else
// debug(1,"writing %u to pipe done...",reply);
} while ((reply == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK)));
return reply;
// return write(fd,buf,count);
}
+2
View File
@@ -90,6 +90,8 @@ int get_requested_connection_state_to_output();
void set_requested_connection_state_to_output(int v);
ssize_t non_blocking_write(int fd, const void *buf, size_t count); // used in a few places
int debuglev;
void die(char *format, ...);
void warn(char *format, ...);