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