[erlang-questions] ssl:shutdown(Socket, write) unexpected behavior?
Jay Doane
jay@REDACTED
Thu Jun 9 01:25:19 CEST 2016
I'm working on an erlang network file copier that should be able to
use either tcp or ssl, depending on its configuration.
The basic idea is that it listens on a specified port, and writes
anything it receives to a file, then with the *same* connection,
responds to the sender with some statistics, and finally closes the
connection. A demonstration version can be found here:
https://gist.github.com/jaydoane/65dc6b005788af3c49e2866ea7d03f09
For basic tcp, this can be achieved by the sender doing a
gen_tcp:shutdown(Socket, write) after sending the payload, which -- if
the receiving socket is configured with {exit_on_close, false} --
closes the connection in the sending direction, but leaves it open to
receive the response. For example, this test works:
1> netcopy:test(tcp).
Response #{bytecount => 393,checksum => 3827135813,path => "/tmp/netcp"}
ok
Unfortunately, trying to use ssl:shutdown/2 [1] in the same way seems to
close the connection for both writing and reading, and therefore the
attempt to use ssl:recv/3 fails:
2> netcopy:test(ssl).
Generating a 2048 bit RSA private key
................................................................+++
.................+++
writing new private key to '/tmp/netcopy/key.pem'
-----
=ERROR REPORT==== 8-Jun-2016::23:13:26 ===
Error in process <0.621.0> with exit value:
{{badmatch,{error,closed}},
[{netcopy,listen,4,[{file,"netcopy.erl"},{line,38}]}]}
** exception error: no match of right hand side value {error,closed}
in function netcopy:sendfile/5 (netcopy.erl, line 88)
in call from netcopy:test/1 (netcopy.erl, line 172)
After some research [2], I thought the problem might be related to using
a Mac, but I've gotten the same results on Ubuntu 14.04. I've also
seen this both with otp 18.3 and 19.0-rc2.
Is this possible to do using ssl?
Thanks,
Jay
[1] http://erlang.org/doc/man/ssl.html#shutdown-2
[2] https://docs.python.org/2/library/socket.html#socket.socket.shutdown
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160608/9ce0d725/attachment.htm>
More information about the erlang-questions
mailing list