Skip to content
Browse files

Merge branch 'adt-add-sockname' of https://github.com/Vagabond/cowboy

  • Loading branch information...
2 parents e8ee647 + 06a2d63 commit 85ed79eb59cf2587b3c13558101eb1d78c95cfa6 Loïc Hoguin committed
Showing with 16 additions and 2 deletions.
  1. +8 −1 src/cowboy_ssl_transport.erl
  2. +8 −1 src/cowboy_tcp_transport.erl
View
9 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.
View
9 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).

0 comments on commit 85ed79e

Please sign in to comment.
Something went wrong with that request. Please try again.