浏览代码

obs-outputs: Explicitly close RTMP socket on send error

Some send() errors are not treated as fatal but the connection gets shut
down regardless. When this happens, librtmp may send an FCunpublish
message which various services interpret as an "end of stream" message
and disable features like "disconnect protection". Instead, let's
explicitly close the socket so that the remote end is aware that this is
an unclean disconnect.
Richard Stanway 2 年之前
父节点
当前提交
c9dd230a72
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      plugins/obs-outputs/librtmp/rtmp.c

+ 10 - 0
plugins/obs-outputs/librtmp/rtmp.c

@@ -1567,6 +1567,7 @@ static int
 WriteN(RTMP *r, const char *buffer, int n)
 {
     const char *ptr = buffer;
+    struct linger l;
 
     while (n > 0)
     {
@@ -1591,6 +1592,15 @@ WriteN(RTMP *r, const char *buffer, int n)
 
             r->last_error_code = sockerr;
 
+            // Force-close the socket. Sometimes a send() error isn't fatal, so
+            // we could end up writing an unpublish message which some services
+            // treat as a clean shutdown. We need to disable lingering too so
+            // the remote side sees an abortive shutdown (RST).
+            l.l_onoff = 1;
+            l.l_linger = 0;
+            setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l));
+            RTMPSockBuf_Close(&r->m_sb);
+
             RTMP_Close(r);
             n = 1;
             break;