Skip to content

Commit

Permalink
Add a function to stop a RTSP server (#43)
Browse files Browse the repository at this point in the history
* Add a function to stop a RTSP server
  • Loading branch information
Noarkhh authored Aug 28, 2024
1 parent 4084f7a commit 1e0f75d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
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
16 changes: 16 additions & 0 deletions lib/membrane_rtsp/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ defmodule Membrane.RTSP.Server do
GenServer.start_link(__MODULE__, config, name: config[:name])
end

@doc """
Stops the RTSP server.
## Options
- `timeout` - timeout of the server termination, passed to `GenServer.stop/3`.
"""
@spec stop(pid(), timeout: timeout()) :: :ok
def stop(server, opts \\ []) do
timeout = Keyword.get(opts, :timeout, :infinity)
GenServer.stop(server, :normal, timeout)
end

@doc """
Get the port number of the server.
Expand Down Expand Up @@ -171,12 +183,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
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
"ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"},
"ex_sdp": {:hex, :ex_sdp, "0.15.0", "53815fb5b5e4fae0f3b26de90f372446bb8e0eed62a3cc20394d3c29519698be", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}], "hexpm", "d3f23596b73e7057521ff0f0d55b1189c6320a2f04388aa3a80a0aa97ffb379f"},
"ex_sdp": {:hex, :ex_sdp, "0.17.0", "4c50e7814f01f149c0ccf258fba8428f8567dffecf1c416ec3f6aaaac607a161", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}], "hexpm", "c7fe0625902be2a835b5fe6834a189f7db7639d2625c8e9d8b3564e6d704145f"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
Expand Down

0 comments on commit 1e0f75d

Please sign in to comment.