Commit b10eb7ae authored by Ole André Vadla Ravnås's avatar Ole André Vadla Ravnås Committed by Olivier Crête

iostream: Implement close() for ICE-TCP also

parent 462a3629
......@@ -393,6 +393,35 @@ nice_component_close (NiceAgent *agent, NiceStream *stream, NiceComponent *cmp)
cmp->rfc4571_buffer = NULL;
}
void
nice_component_shutdown (NiceComponent *component, gboolean shutdown_read,
gboolean shutdown_write)
{
GSList *i;
g_assert (shutdown_read || shutdown_write);
if (!pseudo_tcp_socket_is_closed (component->tcp)) {
PseudoTcpShutdown how;
if (shutdown_read && shutdown_write)
how = PSEUDO_TCP_SHUTDOWN_RDWR;
else if (shutdown_read)
how = PSEUDO_TCP_SHUTDOWN_RD;
else
how = PSEUDO_TCP_SHUTDOWN_WR;
pseudo_tcp_socket_shutdown (component->tcp, how);
}
for (i = component->socket_sources; i; i = i->next) {
SocketSource *source = i->data;
NiceSocket *sock = source->socket;
if (sock->type == NICE_SOCKET_TYPE_TCP_BSD)
g_socket_shutdown (sock->fileno, shutdown_read, shutdown_write, NULL);
}
}
/*
* Finds a candidate pair that has matching foundation ids.
*
......
......@@ -266,6 +266,10 @@ void
nice_component_close (NiceAgent *agent, NiceStream *stream,
NiceComponent *component);
void
nice_component_shutdown (NiceComponent *component, gboolean shutdown_read,
gboolean shutdown_write);
gboolean
nice_component_find_pair (NiceComponent *component, NiceAgent *agent,
const gchar *lfoundation, const gchar *rfoundation, CandidatePair *pair);
......
......@@ -333,7 +333,6 @@ nice_input_stream_close (GInputStream *stream, GCancellable *cancellable,
{
NiceInputStreamPrivate *priv = NICE_INPUT_STREAM (stream)->priv;
NiceComponent *component = NULL;
NiceStream *_stream = NULL;
NiceAgent *agent; /* owned */
/* Has the agent disappeared? */
......@@ -343,11 +342,10 @@ nice_input_stream_close (GInputStream *stream, GCancellable *cancellable,
agent_lock (agent);
/* Shut down the read side of the pseudo-TCP stream, if it still exists. */
if (agent_find_component (agent, priv->stream_id, priv->component_id,
&_stream, &component) && agent->reliable &&
!pseudo_tcp_socket_is_closed (component->tcp)) {
pseudo_tcp_socket_shutdown (component->tcp, PSEUDO_TCP_SHUTDOWN_RD);
/* Shut down the read side of the TCP stream, if it still exists. */
if (agent_find_component (agent, priv->stream_id, priv->component_id, NULL,
&component)) {
nice_component_shutdown (component, TRUE, FALSE);
}
agent_unlock (agent);
......
......@@ -477,7 +477,6 @@ nice_output_stream_close (GOutputStream *stream, GCancellable *cancellable,
{
NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
NiceComponent *component = NULL;
NiceStream *_stream = NULL;
NiceAgent *agent; /* owned */
/* Has the agent disappeared? */
......@@ -487,11 +486,10 @@ nice_output_stream_close (GOutputStream *stream, GCancellable *cancellable,
agent_lock (agent);
/* Shut down the write side of the pseudo-TCP stream. */
if (agent_find_component (agent, priv->stream_id, priv->component_id,
&_stream, &component) && agent->reliable &&
!pseudo_tcp_socket_is_closed (component->tcp)) {
pseudo_tcp_socket_shutdown (component->tcp, PSEUDO_TCP_SHUTDOWN_WR);
/* Shut down the write side of the TCP stream. */
if (agent_find_component (agent, priv->stream_id, priv->component_id, NULL,
&component)) {
nice_component_shutdown (component, FALSE, TRUE);
}
agent_unlock (agent);
......
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