rtspconnection: Update to merged GOutputStream::writev() API

This commit is contained in:
Sebastian Dröge 2019-01-24 17:52:50 +02:00
parent 8a54cc3b16
commit 3a0e7fb8f4

View file

@ -1229,7 +1229,11 @@ error:
if (G_UNLIKELY (r == 0)) if (G_UNLIKELY (r == 0))
return GST_RTSP_EEOF; return GST_RTSP_EEOF;
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
GST_WARNING ("%s", err->message);
else
GST_DEBUG ("%s", err->message); GST_DEBUG ("%s", err->message);
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_clear_error (&err); g_clear_error (&err);
return GST_RTSP_EINTR; return GST_RTSP_EINTR;
@ -1245,10 +1249,7 @@ error:
} }
} }
/* NOTE: This changes the values of vectors if multiple iterations are needed! /* NOTE: This changes the values of vectors if multiple iterations are needed! */
*
* Depends on https://gitlab.gnome.org/GNOME/glib/merge_requests/333
*/
#if GLIB_CHECK_VERSION(2, 59, 0) #if GLIB_CHECK_VERSION(2, 59, 0)
static GstRTSPResult static GstRTSPResult
writev_bytes (GOutputStream * stream, GOutputVector * vectors, gint n_vectors, writev_bytes (GOutputStream * stream, GOutputVector * vectors, gint n_vectors,
@ -1257,23 +1258,30 @@ writev_bytes (GOutputStream * stream, GOutputVector * vectors, gint n_vectors,
gsize _bytes_written = 0; gsize _bytes_written = 0;
gsize written; gsize written;
GError *err = NULL; GError *err = NULL;
GPollableReturn res = G_POLLABLE_RETURN_OK;
while (n_vectors > 0) { while (n_vectors > 0) {
gboolean res; if (block) {
if (G_UNLIKELY (!g_output_stream_writev (stream, vectors, n_vectors,
if (block) &written, cancellable, &err))) {
res = g_output_stream_writev (stream, vectors, n_vectors, &written, /* This will never return G_IO_ERROR_WOULD_BLOCK */
cancellable, &err); res = G_POLLABLE_RETURN_FAILED;
else goto error;
}
} else {
res = res =
g_pollable_output_stream_writev_nonblocking (G_POLLABLE_OUTPUT_STREAM g_pollable_output_stream_writev_nonblocking (G_POLLABLE_OUTPUT_STREAM
(stream), vectors, n_vectors, &written, cancellable, &err); (stream), vectors, n_vectors, &written, cancellable, &err);
_bytes_written += written;
if (G_UNLIKELY (!res || written == 0)) if (res != G_POLLABLE_RETURN_OK) {
g_assert (written == 0);
goto error; goto error;
}
}
_bytes_written += written;
/* skip vectors that have been written in full */ /* skip vectors that have been written in full */
while (written >= vectors[0].size) { while (written > 0 && written >= vectors[0].size) {
written -= vectors[0].size; written -= vectors[0].size;
++vectors; ++vectors;
--n_vectors; --n_vectors;
@ -1296,11 +1304,11 @@ error:
*bytes_written = _bytes_written; *bytes_written = _bytes_written;
if (err) if (err)
GST_DEBUG ("%s", err->message); GST_WARNING ("%s", err->message);
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { if (res == G_POLLABLE_RETURN_WOULD_BLOCK) {
g_clear_error (&err); g_assert (!err);
return GST_RTSP_EINTR; return GST_RTSP_EINTR;
} else if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { } else if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_clear_error (&err); g_clear_error (&err);
return GST_RTSP_EINTR; return GST_RTSP_EINTR;
} else if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)) { } else if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)) {