[erlang-questions] gen_tcp not correctly handling half duplex(shutdown) sockets?

Paulo Sérgio Almeida <>
Thu Dec 20 01:08:23 CET 2007


Hi,

to be able to keep sending after the other side has made a half-close 
you need to pass {exit_on_close, false} while creating the listening socket.

I include an example that works (at least with "active" sockets). This 
"adder" server keeps adding numbers received until the client 
half-closes the connection, and then replies with the sum of all numbers 
received so far.

Regards,
psa

P.S. In case someone has spare time to comment ... does my code use 
binaries efficiently assuming R12B?

Scott R Parish wrote:
> Its not clear to me if i'm doing something wrong, or if gen_tcp isn't
> correctly handling half duplex sockets. As a refresher, half duplex
> sockets are created when shutdown(2) is called on a socket to close one
> direction:
> 
>   http://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-2.html#ss2.6
> 
> My erlang code is acting as follows:
> 
> maple% erl
> Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0] [hipe]
> [kernel-poll:false]
> 
> Eshell V5.5.5  (abort with ^G)
> 1> Opts = [binary, {packet, raw}, {active, false}].
> [binary,{packet,raw},{active,false}]
> 2> {ok, LS} = gen_tcp:listen(6000, Opts).

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: adder.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071220/b3d25060/attachment.ksh>


More information about the erlang-questions mailing list