diff options
author | Ole André Vadla Ravnås <oleavr@gmail.com> | 2021-05-15 22:20:40 +0200 |
---|---|---|
committer | Olivier Crête <olivier.crete@ocrete.ca> | 2021-11-22 21:53:08 +0000 |
commit | b10eb7aefb62bd0f527035bc5c6b6381416f3a9e (patch) | |
tree | 9ce007465154e0b24b49483bf75543f7b505241e | |
parent | 462a36298246aa678bbe62f8b24d56a457bb1f63 (diff) | |
download | libnice-b10eb7aefb62bd0f527035bc5c6b6381416f3a9e.tar.gz |
iostream: Implement close() for ICE-TCP also
-rw-r--r-- | agent/component.c | 29 | ||||
-rw-r--r-- | agent/component.h | 4 | ||||
-rw-r--r-- | agent/inputstream.c | 10 | ||||
-rw-r--r-- | 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); |