[Spice-devel] [PATCH spice-gtk V3 1/3] file-xfer: handling various transfer messages in main channel

Marc-André Lureau mlureau at redhat.com
Tue Dec 18 03:50:34 PST 2012


Hi

----- Mensaje original -----
> >> +static gboolean send_data(gpointer opaque)
> >> +{
> >> +#define FILE_XFER_CHUNK_SIZE (VD_AGENT_MAX_DATA_SIZE -
> >> sizeof(VDAgentMessage))
> >> +    SpiceFileXferTask *task = (SpiceFileXferTask *)opaque;
> >> +
> >> +    SpiceMainChannel *channel =
> >> SPICE_MAIN_CHANNEL(task->channel);
> >> +    SpiceMainChannelPrivate *c = channel->priv;
> >> +    gssize len;
> >> +    GError *error = NULL;
> >> +    VDAgentFileXferDataMessage *msg;
> >> +    uint32_t msg_size;
> >> +
> >> +    if (!g_queue_is_empty(c->agent_msg_queue)) {
> >> +        spice_channel_wakeup(SPICE_CHANNEL(channel), FALSE);
> >> +        return TRUE;
> >
> >
> > You can't use Idle functions this way, you are going to busy-loop.
> > You need
> > to handle filling the queue differently.
> >
> I  knew this way is not good, but I cant find a better way to handle
> it. What about using g_io_scheduler_push_job() to fill data into msg
> queue.
> e.g.:
> 
> // gio thread context
> static gboolean send_data()
> {
>     // code
> 
>     for (;;) {
>         if (agent msg queue is not empty) {
>             // wait for 1ms until msg queue become empty, so that
>             other messages
>             // can still get through.
>             usleep(1000);
>             continue;
>         }

Why not call spice_channel_flush_async() and wait for the channel data to be sent? I think that could do the trick.


More information about the Spice-devel mailing list