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

Add a function to stop a RTSP server #43

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ of dependencies in `mix.exs`:
```elixir
def deps do
[
{:membrane_rtsp, "~> 0.8.0"}
{:membrane_rtsp, "~> 0.9.0"}
]
end
```
Expand Down
12 changes: 12 additions & 0 deletions lib/membrane_rtsp/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ defmodule Membrane.RTSP.Server do
GenServer.start_link(__MODULE__, config, name: config[:name])
end

@doc """
Same as `GenServer.stop/2`
"""
@spec stop(pid(), reason :: term(), timeout()) :: :ok
def stop(server, reason \\ :normal, timeout \\ :infinity) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need the reason argument. I'd also accept a keyword to make it more future-proof

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the signature of GenServer.stop/2

Copy link
Member

@mat-hek mat-hek Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's the point :P GenServer is generic and RTSP server is not. You don't have RTSPServer.call. I admit it's not a big deal though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the keyword would include fields like reason and timeout and also give us ability to add some options later, yes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to put the reason there :P So it would be just timeout for now

and also give us ability to add some options later

yeah, without having many default arguments

GenServer.stop(server, reason, timeout)
end

@doc """
Get the port number of the server.

Expand Down Expand Up @@ -171,12 +179,16 @@ defmodule Membrane.RTSP.Server do
{:noreply, state}
end

@spec do_listen(:gen_tcp.socket(), pid()) :: :ok
defp do_listen(socket, parent_pid) do
case :gen_tcp.accept(socket) do
{:ok, client_socket} ->
send(parent_pid, {:new_connection, client_socket})
do_listen(socket, parent_pid)

{:error, :closed} ->
:ok

{:error, reason} ->
raise("error occurred when accepting client connection: #{inspect(reason)}")
end
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Membrane.RTSP.MixProject do
use Mix.Project

@version "0.8.0"
@version "0.9.0"
@github_url "https://github.com/membraneframework/membrane_rtsp"

def project do
Expand Down Expand Up @@ -112,7 +112,7 @@ defmodule Membrane.RTSP.MixProject do
defp deps do
[
{:bunch, "~> 1.6"},
{:ex_sdp, "~> 0.15.0"},
{:ex_sdp, "~> 0.17.0"},
{:nimble_parsec, "~> 1.4.0", runtime: false},
{:dialyxir, "~> 1.1", only: [:dev], runtime: false},
{:mockery, "~> 2.3", runtime: false},
Expand Down
Loading