mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-03 15:06:34 +00:00
tcp: Fix handling of closed connections
This commit is contained in:
parent
6d6593b757
commit
6cb38409d1
2 changed files with 38 additions and 22 deletions
|
@ -217,24 +217,32 @@ gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
avail = g_socket_get_available_bytes (src->socket);
|
avail = g_socket_get_available_bytes (src->socket);
|
||||||
if (avail <= 0)
|
if (avail < 0)
|
||||||
goto get_available_error;
|
goto get_available_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
read = MIN (avail, MAX_READ_SIZE);
|
if (avail > 0) {
|
||||||
*outbuf = gst_buffer_new_and_alloc (read);
|
read = MIN (avail, MAX_READ_SIZE);
|
||||||
data = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_READWRITE);
|
*outbuf = gst_buffer_new_and_alloc (read);
|
||||||
rret =
|
data = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_READWRITE);
|
||||||
g_socket_receive (src->socket, (gchar *) data, read,
|
rret =
|
||||||
src->cancellable, &err);
|
g_socket_receive (src->socket, (gchar *) data, read,
|
||||||
|
src->cancellable, &err);
|
||||||
|
} else {
|
||||||
|
/* Connection closed */
|
||||||
|
*outbuf = NULL;
|
||||||
|
rret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (rret == 0) {
|
if (rret == 0) {
|
||||||
GST_DEBUG_OBJECT (src, "Connection closed");
|
GST_DEBUG_OBJECT (src, "Connection closed");
|
||||||
ret = GST_FLOW_EOS;
|
ret = GST_FLOW_EOS;
|
||||||
gst_buffer_unmap (*outbuf, data, read);
|
if (*outbuf) {
|
||||||
gst_buffer_unref (*outbuf);
|
gst_buffer_unmap (*outbuf, data, read);
|
||||||
|
gst_buffer_unref (*outbuf);
|
||||||
|
}
|
||||||
*outbuf = NULL;
|
*outbuf = NULL;
|
||||||
} else if (ret < 0) {
|
} else if (rret < 0) {
|
||||||
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||||
ret = GST_FLOW_WRONG_STATE;
|
ret = GST_FLOW_WRONG_STATE;
|
||||||
GST_DEBUG_OBJECT (src, "Cancelled reading from socket");
|
GST_DEBUG_OBJECT (src, "Cancelled reading from socket");
|
||||||
|
@ -274,7 +282,7 @@ select_error:
|
||||||
get_available_error:
|
get_available_error:
|
||||||
{
|
{
|
||||||
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
||||||
("Select to get available bytes from socket"));
|
("Failed to get available bytes from socket"));
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
}
|
}
|
||||||
wrong_state:
|
wrong_state:
|
||||||
|
|
|
@ -212,24 +212,32 @@ gst_tcp_server_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
avail = g_socket_get_available_bytes (src->client_socket);
|
avail = g_socket_get_available_bytes (src->client_socket);
|
||||||
if (avail <= 0)
|
if (avail < 0)
|
||||||
goto get_available_error;
|
goto get_available_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
read = MIN (avail, MAX_READ_SIZE);
|
if (avail > 0) {
|
||||||
*outbuf = gst_buffer_new_and_alloc (read);
|
read = MIN (avail, MAX_READ_SIZE);
|
||||||
data = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_READWRITE);
|
*outbuf = gst_buffer_new_and_alloc (read);
|
||||||
rret =
|
data = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_READWRITE);
|
||||||
g_socket_receive (src->client_socket, (gchar *) data, read,
|
rret =
|
||||||
src->cancellable, &err);
|
g_socket_receive (src->client_socket, (gchar *) data, read,
|
||||||
|
src->cancellable, &err);
|
||||||
|
} else {
|
||||||
|
/* Connection closed */
|
||||||
|
rret = 0;
|
||||||
|
*outbuf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (rret == 0) {
|
if (rret == 0) {
|
||||||
GST_DEBUG_OBJECT (src, "Connection closed");
|
GST_DEBUG_OBJECT (src, "Connection closed");
|
||||||
ret = GST_FLOW_EOS;
|
ret = GST_FLOW_EOS;
|
||||||
gst_buffer_unmap (*outbuf, data, MAX_READ_SIZE);
|
if (*outbuf) {
|
||||||
gst_buffer_unref (*outbuf);
|
gst_buffer_unmap (*outbuf, data, MAX_READ_SIZE);
|
||||||
|
gst_buffer_unref (*outbuf);
|
||||||
|
}
|
||||||
*outbuf = NULL;
|
*outbuf = NULL;
|
||||||
} else if (ret < 0) {
|
} else if (rret < 0) {
|
||||||
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||||
ret = GST_FLOW_WRONG_STATE;
|
ret = GST_FLOW_WRONG_STATE;
|
||||||
GST_DEBUG_OBJECT (src, "Cancelled reading from socket");
|
GST_DEBUG_OBJECT (src, "Cancelled reading from socket");
|
||||||
|
@ -285,7 +293,7 @@ select_error:
|
||||||
get_available_error:
|
get_available_error:
|
||||||
{
|
{
|
||||||
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
||||||
("Select to get available bytes from socket"));
|
("Failed to get available bytes from socket"));
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue