diff options
author | Loïc Hoguin <[email protected]> | 2013-12-07 14:26:14 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-12-07 14:26:14 +0100 |
commit | 441687473ab364ba1cc5c19d89dced6a319747f9 (patch) | |
tree | a0862f0a944ad3380161614dc4debd5782a0962e | |
parent | 366cb0a6df123ed9b128966dba6b64993e88b60a (diff) | |
parent | 261e325883646912c880f2a1f2256b55eb7dcee9 (diff) | |
download | ranch-441687473ab364ba1cc5c19d89dced6a319747f9.tar.gz ranch-441687473ab364ba1cc5c19d89dced6a319747f9.tar.bz2 ranch-441687473ab364ba1cc5c19d89dced6a319747f9.zip |
Merge branch 'connect_timeout' of git://github.com/heroku/ranch
-rw-r--r-- | src/ranch_ssl.erl | 12 | ||||
-rw-r--r-- | src/ranch_tcp.erl | 13 | ||||
-rw-r--r-- | src/ranch_transport.erl | 5 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/ranch_ssl.erl b/src/ranch_ssl.erl index a6ceb4d..dc29a18 100644 --- a/src/ranch_ssl.erl +++ b/src/ranch_ssl.erl @@ -32,6 +32,7 @@ -export([accept/2]). -export([accept_ack/2]). -export([connect/3]). +-export([connect/4]). -export([recv/3]). -export([send/2]). -export([sendfile/2]). @@ -189,6 +190,17 @@ connect(Host, Port, Opts) when is_integer(Port) -> ssl:connect(Host, Port, Opts ++ [binary, {active, false}, {packet, raw}]). +%% @private Experimental. Open a connection to the given host and port number. +%% @see ssl:connect/4 +%% @todo Probably filter Opts? +-spec connect(inet:ip_address() | inet:hostname(), + inet:port_number(), any(), timeout()) + -> {ok, inet:socket()} | {error, atom()}. +connect(Host, Port, Opts, Timeout) when is_integer(Port) -> + ssl:connect(Host, Port, + Opts ++ [binary, {active, false}, {packet, raw}], + Timeout). + %% @doc Receive data from a socket in passive mode. %% @see ssl:recv/3 -spec recv(ssl:sslsocket(), non_neg_integer(), timeout()) diff --git a/src/ranch_tcp.erl b/src/ranch_tcp.erl index 86b1e35..d5d5003 100644 --- a/src/ranch_tcp.erl +++ b/src/ranch_tcp.erl @@ -26,6 +26,7 @@ -export([accept/2]). -export([accept_ack/2]). -export([connect/3]). +-export([connect/4]). -export([recv/3]). -export([send/2]). -export([sendfile/2]). @@ -104,6 +105,18 @@ connect(Host, Port, Opts) when is_integer(Port) -> gen_tcp:connect(Host, Port, Opts ++ [binary, {active, false}, {packet, raw}]). +%% @private Experimental. Open a connection to the given host and port +%% number with a timeout. +%% @see gen_tcp:connect/4 +%% @todo Probably filter Opts? +-spec connect(inet:ip_address() | inet:hostname(), + inet:port_number(), any(), timeout()) + -> {ok, inet:socket()} | {error, atom()}. +connect(Host, Port, Opts, Timeout) when is_integer(Port) -> + gen_tcp:connect(Host, Port, + Opts ++ [binary, {active, false}, {packet, raw}], + Timeout). + %% @doc Receive data from a socket in passive mode. %% @see gen_tcp:recv/3 -spec recv(inet:socket(), non_neg_integer(), timeout()) diff --git a/src/ranch_transport.erl b/src/ranch_transport.erl index 5c1153c..5cf10d1 100644 --- a/src/ranch_transport.erl +++ b/src/ranch_transport.erl @@ -55,6 +55,11 @@ -callback connect(string(), inet:port_number(), opts()) -> {ok, socket()} | {error, atom()}. +%% Experimental. Open a connection to the given host and port number +%% with a timeout. +-callback connect(string(), inet:port_number(), opts(), timeout()) + -> {ok, socket()} | {error, atom()}. + %% Receive data from a socket in passive mode. -callback recv(socket(), non_neg_integer(), timeout()) -> {ok, any()} | {error, closed | timeout | atom()}. |