Commit 7523b49b authored by Dafydd Harries's avatar Dafydd Harries

nice_agent_main_context_attach (): use struct to move lookups to setup time...

nice_agent_main_context_attach (): use struct to move lookups to setup time rather than callback time

darcs-hash:20070215221125-c9803-ebd2eb69dee014fcc6fde03f1a6ece97b1b7ec93.gz
parent a31f3f3e
...@@ -1192,6 +1192,42 @@ nice_agent_dispose (GObject *object) ...@@ -1192,6 +1192,42 @@ nice_agent_dispose (GObject *object)
} }
typedef struct _IOCtx IOCtx;
struct _IOCtx
{
NiceAgent *agent;
Stream *stream;
Component *component;
NiceCandidate *candidate;
};
static IOCtx *
io_ctx_new (
NiceAgent *agent,
Stream *stream,
Component *component,
NiceCandidate *candidate)
{
IOCtx *ctx;
ctx = g_slice_new0 (IOCtx);
ctx->agent = agent;
ctx->stream = stream;
ctx->component = component;
ctx->candidate = candidate;
return ctx;
}
static void
io_ctx_free (IOCtx *ctx)
{
g_slice_free (IOCtx, ctx);
}
static gboolean static gboolean
nice_agent_g_source_cb ( nice_agent_g_source_cb (
GIOChannel *source, GIOChannel *source,
...@@ -1201,28 +1237,20 @@ nice_agent_g_source_cb ( ...@@ -1201,28 +1237,20 @@ nice_agent_g_source_cb (
{ {
/* return value is whether to keep the source */ /* return value is whether to keep the source */
NiceAgent *agent = data; IOCtx *ctx = data;
NiceCandidate *candidate; NiceAgent *agent = ctx->agent;
Stream *stream; Stream *stream = ctx->stream;
Component *component; Component *component = ctx->component;
NiceCandidate *candidate = ctx->candidate;
gchar buf[1024]; gchar buf[1024];
guint len; guint len;
candidate = _local_candidate_lookup_by_fd (agent, len = _nice_agent_recv (agent, stream, component, candidate, 1024,
g_io_channel_unix_get_fd (source)); buf);
if (candidate == NULL)
return TRUE;
if (!_component_lookup (agent, candidate->stream_id,
candidate->component_id, &stream, &component))
return TRUE;
len = _nice_agent_recv (agent, stream, component, candidate, 1024, buf);
if (len > 0) if (len > 0)
agent->read_func (agent, stream->id, component->id, len, buf, agent->read_func (agent, candidate->stream_id, candidate->component_id,
agent->read_func_data); len, buf, agent->read_func_data);
return TRUE; return TRUE;
} }
...@@ -1248,12 +1276,20 @@ nice_agent_main_context_attach ( ...@@ -1248,12 +1276,20 @@ nice_agent_main_context_attach (
NiceCandidate *candidate = i->data; NiceCandidate *candidate = i->data;
GIOChannel *io; GIOChannel *io;
GSource *source; GSource *source;
Stream *stream;
Component *component;
IOCtx *ctx;
if (!_component_lookup (agent, candidate->stream_id,
candidate->component_id, &stream, &component))
continue;
io = g_io_channel_unix_new (candidate->sock.fileno); io = g_io_channel_unix_new (candidate->sock.fileno);
source = g_io_create_watch (io, G_IO_IN); source = g_io_create_watch (io, G_IO_IN);
ctx = io_ctx_new (agent, stream, component, candidate);
g_source_set_callback (source, (GSourceFunc) nice_agent_g_source_cb, g_source_set_callback (source, (GSourceFunc) nice_agent_g_source_cb,
agent, NULL); ctx, (GDestroyNotify) io_ctx_free);
g_source_attach (source, ctx); g_source_attach (source, NULL);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment