From b10eb7aefb62bd0f527035bc5c6b6381416f3a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Sat, 15 May 2021 22:20:40 +0200 Subject: iostream: Implement close() for ICE-TCP also --- agent/component.c | 29 +++++++++++++++++++++++++++++ agent/component.h | 4 ++++ agent/inputstream.c | 10 ++++------ agent/outputstream.c | 10 ++++------ 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/agent/component.c b/agent/component.c index a16cc9d..b19c50f 100644 --- a/agent/component.c +++ b/agent/component.c @@ -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. * diff --git a/agent/component.h b/agent/component.h index 7a78f10..1dcd57b 100644 --- a/agent/component.h +++ b/agent/component.h @@ -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); diff --git a/agent/inputstream.c b/agent/inputstream.c index eafac1b..b72e829 100644 --- a/agent/inputstream.c +++ b/agent/inputstream.c @@ -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); diff --git a/agent/outputstream.c b/agent/outputstream.c index 7fae413..8ff2b8a 100644 --- a/agent/outputstream.c +++ b/agent/outputstream.c @@ -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); -- cgit v1.2.1