diff options
author | Loïc Hoguin <[email protected]> | 2013-12-07 16:20:30 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-12-07 16:20:30 +0100 |
commit | c331076bad75ed89ff01c67d9e2c12688da7cc10 (patch) | |
tree | ed68d8e36537c9a867bbe23205abdef53e344777 | |
parent | 20a48ce65e0f14898e5027df080ec01813c1feb0 (diff) | |
download | ranch-c331076bad75ed89ff01c67d9e2c12688da7cc10.tar.gz ranch-c331076bad75ed89ff01c67d9e2c12688da7cc10.tar.bz2 ranch-c331076bad75ed89ff01c67d9e2c12688da7cc10.zip |
Add Transport:shutdown/2
Allows closing the socket in one or two directions.
-rw-r--r-- | manual/ranch_transport.md | 8 | ||||
-rw-r--r-- | src/ranch_ssl.erl | 6 | ||||
-rw-r--r-- | src/ranch_tcp.erl | 6 | ||||
-rw-r--r-- | src/ranch_transport.erl | 2 |
4 files changed, 22 insertions, 0 deletions
diff --git a/manual/ranch_transport.md b/manual/ranch_transport.md index 291b0e4..7ae3e31 100644 --- a/manual/ranch_transport.md +++ b/manual/ranch_transport.md @@ -167,6 +167,14 @@ Callbacks > > This is mainly useful for switching to active or passive mode. +### shutdown(CSocket, How) -> ok | {error, atom()} + +> Types: +> * CSocket = any() +> * How = read | write | read_write +> +> Immediately close the socket in one or two directions. + ### sockname(CSocket) -> {ok, {IP, Port}} | {error, atom()} > Types: diff --git a/src/ranch_ssl.erl b/src/ranch_ssl.erl index 3f73655..f3a669d 100644 --- a/src/ranch_ssl.erl +++ b/src/ranch_ssl.erl @@ -31,6 +31,7 @@ -export([controlling_process/2]). -export([peername/1]). -export([sockname/1]). +-export([shutdown/2]). -export([close/1]). -type opts() :: [{backlog, non_neg_integer()} @@ -166,6 +167,11 @@ peername(Socket) -> sockname(Socket) -> ssl:sockname(Socket). +-spec shutdown(ssl:sslsocket(), read | write | read_write) + -> ok | {error, atom()}. +shutdown(Socket, How) -> + ssl:shutdown(Socket, How). + -spec close(ssl:sslsocket()) -> ok. close(Socket) -> ssl:close(Socket). diff --git a/src/ranch_tcp.erl b/src/ranch_tcp.erl index bd2eea6..bdee709 100644 --- a/src/ranch_tcp.erl +++ b/src/ranch_tcp.erl @@ -31,6 +31,7 @@ -export([controlling_process/2]). -export([peername/1]). -export([sockname/1]). +-export([shutdown/2]). -export([close/1]). -type opts() :: [{backlog, non_neg_integer()} @@ -160,6 +161,11 @@ peername(Socket) -> sockname(Socket) -> inet:sockname(Socket). +-spec shutdown(inet:socket(), read | write | read_write) + -> ok | {error, atom()}. +shutdown(Socket, How) -> + gen_tcp:shutdown(Socket, How). + -spec close(inet:socket()) -> ok. close(Socket) -> gen_tcp:close(Socket). diff --git a/src/ranch_transport.erl b/src/ranch_transport.erl index 33c6fad..9188965 100644 --- a/src/ranch_transport.erl +++ b/src/ranch_transport.erl @@ -49,6 +49,8 @@ -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}. -callback sockname(socket()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}. +-callback shutdown(socket(), read | write | read_write) + -> ok | {error, atom()}. -callback close(socket()) -> ok. %% A fallback for transports that don't have a native sendfile implementation. |