Skip to content

Commit e5f67e9

Browse files
authored
Merge pull request #2 from membraneframework-labs/varsill/fix_listen_callback_setting
Fix srt listen callback setting
2 parents b2b1345 + 77db53d commit e5f67e9

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

c_src/ex_libsrt/server/server.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ void Server::Run(const char* address, int port) {
2828
throw std::runtime_error(std::string(srt_getlasterror_str()));
2929
}
3030

31+
srt_listen_callback(srt_sock,
32+
(srt_listen_callback_fn*)&Server::ListenAcceptCallback,
33+
(void*)this);
3134
srt_bind_sock = srt_listen(srt_sock, MAX_PENDING_CONNECTIONS);
3235
if (srt_bind_sock == SRT_ERROR) {
3336
throw std::runtime_error(std::string(srt_getlasterror_str()));
@@ -41,10 +44,6 @@ void Server::Run(const char* address, int port) {
4144
const int read_modes = SRT_EPOLL_IN | SRT_EPOLL_ERR;
4245
srt_epoll_add_usock(epoll, srt_sock, &read_modes);
4346

44-
srt_listen_callback(srt_sock,
45-
(srt_listen_callback_fn*)&Server::ListenAcceptCallback,
46-
(void*)this);
47-
4847
running.store(true);
4948

5049
epoll_loop = std::thread(&Server::RunEpoll, this);

examples/server.exs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Mix.install([{:ex_libsrt, path: "../ex_libsrt"}])
2-
1+
Mix.install([{:ex_libsrt, path: "../"}])
32

43
defmodule Server do
54
use GenServer
@@ -19,7 +18,9 @@ defmodule Server do
1918

2019
@impl true
2120
def handle_info({:srt_server_connect_request, address, stream_id}, state) do
22-
Logger.info("Receiving new connection request with stream id: #{stream_id} from address: #{address}")
21+
Logger.info(
22+
"Receiving new connection request with stream id: #{stream_id} from address: #{address}"
23+
)
2324

2425
:ok = ExLibSRT.Server.accept_awaiting_connect_request(state.server)
2526

@@ -64,20 +65,15 @@ receive do
6465
end
6566

6667
# Process.sleep(2_000)
67-
#
6868
for _i <- 1..10_000 do
6969
payload = :crypto.strong_rand_bytes(1200)
70-
7170
:ok = ExLibSRT.Client.send_data(payload, client)
7271
end
7372

74-
75-
7673
Process.sleep(5000)
7774

7875
ExLibSRT.Client.stop(client)
7976

8077
Process.sleep(1000)
8178

8279
GenServer.stop(server)
83-

0 commit comments

Comments
 (0)