diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-04-07 14:30:47 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-04-07 14:30:47 +0100 |
commit | a5fccc82365e8bd9b39dbc0202d14772d5b2d7aa (patch) | |
tree | 38f5f88a747d9361866089c5273ad764f55593ca /src/rabbit_net.erl | |
parent | 93674ad1716b7c5dd07bcbc255599d4e3fd12828 (diff) | |
download | rabbitmq-server-a5fccc82365e8bd9b39dbc0202d14772d5b2d7aa.tar.gz |
make ssl work
...and handle socket errors
It turns out that for active sockets the messages sent by tcp and ssl
sockets to the controlling process differ gratuitously.
Diffstat (limited to 'src/rabbit_net.erl')
-rw-r--r-- | src/rabbit_net.erl | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/rabbit_net.erl b/src/rabbit_net.erl index c8514d90..b6cc28af 100644 --- a/src/rabbit_net.erl +++ b/src/rabbit_net.erl @@ -18,7 +18,7 @@ -include("rabbit.hrl"). -export([is_ssl/1, ssl_info/1, controlling_process/2, getstat/2, - async_recv/3, port_command/2, setopts/2, send/2, close/1, + recv/1, async_recv/3, port_command/2, setopts/2, send/2, close/1, sockname/1, peername/1, peercert/1]). %%--------------------------------------------------------------------------- @@ -42,6 +42,9 @@ -spec(getstat/2 :: (socket(), [stat_option()]) -> ok_val_or_error([{stat_option(), integer()}])). +-spec(recv/1 :: (socket()) -> + {'data', [char()] | binary()} | 'closed' | + rabbit_types:error(any()) | {'other', any()}). -spec(async_recv/3 :: (socket(), integer(), timeout()) -> rabbit_types:ok(any())). -spec(port_command/2 :: (socket(), iolist()) -> 'true'). @@ -83,6 +86,23 @@ getstat(Sock, Stats) when ?IS_SSL(Sock) -> getstat(Sock, Stats) when is_port(Sock) -> inet:getstat(Sock, Stats). +recv(Sock) when ?IS_SSL(Sock) -> + S = Sock#ssl_socket.ssl, + receive + {ssl, S, Data} -> {data, Data}; + {ssl_closed, S} -> closed; + {ssl_error, S, Reason} -> {error, Reason}; + Other -> {other, Other} + end; +recv(Sock) -> + S = Sock, + receive + {tcp, S, Data} -> {data, Data}; + {tcp_closed, S} -> closed; + {tcp_error, S, Reason} -> {error, Reason}; + Other -> {other, Other} + end. + async_recv(Sock, Length, Timeout) when ?IS_SSL(Sock) -> Pid = self(), Ref = make_ref(), |