diff options
author | Micael Karlberg <[email protected]> | 2018-04-26 16:16:24 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-09-18 13:01:37 +0200 |
commit | b69436fc5970ff8fc749a37351e9d9c5a54f445e (patch) | |
tree | 0031ebdbef63c81502f75a1214f85eab81abe6e3 /erts/preloaded/src/socket.erl | |
parent | 82bfbdd7919e1aee360b76bdbaca17d2cf00ee73 (diff) | |
download | otp-b69436fc5970ff8fc749a37351e9d9c5a54f445e.tar.gz otp-b69436fc5970ff8fc749a37351e9d9c5a54f445e.tar.bz2 otp-b69436fc5970ff8fc749a37351e9d9c5a54f445e.zip |
[socket-nif] Completed the shutdown function
Diffstat (limited to 'erts/preloaded/src/socket.erl')
-rw-r--r-- | erts/preloaded/src/socket.erl | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index f1e8a8b099..8dce86c518 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -44,6 +44,7 @@ %% readv/3, close/1, + shutdown/2, setopt/4, getopt/3 @@ -65,7 +66,9 @@ accept_flag/0, send_flags/0, - send_flag/0 + send_flag/0, + + shutdown_how/0 ]). @@ -148,6 +151,8 @@ -type setopt_key() :: foo. -type getopt_key() :: foo. +-type shutdown_how() :: read | write | read_write. + -record(msg_hdr, { %% Optional address @@ -221,6 +226,9 @@ -define(SOCKET_GETOPT_KEY_DEBUG, ?SOCKET_SETOPT_KEY_DEBUG). +-define(SOCKET_SHUTDOWN_HOW_READ, 0). +-define(SOCKET_SHUTDOWN_HOW_WRITE, 1). +-define(SOCKET_SHUTDOWN_HOW_READ_WRITE, 2). %% =========================================================================== @@ -1016,6 +1024,32 @@ close(#socket{ref = SockRef}) -> %% =========================================================================== %% +%% shutdown - shut down part of a full-duplex connection +%% + +-spec shutdown(Socket, How) -> ok | {error, Reason} when + Socket :: socket(), + How :: shutdown_how(), + Reason :: term(). + +shutdown(#socket{ref = SockRef}, How) -> + try + begin + EHow = enc_shutdown_how(How), + nif_shutdown(SockRef, EHow) + end + catch + throw:T -> + T; + error:Reason -> + {error, Reason} + end. + + + + +%% =========================================================================== +%% %% setopt - manipulate individual properties of a socket %% %% What properties are valid depend on what kind of socket it is @@ -1223,6 +1257,16 @@ dec_getopt_value(otp, debug, B, _, _, _) when is_boolean(B) -> +enc_shutdown_how(read) -> + ?SOCKET_SHUTDOWN_HOW_READ; +enc_shutdown_how(write) -> + ?SOCKET_SHUTDOWN_HOW_WRITE; +enc_shutdown_how(read_write) -> + ?SOCKET_SHUTDOWN_HOW_READ_WRITE. + + + + %% =========================================================================== %% %% Misc utility functions @@ -1340,6 +1384,9 @@ nif_cancel(_SRef, _Op, _Ref) -> nif_close(_SRef) -> erlang:error(badarg). +nif_shutdown(_SRef, _How) -> + erlang:error(badarg). + nif_finalize_close(_SRef) -> erlang:error(badarg). |