[Nice] Sending data but not receiving the last part.

Youness Alaoui youness.alaoui at collabora.co.uk
Fri Sep 14 16:40:32 PDT 2012


First, you connect to the writable signal, then you do the candidate exchange
and you wait, you only start transferring after you receive the writable signal
(you must ignore the component state change because even if the connection is
established, it doesn't mean that the pseudotcp connection has been established
Once you get the writable event, then you can start sending data, and yes, you
can send it from within the callback and no, it will not fire the writable
signal right after the nice_agent_send.
Once you receive the writable signal, then you can send data as long as you
want, the signal will *not* be fired again, it is fired only once!! BUT, as soon
as you call nice_agent_send and the return value is less than the length you
wanted to size, THEN the writable signal will be sent again.
In other words :
is_writable = FALSE;
g_signal_connect(agent, "reliable-transport-writable", writable_cb);

static void
writable_cb ()
  writable = TRUE;
  while (need_to_send_data) {
     ret = nice_agent_send(agent, buffer, size);
     if (ret >= 0 && ret < size) {
        writable = FALSE;

You can either keep track of whether or not the agent is writable or not, or you
can just try to send and see if it returns 0 or <= len...

Just to make sure you understand, internally, inside libnice, the writable
signal is enabled ONLY in two cases :
1 - the initial connection gets established
2 - after a nice_agent_send has been called and the return is 0 or <= len
If one of these conditions doesn't happen, then the agent will not send a new
writable signal (this is to prevent flooding the CPU of signal emition that is
useless, so it only gets sent if there is a need for it)

Hope that helps,

On 09/14/2012 05:49 PM, Federico Kouyoumdjian wrote:
>>> I'm having problems with the send of a file, I get almost all the file (~185KB),
>>> but at the end I don receive the last part,
>>> I'm using a reliable agent to transfer the file, the sender send all the pieces,
>>> but the receiver don't get the last part, can it be because I have some info in
>>> some buffer in the agent that I need to flush (in this case, how I do the flush)
>>> or may be because other issue?
>> Make sure the nice_agent_send doesn't return a length inferior to the requested
>> size (in which case, you have to wait for the writable signal before sending the
>> last part).
>> As for flushing, no, there is no way of doing a flush. Even if there was an API
>> for it, it wouldn't work, if you flush and you unref right away, there is no way
>> to ensure the flush happened because it's over UDP, and if the agent is
>> destroyed, it can't syn/ack/retransmit/etc..
>>> We are doing an unref ("g_object_unref(data->agent);") of the agent in the
>>> sender, but the agent in the receiver side don't change state,
>> Yeah, if the unref destroys the agent, then it might not have had time to flush
>> (it does try to flush, but the socket might not have time to do send the data
>> before it gets closed).
>> As for the other side not going into FAILED state, it's because it will
>> periodically send connchecks to ensure it's still open and you'd have to wait
>> about 30 seconds before it detects that the connection dropped.
>> My suggestion for your problem is to simply put a timer after completion before
>> closing the agent.. like, unref the agent 30 seconds after sending/receiving the
>> file...
> Thanks for the response. I've been trying different approaches but instead of
> getting better now the nice transmission stops at the beginning. Now I know that
> I have to wait for the writable callback to try to send the remaining data
> again. But I don't know where to send the remaining data again. Is the writeable
> callback only supposed to change the value of a flag "writable" or I have to do
> the send inside the writable callback? If the writable callback is fired
> immediately after the nice_agent_send finishes execution how do I know inside
> the callback which was the return of the nice_agent_send? Is there an example
> that I can check online in the web because the only one I found was this
> material tp://nice.freedesktop.org/libnice/NiceAgent.html
> http://nice.freedesktop.org/libnice/NiceAgent.html#nice-agent-send
> http://nice.freedesktop.org/libnice/NiceAgent.html#NiceAgent-reliable-transport-writable
> but I still can't understand exactly how it works.
> Thanks in advance.
> _______________________________________________
> nice mailing list
> nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/nice/attachments/20120914/28f71325/attachment.pgp>

More information about the nice mailing list