[Bug 785684] rtspconnection: add API to send messages without blocking

GStreamer (GNOME Bugzilla) bugzilla at gnome.org
Tue Oct 24 14:40:31 UTC 2017


https://bugzilla.gnome.org/show_bug.cgi?id=785684

--- Comment #19 from Branko Subasic <branko.subasic at axis.com> ---
(In reply to Tim-Philipp Müller from comment #18)
> > Regarding the while loop, g_socket_send_message() behaves in a similar way.
> > If sendmsg() returns an error it will try again. However, if sendmsg()
> > manages to write a part of the data then g_socket_send_message() will not
> > try to write the rest. It will simply return the number of bytes written.
> > Thus the handling of partial writes in the while loop.
> 
> This is when the socket is in non-blocking mode, correct?
> 
> But when you set it to blocking mode, surely it will retry and loop until it
> has sent out all messages? (Or there's an error)

Nope, unless I misunderstand the code, as soon sendmsg() returns a value >= 0
g_socket_send_message() will return that value. Which I found a bit surprising.
I had expected it to retry until all data was written, or a fatal error
occured.

> 
> > Unfortunately I discovered that while handling partial writes the new
> > function changes the GOutputVectors that it gets as in-parameter. This may
> > lead to weird behavior if the caller e.g. needs to de-allocate the data
> > chunks.
> 
> Why is that? Not sure I understand the problem here. Could you explain?

The code here is from the function. vecs is the GOutputVector array. 

    ...
    /* recalculate to deal with partial writes */
    while (num_written > 0) {
      if (num_written < vecs[i].size) {
        vecs[i].buffer = (gchar *) vecs[i].buffer + num_written;
        vecs[i].size -= num_written;
        num_written = 0;
      } else {
    ...

If sendmsg() failed to write all data of an GOutputVector we will end up in the
if-statement. There the buffer-pointer and the size of that GOutputVector is
modified, meaning that vecs[i].buffer no longer points to the same address that
it pointed to when the call was made.

In my unit test the GOutputVector I pass to gst_rtsp_connection_write_vectors()
points to malloc():ed data. After returning from the call the test deallocates
the data, which gives funny errors when the pointers no longer points to the
beginning of the malloc():ed data.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
You are the assignee for the bug.


More information about the gstreamer-bugs mailing list