Skip to content

Commit 3d42bd5

Browse files
committed
Build the 'examples' using rebar3
1 parent bcfb113 commit 3d42bd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+196
-546
lines changed
Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
1+
## active_n
12

2-
## TCP Window Full
3+
Benchmark the `{active, N}` and `async_recv`.
4+
5+
```
6+
recv_eprof:start(Port = 6000, async_recv, 10000).
7+
8+
recv_eprof:start(Port = 5000, active_n, 10000).
9+
```
10+
11+
## async_recv
12+
13+
## client
14+
15+
TCP echo client.
16+
17+
## dtls
18+
19+
The DTLS echo server which listens on port 5000.
20+
21+
Start a DTLS client:
22+
23+
```
24+
openssl s_client -dtls1 -connect 127.0.0.1:5000 -debug
25+
```
26+
27+
## dtls_psk
28+
29+
The DTLS echo server which listens on port 5000.
30+
31+
Start a DTLS client:
32+
```
33+
Client = dtls_psk_client:connect().
34+
dtls_psk_client:send(Client, <<"hi">>).
35+
```
36+
37+
## gen_server
38+
39+
## plain
40+
41+
## proxy_protocol
42+
43+
## simple
44+
45+
## ssl
46+
47+
Start the SSL echo server which listens on port 5000:
48+
49+
```
50+
ssl_echo_server:start(5000).
51+
```
52+
53+
Start a SSL client:
54+
```
55+
openssl s_client -tls1 -debug -connect 127.0.0.1:5000
56+
```
57+
58+
## tcp_window
59+
60+
`rebar3 shell` and run `tcp_window` test:
61+
62+
```
63+
tcp_window:start(5000, sync).
64+
tcp_window:start(5000, async).
65+
tcp_window:start(5000, async_force).
66+
tcp_window:start(5000, async_nosuspend).
67+
```
68+
69+
TCP Window Full:
370

471
Send Function | Socket Options | TCP Window full
572
----------------------------------------|--------------------------|-------------------------------------------
@@ -12,8 +79,16 @@ port_command(Socket, Data) | {send_timeout, 5000} | Return true
1279
port_command(Socket, Data, [force]) | {send_timeout, 5000} | Return true always. Write to TCP Stack.
1380
port_command(Socket, Data, [nosuspend]) | {send_timeout, 5000} | Return false first, and true after timeout. Drop the packets silently.
1481

15-
## Conclusions
82+
Conclusions:
1683

1784
1. Should set the `send_timeout` option if using `gen_tcp:send`
1885
2. Should not set the `nosuspend` option if using `port_command`, for the busy sock will be killed at once.
1986

87+
## udp
88+
89+
Start the UDP echo server which listens on port 5000.
90+
91+
```
92+
udp_echo_server:start(5000).
93+
```
94+

examples/active_n/README

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/async_recv/Makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/async_recv/src/async_recv_echo_server.erl renamed to examples/async_recv/async_recv_echo_server.erl

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,41 @@
1717
%% @doc Async Recv Echo Server.
1818
-module(async_recv_echo_server).
1919

20-
-include("../../../include/esockd.hrl").
20+
-include("esockd.hrl").
2121

2222
-behaviour(gen_server).
2323

2424
%% start
25-
-export([start/0, start/1]).
25+
-export([start/1]).
2626

2727
-export([start_link/2]).
2828

2929
%% gen_server Function Exports
30-
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
31-
terminate/2, code_change/3]).
30+
-export([ init/1
31+
, handle_call/3
32+
, handle_cast/2
33+
, handle_info/2
34+
, terminate/2
35+
, code_change/3
36+
]).
3237

3338
-record(state, {transport, socket}).
3439

35-
start() -> start(5000).
36-
start([Port]) when is_atom(Port) ->
37-
start(list_to_integer(atom_to_list(Port)));
38-
start(Port) when is_integer(Port) ->
39-
[{ok, _} = application:ensure_all_started(App)
40-
|| App <- [crypto, ssl, esockd]],
40+
start(Port) ->
41+
ok = esockd:start(),
4142
TcpOpts = [binary,
4243
{reuseaddr, true},
4344
{backlog, 512},
44-
{nodelay, false}],
45+
{nodelay, false}
46+
],
4547
SslOpts = [{certfile, "./crt/demo.crt"},
46-
{keyfile, "./crt/demo.key"}],
48+
{keyfile, "./crt/demo.key"}
49+
],
4750
Options = [{acceptors, 8},
4851
{max_connections, 100000},
4952
{tcp_options, TcpOpts},
50-
{ssl_options, SslOpts}],
53+
{ssl_options, SslOpts}
54+
],
5155
MFArgs = {?MODULE, start_link, []},
5256
esockd:open(echo, Port, Options, MFArgs).
5357

examples/async_recv/run

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/async_recv/src/async_recv_echo_server.app.src

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/client/Makefile

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/client/client.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717
%% @doc Echo test client
1818
-module(echo_client).
1919

20-
-export([start/1, start/3, send/2, run/4, connect/4, loop/2]).
20+
-export([start/3, send/2, run/4, connect/4, loop/2]).
2121

2222
-define(TCP_OPTIONS, [binary, {packet, raw}, {active, true}]).
2323

24-
%%shell
25-
start([Host, Port, Num]) when is_atom(Host), is_atom(Port), is_atom(Num) ->
26-
start(atom_to_list(Host), a2i(Port), a2i(Num)).
27-
2824
start(Host, Port, Num) ->
2925
spawn(?MODULE, run, [self(), Host, Port, Num]),
3026
mainloop(1).
@@ -72,5 +68,3 @@ loop(Num, Sock) ->
7268
send(N, Sock) ->
7369
gen_tcp:send(Sock, [integer_to_list(N), ":", <<"Hello, eSockd!">>]).
7470

75-
a2i(A) -> list_to_integer(atom_to_list(A)).
76-

examples/client/src/echo_client.app.src

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)