Home > Erlang探索, 源码分析 > gen_tcp连接半关闭问题

gen_tcp连接半关闭问题

May 14th, 2013

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: gen_tcp连接半关闭问题

很久之前我发在javaeye论坛上,预防丢了抄过来:

原文:http://erlang.group.iteye.com/group/wiki/1422-gen_tcp-half-closed

当tcp对端调用shutdown(RD/WR) 时候, 宿主进程默认将收到{tcp_closed, Socket}消息, 如果这个行为不是你想要的,那么请看:

shutdown(Socket, How) -> ok | {error, Reason}
Types:
Socket = socket()
How = read | write | read_write
Reason = posix()

Immediately close a socket in one or two directions.
How == write means closing the socket for writing, reading from it is still possible.
To be able to handle that the peer has done a shutdown on the write side, the {exit_on_close, false} option is useful.

简单的设置inets:setopts(Socket, [{exit_on_close, false}]). 这样就不会被强制退出了。

祝玩得开心!

Post Footer automatically generated by wp-posturl plugin for wordpress.

Comments are closed.