Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
c9dd230a72
1 mainītis faili ar 10 papildinājumiem un 0 dzēšanām
  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)
 WriteN(RTMP *r, const char *buffer, int n)
 {
 {
     const char *ptr = buffer;
     const char *ptr = buffer;
+    struct linger l;
 
 
     while (n > 0)
     while (n > 0)
     {
     {
@@ -1591,6 +1592,15 @@ WriteN(RTMP *r, const char *buffer, int n)
 
 
             r->last_error_code = sockerr;
             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);
             RTMP_Close(r);
             n = 1;
             n = 1;
             break;
             break;