rtmp2/connection: Handle EOF like error
authorJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>
Wed, 1 Dec 2021 14:53:13 +0000 (15:53 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 7 Nov 2022 12:31:08 +0000 (12:31 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1403>

subprojects/gst-plugins-bad/gst/rtmp2/rtmp/rtmpconnection.c

index d9af4d2..33f0a13 100644 (file)
@@ -474,6 +474,12 @@ gst_rtmp_connection_input_ready (GInputStream * is, gpointer user_data)
       sc->input_bytes->data + oldsize, READ_SIZE, sc->cancellable, &error);
   g_byte_array_set_size (sc->input_bytes, oldsize + (ret > 0 ? ret : 0));
 
+  if (ret == 0) {
+    error = g_error_new (G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED,
+        "connection closed remotely");
+    ret = -1;
+  }
+
   if (ret < 0) {
     gint code = error->code;
 
@@ -488,13 +494,9 @@ gst_rtmp_connection_input_ready (GInputStream * is, gpointer user_data)
 
     GST_ERROR_OBJECT (sc, "read error: %s %d %s",
         g_quark_to_string (error->domain), code, error->message);
-    g_error_free (error);
-  } else if (ret == 0) {
-    GST_INFO_OBJECT (sc, "read EOF");
-  }
 
-  if (ret <= 0) {
     gst_rtmp_connection_emit_error (sc);
+    g_error_free (error);
     return G_SOURCE_REMOVE;
   }
 
@@ -577,16 +579,11 @@ out:
 static void
 gst_rtmp_connection_emit_error (GstRtmpConnection * self)
 {
-  if (self->error) {
-    return;
+  if (!self->error) {
+    self->error = TRUE;
+    cancel_all_commands (self);
+    g_signal_emit (self, signals[SIGNAL_ERROR], 0);
   }
-
-  GST_INFO_OBJECT (self, "connection error");
-  self->error = TRUE;
-
-  cancel_all_commands (self);
-
-  g_signal_emit (self, signals[SIGNAL_ERROR], 0);
 }
 
 static void