Skip to content

Commit

Permalink
Use the inet:socket() type instead of the user-defined one.
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Hoguin committed Apr 17, 2011
1 parent 9ad3238 commit 15dc645
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/http.hrl
Expand Up @@ -14,7 +14,7 @@

-record(http_req, {
%% Transport.
socket = undefined :: undefined | socket(),
socket = undefined :: undefined | inet:socket(),
transport = undefined :: undefined | module(),
connection = keepalive :: keepalive | close,

Expand Down
1 change: 0 additions & 1 deletion include/types.hrl
Expand Up @@ -16,7 +16,6 @@
{takeover, Node::node()} | {failover, Node::node()}.

-type posix() :: atom().
-opaque socket() :: term().
-opaque sslsocket() :: term().
-type port_number() :: 0..65535.

Expand Down
4 changes: 2 additions & 2 deletions src/cowboy_acceptor.erl
Expand Up @@ -20,7 +20,7 @@

%% API.

-spec start_link(LSocket::socket(), Transport::module(),
-spec start_link(LSocket::inet:socket(), Transport::module(),
Protocol::module(), Opts::term(), ReqsSup::pid()) -> {ok, Pid::pid()}.
start_link(LSocket, Transport, Protocol, Opts, ReqsSup) ->
Pid = spawn_link(?MODULE, acceptor,
Expand All @@ -29,7 +29,7 @@ start_link(LSocket, Transport, Protocol, Opts, ReqsSup) ->

%% Internal.

-spec acceptor(LSocket::socket(), Transport::module(),
-spec acceptor(LSocket::inet:socket(), Transport::module(),
Protocol::module(), Opts::term(), ReqsSup::pid()) -> no_return().
acceptor(LSocket, Transport, Protocol, Opts, ReqsSup) ->
case Transport:accept(LSocket, 2000) of
Expand Down
6 changes: 3 additions & 3 deletions src/cowboy_http_protocol.erl
Expand Up @@ -20,7 +20,7 @@
-include("include/http.hrl").

-record(state, {
socket :: socket(),
socket :: inet:socket(),
transport :: module(),
dispatch :: dispatch(),
handler :: {Handler::module(), Opts::term()},
Expand All @@ -32,15 +32,15 @@

%% API.

-spec start_link(Socket::socket(), Transport::module(), Opts::term())
-spec start_link(Socket::inet:socket(), Transport::module(), Opts::term())
-> {ok, Pid::pid()}.
start_link(Socket, Transport, Opts) ->
Pid = spawn_link(?MODULE, init, [Socket, Transport, Opts]),
{ok, Pid}.

%% FSM.

-spec init(Socket::socket(), Transport::module(), Opts::term()) -> ok.
-spec init(Socket::inet:socket(), Transport::module(), Opts::term()) -> ok.
init(Socket, Transport, Opts) ->
Dispatch = proplists:get_value(dispatch, Opts, []),
MaxEmptyLines = proplists:get_value(max_empty_lines, Opts, 5),
Expand Down
2 changes: 1 addition & 1 deletion src/cowboy_requests_sup.erl
Expand Up @@ -26,7 +26,7 @@
start_link() ->
supervisor:start_link(?MODULE, []).

-spec start_request(Socket::socket(), Transport::module(),
-spec start_request(Socket::inet:socket(), Transport::module(),
Protocol::module(), Opts::term()) -> {ok, Pid::pid()}.
start_request(Socket, Transport, Protocol, Opts) ->
Protocol:start_link(Socket, Transport, Opts).
Expand Down
19 changes: 10 additions & 9 deletions src/cowboy_tcp_transport.erl
Expand Up @@ -27,42 +27,43 @@ name() -> tcp.
messages() -> {tcp, tcp_closed, tcp_error}.

-spec listen([{port, Port::port_number()}])
-> {ok, LSocket::socket()} | {error, Reason::posix()}.
-> {ok, LSocket::inet:socket()} | {error, Reason::posix()}.
listen(Opts) ->
{port, Port} = lists:keyfind(port, 1, Opts),
gen_tcp:listen(Port, [binary, {active, false},
{packet, raw}, {reuseaddr, true}]).

-spec accept(LSocket::socket(), Timeout::timeout())
-> {ok, Socket::socket()} | {error, Reason::closed | timeout | posix()}.
-spec accept(LSocket::inet:socket(), Timeout::timeout())
-> {ok, Socket::inet:socket()}
| {error, Reason::closed | timeout | posix()}.
accept(LSocket, Timeout) ->
gen_tcp:accept(LSocket, Timeout).

-spec recv(Socket::socket(), Length::integer(), Timeout::timeout())
-spec recv(Socket::inet:socket(), Length::integer(), Timeout::timeout())
-> {ok, Packet::term()} | {error, Reason::closed | posix()}.
recv(Socket, Length, Timeout) ->
gen_tcp:recv(Socket, Length, Timeout).

-spec send(Socket::socket(), Packet::iolist())
-spec send(Socket::inet:socket(), Packet::iolist())
-> ok | {error, Reason::posix()}.
send(Socket, Packet) ->
gen_tcp:send(Socket, Packet).

-spec setopts(Socket::socket(), Opts::list(term()))
-spec setopts(Socket::inet:socket(), Opts::list(term()))
-> ok | {error, Reason::posix()}.
setopts(Socket, Opts) ->
inet:setopts(Socket, Opts).

-spec controlling_process(Socket::socket(), Pid::pid())
-spec controlling_process(Socket::inet:socket(), Pid::pid())
-> ok | {error, Reason::closed | not_owner | posix()}.
controlling_process(Socket, Pid) ->
gen_tcp:controlling_process(Socket, Pid).

-spec peername(Socket::socket())
-spec peername(Socket::inet:socket())
-> {ok, {Address::inet:ip_address(), Port::port_number()}} | {error, posix()}.
peername(Socket) ->
inet:peername(Socket).

-spec close(Socket::socket()) -> ok.
-spec close(Socket::inet:socket()) -> ok.
close(Socket) ->
gen_tcp:close(Socket).

0 comments on commit 15dc645

Please sign in to comment.