Skip to content

Commit

Permalink
Fix tcp_socket_dead() for FreeBSD
Browse files Browse the repository at this point in the history
The FreeBSD port of tvheadend couldn't stream Live TV, and debug
log shows webui judged the peer socket closed immediately after
starting streaming:

2018-04-15 06:30:04.996 [  DEBUG]:webui: Start streaming /stream/mux/c4bc67bdaa13457e33740ca883cc4d75?ticket=7D1B56AD0E434C5F7EBFA4677A7FBE4C94097974
2018-04-15 06:30:04.996 [  DEBUG]:webui: Stop streaming /stream/mux/c4bc67bdaa13457e33740ca883cc4d75?ticket=7D1B56AD0E434C5F7EBFA4677A7FBE4C94097974, client hung up

It looks tcp_socket_dead() misunderstood the zero-return from recv().
For the FreeBSD, recv() might return zero for alive sockets which
have nothing to read.

Submitted by:	Jongsung Kim <jongsung.kim@gmail.com>
Obtained from:	tvheadend/tvheadend#1112


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@467705 35697150-7ecd-e111-bb59-0022644237b5
  • Loading branch information
decke committed Apr 18, 2018
1 parent 83d62c1 commit fd0b8ec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions multimedia/tvheadend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
PORTNAME= tvheadend
PORTVERSION= 4.2.6
DISTVERSIONPREFIX= v
PORTREVISION= 1
CATEGORIES= multimedia

MAINTAINER= decke@FreeBSD.org
Expand Down
39 changes: 39 additions & 0 deletions multimedia/tvheadend/files/patch-src_tcp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From dc7804e1410971dabbe087193ca2b47f02131524 Mon Sep 17 00:00:00 2001
From: Jongsung Kim <jongsung.kim@gmail.com>
Date: Mon, 16 Apr 2018 13:01:41 +0900
Subject: [PATCH] tcp: fix tcp_socket_dead() for FreeBSD

The FreeBSD port of tvheadend couldn't stream Live TV, and debug
log shows webui judged the peer socket closed immediately after
starting streaming:

2018-04-15 06:30:04.996 [ DEBUG]:webui: Start streaming /stream/mux/c4bc67bdaa13457e33740ca883cc4d75?ticket=7D1B56AD0E434C5F7EBFA4677A7FBE4C94097974
2018-04-15 06:30:04.996 [ DEBUG]:webui: Stop streaming /stream/mux/c4bc67bdaa13457e33740ca883cc4d75?ticket=7D1B56AD0E434C5F7EBFA4677A7FBE4C94097974, client hung up

It looks because tcp_socket_dead() misunderstood the zero-return
from recv(). For the FreeBSD, recv() might return zero for alive
sockets which have nothing to read.

Patch tested with the latest FreeBSD port of tvheadend-4.2.6.
---
src/tcp.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/tcp.c b/src/tcp.c
index 40f6c1c0cc..9b865eb292 100644
--- src/tcp.c
+++ src/tcp.c
@@ -453,8 +453,13 @@ tcp_socket_dead(int fd)
return -errno;
if (err)
return -err;
+#ifdef PLATFORM_FREEBSD
+ if (recv(fd, NULL, 0, MSG_PEEK | MSG_DONTWAIT) < 0)
+ return -errno;
+#else
if (recv(fd, NULL, 0, MSG_PEEK | MSG_DONTWAIT) == 0)
return -EIO;
+#endif
return 0;
}

0 comments on commit fd0b8ec

Please sign in to comment.