[erlang-questions] Unimplemented {buffer, integer()} option in ssl module - bug?

Richard Jones <>
Thu Dec 1 12:37:37 CET 2016


The {buffer, integer()} option from gen_tcp is useful for breaking up
incoming data into manageable sizes, especially when in {packet, line}
mode.

The docs suggest (kinda) that the gen_tcp options should also work
when connecting via the ssl module, but this isn't always the case -
the buffer option is silently ignored by ssl:connect.

Is this a bug? Tested on erl 17, 18, 19

Examples follow using netcat/socat as a server. Note that gen_tcp
breaks the incoming data into 3 messages, ssl delivers as one large
message.

Non-SSL example:
----------------

$ echo "12345678901234567890123" | nc -l 1234

1> {ok, _} = gen_tcp:connect("localhost", 1234, [
 binary,
 {packet, line},
 {buffer, 10},
 {active, true}]).

{ok,#Port<0.1180>}

2> flush().

Shell got {tcp,#Port<0.1180>,<<"1234567890">>}
Shell got {tcp,#Port<0.1180>,<<"1234567890">>}
Shell got {tcp,#Port<0.1180>,<<"123\n">>}
Shell got {tcp_closed,#Port<0.1180>}
ok

SSL example:
------------

$ echo "12345678901234567890123" | socat STDIO
OPENSSL-LISTEN:1234,reuseaddr,cert=/some.pem,cafile=/some.crt,verify=0

1> {ok, _} = ssl:connect("localhost", 1234, [
  binary,
  {packet, line},
  {buffer, 10},
  {active, true},
  {verify, verify_none}]).

{ok,{sslsocket,{gen_tcp,#Port<0.1179>,tls_connection,
                        undefined},
               <0.54.0>}}

2> flush().

Shell got {ssl,{sslsocket,{gen_tcp,#Port<0.1179>,tls_connection,undefined},
                          <0.54.0>},
               <<"12345678901234567890123\n">>}
Shell got {ssl_closed,
              {sslsocket,
                  {gen_tcp,#Port<0.1179>,tls_connection,undefined},
                  <0.54.0>}}
ok


More information about the erlang-questions mailing list