[erlang-questions] EPIPE and TCP sockets

Bruce Fitzsimons bruce@REDACTED
Fri Oct 12 01:29:41 CEST 2007


Tony Garnock-Jones wrote:
> <snip>
> Is there a way of getting gen_tcp to let me know if a send is not fully 
> completed at the time of socket close? (My initial experiments lead me 
> to believe the answer is "no", and inspecting .../common/inet_drv.c's 
> use of EPIPE tends to support that conclusion.)
>
> The goal here is to be able to use TCP's reliable-delivery feature to 
> get told if the socket closes while unacknowledged sent data exists.
>
>   
I saw the same sort of issue in a rant against the jabber/XMPP protocol; 
it treats TCP as "reliable" in an application to application sense. TCP 
isn't, although 99% of the time it is probably close enough. See 
http://about.psyc.eu/Jabber#Closing_Idle_Connections  I'd still like to 
use the SCTP support in Erlang to demonstrate XMPP over SCTP and see 
what sort of improvements it might give, but time/motivation prevents 
me. I don't think it would be a magical fix, but the auto-heartbeating 
alone would be an improvement. Anyway I've drifted off-topic :-)

There is a way using getsockopt to find out if there is a tcp buffer of 
unsent/un-acked data, but I believe it is *linux-specific* (ah, TCP_INFO 
returns struct tcp_info. See /usr/include/linux/tcp.h). If that isn't a 
problem for your application it would appear (completely untested) then 
you can use inet:getopts to invoke this. I've also seen an ioctl that 
can get this information but again it is non-standard.

Cheers,
Bruce





More information about the erlang-questions mailing list