aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/nifs/common/socket_nif.c21
-rw-r--r--erts/preloaded/src/socket.erl16
2 files changed, 31 insertions, 6 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c
index 9887047135..14d7cd2611 100644
--- a/erts/emulator/nifs/common/socket_nif.c
+++ b/erts/emulator/nifs/common/socket_nif.c
@@ -133,6 +133,7 @@
#endif
#include <netinet/tcp.h>
+#include <netinet/udp.h>
#include <arpa/inet.h>
#include <sys/param.h>
@@ -372,6 +373,8 @@ typedef union {
#define SOCKET_OPT_TCP_MAXSEG 1
#define SOCKET_OPT_TCP_NODELAY 2
+#define SOCKET_OPT_UDP_CORK 0
+
#define SOCKET_OPT_SCTP_AUTOCLOSE 7
#define SOCKET_OPT_SCTP_NODELAY 22
@@ -3625,8 +3628,8 @@ BOOLEAN_T eoptval2optval_tcp(ErlNifEnv* env,
/* +++ decode UDP socket options +++
- * Currently there are no such options, so this function
- * is just a placeholder!
+ * Currently there are only one option, cork, and that may only
+ * work on linux...
*/
static
BOOLEAN_T eoptval2optval_udp(ErlNifEnv* env,
@@ -3636,6 +3639,20 @@ BOOLEAN_T eoptval2optval_udp(ErlNifEnv* env,
SocketOptValue* valP)
{
switch (eOpt) {
+#if defined(UDP_CORK)
+ case SOCKET_OPT_UDP_CORK:
+ if (decode_bool(env, eVal, &valP->u.boolVal)) {
+ valP->tag = SOCKET_OPT_VALUE_BOOL;
+ *opt = UDP_CORK;
+ return TRUE;
+ } else {
+ valP->tag = SOCKET_OPT_VALUE_UNDEF;
+ *opt = -1;
+ return FALSE;
+ }
+ break;
+#endif
+
default:
*opt = -1;
valP->tag = SOCKET_OPT_VALUE_UNDEF;
diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl
index 1c811fa11a..4a9de0dc9e 100644
--- a/erts/preloaded/src/socket.erl
+++ b/erts/preloaded/src/socket.erl
@@ -270,9 +270,8 @@
maxseg |
nodelay.
--type udp_socket_option() :: checksum |
- maxdgram |
- recvspace.
+-type udp_socket_option() :: cork.
+
-type sctp_socket_option() ::
adaption_layer |
associnfo |
@@ -444,6 +443,8 @@
-define(SOCKET_OPT_TCP_MAXSEG, 1).
-define(SOCKET_OPT_TCP_NODELAY, 2).
+-define(SOCKET_OPT_UDP_CORK, 1).
+
-define(SOCKET_OPT_SCTP_AUTOCLOSE, 7).
-define(SOCKET_OPT_SCTP_NODELAY, 22).
@@ -1638,7 +1639,7 @@ enc_setopt_value(ipv6, hoplimit, V, _D, T, _P)
enc_setopt_value(ipv6 = L, Opt, V, _D, _T, _P) ->
not_supported({L, Opt, V});
-enc_setopt_value(tcp, congetsion, V, _D, T, P)
+enc_setopt_value(tcp, congestion, V, _D, T, P)
when is_list(V) andalso
(T =:= stream) andalso
(P =:= tcp) ->
@@ -1656,6 +1657,11 @@ enc_setopt_value(tcp, nodelay, V, _D, T, P)
enc_setopt_value(tcp = L, Opt, V, _D, _T, _P) ->
not_supported({L, Opt, V});
+enc_setopt_value(udp, cork, V, _D, T, P)
+ when is_boolean(V) andalso
+ (T =:= dgram) andalso
+ (P =:= udp) ->
+ V;
enc_setopt_value(udp = L, Opt, _V, _D, _T, _P) ->
not_supported({L, Opt});
@@ -1940,6 +1946,8 @@ enc_sockopt_key(tcp, UnknownOpt, _Dir, _D, _T, _P) ->
unknown(UnknownOpt);
%% UDP socket options
+enc_sockopt_key(udp, cork = _Opt, _Dir, _D, _T, _P) ->
+ ?SOCKET_OPT_UDP_CORK;
enc_sockopt_key(udp, UnknownOpt, _Dir, _D, _T, _P) ->
unknown(UnknownOpt);