From c331076bad75ed89ff01c67d9e2c12688da7cc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 7 Dec 2013 16:20:30 +0100 Subject: Add Transport:shutdown/2 Allows closing the socket in one or two directions. --- manual/ranch_transport.md | 8 ++++++++ src/ranch_ssl.erl | 6 ++++++ src/ranch_tcp.erl | 6 ++++++ src/ranch_transport.erl | 2 ++ 4 files changed, 22 insertions(+) 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. -- cgit v1.2.3