aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-09 15:40:53 (GMT)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-29 17:58:34 (GMT)
commitd58543c21c2493ec4f74b1a54aaaf348f5eb3097 (patch)
tree171a91324d7855bda65713aefaa6fab136882d0d
parent0b16c25a3d0d886156d1cecc39e8f717aeee44d8 (diff)
libdvbv5: better handle overflow errors
There are some issues with handling overflow errors after the addition of remote access. Address them. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r--lib/include/libdvbv5/dvb-dev.h2
-rw-r--r--lib/libdvbv5/dvb-dev-local.c3
-rw-r--r--lib/libdvbv5/dvb-dev-remote.c11
-rw-r--r--utils/dvb/dvbv5-daemon.c8
-rw-r--r--utils/dvb/dvbv5-zap.c5
5 files changed, 21 insertions, 8 deletions
diff --git a/lib/include/libdvbv5/dvb-dev.h b/lib/include/libdvbv5/dvb-dev.h
index 5525685..da42671 100644
--- a/lib/include/libdvbv5/dvb-dev.h
+++ b/lib/include/libdvbv5/dvb-dev.h
@@ -430,7 +430,7 @@ struct dvb_v5_descriptors *dvb_dev_scan(struct dvb_open_descriptor *open_dev,
#ifdef HAVE_DVBV5_REMOTE
/* Better to be at least 4096 + encoding size */
-#define REMOTE_BUF_SIZE 8192
+#define REMOTE_BUF_SIZE (1<<16)
/**
* @brief initialize the dvb-dev to use a remote device running the
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index f514794..bf69fd6 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -558,7 +558,8 @@ static ssize_t dvb_local_read(struct dvb_open_descriptor *open_dev,
ret = read(fd, buf, count);
if (ret == -1) {
- dvb_perror("read()");
+ if (errno != EOVERFLOW)
+ dvb_perror("read()");
return -errno;
}
diff --git a/lib/libdvbv5/dvb-dev-remote.c b/lib/libdvbv5/dvb-dev-remote.c
index b1d9139..c4036c4 100644
--- a/lib/libdvbv5/dvb-dev-remote.c
+++ b/lib/libdvbv5/dvb-dev-remote.c
@@ -273,7 +273,7 @@ static struct queued_msg *send_fmt(struct dvb_device_priv *dvb, int fd,
pthread_mutex_lock(&msg->lock);
i32 = htobe32(p - buf);
- ret = write(fd, (void *)&i32, 4);
+ ret = send(fd, (void *)&i32, 4, MSG_MORE);
if (ret != 4) {
err = 1;
} else {
@@ -363,7 +363,7 @@ static struct queued_msg *send_buf(struct dvb_device_priv *dvb, int fd,
p += in_size;
i32 = htobe32(p - buf);
- ret = write(fd, (void *)&i32, 4);
+ ret = send(fd, (void *)&i32, 4, MSG_MORE);
if (ret != 4) {
err = 1;
} else {
@@ -1514,7 +1514,7 @@ int dvb_dev_remote_init(struct dvb_device *d, char *server, int port)
struct dvb_v5_fe_parms_priv *parms = (void *)dvb->d.fe_parms;
struct dvb_dev_remote_priv *priv;
struct dvb_dev_ops *ops = &dvb->ops;
- int fd, ret;
+ int fd, ret, bufsize;
/* Call an implementation-specific free method, if defined */
if (ops->free)
@@ -1552,6 +1552,11 @@ int dvb_dev_remote_init(struct dvb_device *d, char *server, int port)
return -1;
}
+ /* Set large buffer for read() to work better */
+ bufsize = REMOTE_BUF_SIZE;
+ setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
+ (void *)&bufsize, (int)sizeof(bufsize));
+
/* Start receiving messsages from the server */
pthread_mutex_init(&priv->lock_io, NULL);
ret = pthread_create(&priv->recv_id, NULL, receive_data, dvb);
diff --git a/utils/dvb/dvbv5-daemon.c b/utils/dvb/dvbv5-daemon.c
index f8e2dc2..bce7fc1 100644
--- a/utils/dvb/dvbv5-daemon.c
+++ b/utils/dvb/dvbv5-daemon.c
@@ -425,7 +425,7 @@ static int send_buf(int fd, const char *buf, size_t size)
pthread_mutex_lock(&msg_mutex);
i32 = htobe32(size);
- ret = write(fd, (void *)&i32, 4);
+ ret = send(fd, (void *)&i32, 4, MSG_MORE);
if (ret >= 0)
ret = write(fd, buf, size);
pthread_mutex_unlock(&msg_mutex);
@@ -1209,10 +1209,16 @@ static void *start_server(void *fd_pointer)
char buf[REMOTE_BUF_SIZE + 8], cmd[80], *p;
ssize_t size;
uint32_t seq;
+ int bufsize;
if (verbose)
dbg("Opening socket %d", fd);
+ /* Set a large buffer for read() to work better */
+ bufsize = REMOTE_BUF_SIZE;
+ setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
+ (void *)&bufsize, (int)sizeof(bufsize));
+
/* Command dispatcher */
do {
size = recv(fd, buf, 4, MSG_WAITALL);
diff --git a/utils/dvb/dvbv5-zap.c b/utils/dvb/dvbv5-zap.c
index 5e7725e..13c3ee0 100644
--- a/utils/dvb/dvbv5-zap.c
+++ b/utils/dvb/dvbv5-zap.c
@@ -500,7 +500,7 @@ static void copy_to_file(struct dvb_open_descriptor *in_fd, int out_fd,
while (timeout_flag == 0) {
r = dvb_dev_read(in_fd, buf, BUFLEN);
if (r < 0) {
- if (r == EOVERFLOW) {
+ if (r == -EOVERFLOW) {
fprintf(stderr, _("buffer overrun\n"));
continue;
}
@@ -692,7 +692,7 @@ int do_traffic_monitor(struct arguments *args, struct dvb_device *dvb)
break;
if ((r = dvb_dev_read(dvr_fd, buffer, BSIZE)) <= 0) {
- if (r == EOVERFLOW) {
+ if (r == -EOVERFLOW) {
struct timeval now;
int diff;
gettimeofday(&now, 0);
@@ -702,6 +702,7 @@ int do_traffic_monitor(struct arguments *args, struct dvb_device *dvb)
fprintf(stderr, _("%.2fs: buffer overrun\n"), diff / 1000.);
continue;
}
+ fprintf(stderr, _("dvbtraffic: read() returned error %zd\n"), r);
break;
}
if (r != BSIZE) {

Privacy Policy