aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Cant <[email protected]>2013-11-07 13:17:22 -0800
committerGeoff Cant <[email protected]>2013-11-07 13:17:22 -0800
commit261e325883646912c880f2a1f2256b55eb7dcee9 (patch)
treec91f028201b24c615c9498074d0a512f6afbe524
parentb6662a357a02f8cd99d35eecd4288b847707f777 (diff)
downloadranch-261e325883646912c880f2a1f2256b55eb7dcee9.tar.gz
ranch-261e325883646912c880f2a1f2256b55eb7dcee9.tar.bz2
ranch-261e325883646912c880f2a1f2256b55eb7dcee9.zip
Implements ranch_transport:connect/4.
Adds a transport connect method that takes a timeout, with implementations for both ssl and tcp connections.
-rw-r--r--src/ranch_ssl.erl12
-rw-r--r--src/ranch_tcp.erl13
-rw-r--r--src/ranch_transport.erl5
3 files changed, 30 insertions, 0 deletions
diff --git a/src/ranch_ssl.erl b/src/ranch_ssl.erl
index 59e842c..097b31c 100644
--- a/src/ranch_ssl.erl
+++ b/src/ranch_ssl.erl
@@ -31,6 +31,7 @@
-export([listen/1]).
-export([accept/2]).
-export([connect/3]).
+-export([connect/4]).
-export([recv/3]).
-export([send/2]).
-export([sendfile/2]).
@@ -183,6 +184,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 6bdcdd0..abf7612 100644
--- a/src/ranch_tcp.erl
+++ b/src/ranch_tcp.erl
@@ -25,6 +25,7 @@
-export([listen/1]).
-export([accept/2]).
-export([connect/3]).
+-export([connect/4]).
-export([recv/3]).
-export([send/2]).
-export([sendfile/2]).
@@ -99,6 +100,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 6168b35..fe06420 100644
--- a/src/ranch_transport.erl
+++ b/src/ranch_transport.erl
@@ -52,6 +52,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()}.