aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Thompson <[email protected]>2012-04-06 13:14:54 -0400
committerAndrew Thompson <[email protected]>2012-04-06 13:24:02 -0400
commit06a2d636bce7a0494b960eae574fc092d25fcd7a (patch)
treecfbf0b5a432ca68cd3688a4bab7263da03f35c4e /src
parent95e05d822f46e791a919f4e966879b4827989669 (diff)
downloadcowboy-06a2d636bce7a0494b960eae574fc092d25fcd7a.tar.gz
cowboy-06a2d636bce7a0494b960eae574fc092d25fcd7a.tar.bz2
cowboy-06a2d636bce7a0494b960eae574fc092d25fcd7a.zip
Add sockname/1 to the TCP and SSL transports
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_ssl_transport.erl9
-rw-r--r--src/cowboy_tcp_transport.erl9
2 files changed, 16 insertions, 2 deletions
diff --git a/src/cowboy_ssl_transport.erl b/src/cowboy_ssl_transport.erl
index 8074209..3b130f0 100644
--- a/src/cowboy_ssl_transport.erl
+++ b/src/cowboy_ssl_transport.erl
@@ -24,7 +24,7 @@
%% @see ssl
-module(cowboy_ssl_transport).
-export([name/0, messages/0, listen/1, accept/2, recv/3, send/2, setopts/2,
- controlling_process/2, peername/1, close/1]).
+ controlling_process/2, peername/1, close/1, sockname/1]).
%% @doc Name of this transport API, <em>ssl</em>.
-spec name() -> ssl.
@@ -140,6 +140,13 @@ peername(Socket) ->
close(Socket) ->
ssl:close(Socket).
+%% @doc Get the local address and port of a socket
+%% @see ssl:sockname/1
+-spec sockname(ssl:sslsocket())
+ -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
+sockname(Socket) ->
+ ssl:sockname(Socket).
+
%% Internal.
-spec require(list(module())) -> ok.
diff --git a/src/cowboy_tcp_transport.erl b/src/cowboy_tcp_transport.erl
index 82d193b..f197dd1 100644
--- a/src/cowboy_tcp_transport.erl
+++ b/src/cowboy_tcp_transport.erl
@@ -20,7 +20,7 @@
-module(cowboy_tcp_transport).
-export([name/0, messages/0, listen/1, accept/2, recv/3, send/2, setopts/2,
- controlling_process/2, peername/1, close/1]).
+ controlling_process/2, peername/1, close/1, sockname/1]).
%% @doc Name of this transport API, <em>tcp</em>.
-spec name() -> tcp.
@@ -104,3 +104,10 @@ peername(Socket) ->
-spec close(inet:socket()) -> ok.
close(Socket) ->
gen_tcp:close(Socket).
+
+%% @doc Get the local address and port of a socket
+%% @see inet:sockname/1
+-spec sockname(inet:socket())
+ -> {ok, {inet:ip_address(), inet:port_number()}} | {error, atom()}.
+sockname(Socket) ->
+ inet:sockname(Socket).