Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure closing connection on eos #9

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/membrane_tcp/sink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ defmodule Membrane.TCP.Sink do
Already connected TCP socket, if provided will be used instead of creating
and connecting a new one.
"""
],
close_on_eos: [
spec: boolean(),
default: true,
description: """
Automatically close connection on end-of-stream.
"""
]

def_input_pad :input, accepted_format: _any
Expand All @@ -61,7 +68,8 @@ defmodule Membrane.TCP.Sink do
%{
connection_side: connection_side,
local_socket: local_socket,
remote_socket: remote_socket
remote_socket: remote_socket,
close_on_eos: opts.close_on_eos
}}
end

Expand All @@ -85,7 +93,11 @@ defmodule Membrane.TCP.Sink do

@impl true
def handle_end_of_stream(_pad, _context, state) do
local_socket = Socket.close(state.local_socket)
{[], %{state | local_socket: local_socket}}
if state.close_on_eos do
local_socket = Socket.close(state.local_socket)
{[], %{state | local_socket: local_socket}}
else
{[], state}
end
end
end
Loading