From 165666d8b8b1b21ffaf43ac436cfc1657ba83649 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 30 Jul 2018 18:22:46 +0200 Subject: [socket-nif] Add support for recvmsg Added preliminary support for function recvmsg. At the moment this only works on *nix (Windows has another function, WSARecvMsg, which has a slightly different API). Also we have "no" cmsg decode at the moment (just level and type). OTP-14831 --- erts/emulator/nifs/common/socket_tarray.c | 139 ++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 erts/emulator/nifs/common/socket_tarray.c (limited to 'erts/emulator/nifs/common/socket_tarray.c') diff --git a/erts/emulator/nifs/common/socket_tarray.c b/erts/emulator/nifs/common/socket_tarray.c new file mode 100644 index 0000000000..bf37e5bc0e --- /dev/null +++ b/erts/emulator/nifs/common/socket_tarray.c @@ -0,0 +1,139 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2018-2018. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * %CopyrightEnd% + * + * ---------------------------------------------------------------------- + * Purpose : Build and "maintain" a (erlang) term array of + * variable length. + * ---------------------------------------------------------------------- + * + */ + +#include +#include + +#include + +#include "socket_int.h" +#include "socket_util.h" +#include "socket_tarray.h" + + + +/* ---------------------------------------------------------------------- + * Types + */ + +typedef struct { + uint32_t sz; + uint32_t idx; + ERL_NIF_TERM* array; +} SocketTArrayInt; + + +/* ---------------------------------------------------------------------- + * Forward for internal functions + */ + +static void esock_tarray_add1(SocketTArrayInt* taP, ERL_NIF_TERM t); +static void esock_tarray_ensure_fits(SocketTArrayInt* taP, uint32_t needs); + + +/* ---------------------------------------------------------------------- + * API + */ + +extern +void* esock_tarray_create(uint32_t sz) +{ + SocketTArrayInt* tarrayP; + + ESOCK_ASSERT( (sz == 0) ); + + tarrayP = MALLOC(sizeof(SocketTArrayInt)); + ESOCK_ASSERT( (tarrayP == NULL) ); + + tarrayP->array = MALLOC(sz * sizeof(ERL_NIF_TERM)); + ESOCK_ASSERT( (tarrayP->array == NULL) ); + tarrayP->sz = sz; + tarrayP->idx = 0; + + return ((SocketTArray) tarrayP); +} + +extern +void esock_tarray_delete(SocketTArray ta) +{ + SocketTArrayInt* taP = (SocketTArrayInt*) ta; + + FREE(taP->array); + FREE(taP); +} + + +extern +uint32_t esock_tarray_sz(SocketTArray a) +{ + return ( ((SocketTArrayInt*) a)->idx ); +} + +extern +void esock_tarray_add(SocketTArray ta, ERL_NIF_TERM t) +{ + esock_tarray_add1((SocketTArrayInt*) ta, t); +} + +extern +void esock_tarray_tolist(SocketTArray ta, + ErlNifEnv* env, + ERL_NIF_TERM* list) +{ + SocketTArrayInt* taP = (SocketTArrayInt*) ta; + + *list = MKLA(env, taP->array, taP->idx); + + esock_tarray_delete(taP); +} + + + +/* ---------------------------------------------------------------------- + * "Internal" functions + */ + +static +void esock_tarray_add1(SocketTArrayInt* taP, ERL_NIF_TERM t) +{ + esock_tarray_ensure_fits(taP, 1); + + taP->array[taP->idx++] = t; +} + +static +void esock_tarray_ensure_fits(SocketTArrayInt* taP, uint32_t needs) +{ + if (taP->sz < (taP->idx + needs)) { + uint32_t newSz = (needs < taP->sz) ? 2*taP->sz : 2*needs; + void* mem = REALLOC(taP->array, newSz * sizeof(ERL_NIF_TERM)); + + ESOCK_ASSERT( (mem == NULL) ); + + taP->sz = newSz; + taP->array = (ERL_NIF_TERM*) mem; + } +} -- cgit v1.2.3 From d4c6b555aea77198d662822c7f5a134a16cff8af Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 31 Jul 2018 12:53:52 +0200 Subject: [socket-nif] Debugged and stuff It seems to work, with atleast some of the cmsg options. More testing needed... OTP-14831 --- erts/emulator/nifs/common/socket_tarray.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'erts/emulator/nifs/common/socket_tarray.c') diff --git a/erts/emulator/nifs/common/socket_tarray.c b/erts/emulator/nifs/common/socket_tarray.c index bf37e5bc0e..a327e014c4 100644 --- a/erts/emulator/nifs/common/socket_tarray.c +++ b/erts/emulator/nifs/common/socket_tarray.c @@ -63,13 +63,13 @@ void* esock_tarray_create(uint32_t sz) { SocketTArrayInt* tarrayP; - ESOCK_ASSERT( (sz == 0) ); + ESOCK_ASSERT( (sz > 0) ); tarrayP = MALLOC(sizeof(SocketTArrayInt)); - ESOCK_ASSERT( (tarrayP == NULL) ); + ESOCK_ASSERT( (tarrayP != NULL) ); tarrayP->array = MALLOC(sz * sizeof(ERL_NIF_TERM)); - ESOCK_ASSERT( (tarrayP->array == NULL) ); + ESOCK_ASSERT( (tarrayP->array != NULL) ); tarrayP->sz = sz; tarrayP->idx = 0; @@ -131,7 +131,7 @@ void esock_tarray_ensure_fits(SocketTArrayInt* taP, uint32_t needs) uint32_t newSz = (needs < taP->sz) ? 2*taP->sz : 2*needs; void* mem = REALLOC(taP->array, newSz * sizeof(ERL_NIF_TERM)); - ESOCK_ASSERT( (mem == NULL) ); + ESOCK_ASSERT( (mem != NULL) ); taP->sz = newSz; taP->array = (ERL_NIF_TERM*) mem; -- cgit v1.2.3 From 875825874d4a8d52ec5cc593f5024afc696c29df Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 31 Jan 2019 11:34:03 +0100 Subject: [socket-nif] nosup expection of win32 and type(s) replacements The nif callback functions (nif_open) now instead cause an 'nosup' exception if called (instead of badarg). The basic type uint16_t, uint32_t and int32_t (C99) replaced "own" (that is, defined by "us") types Uint16, Uint32 and Sint32. The point of this is that our Windows build system seems to be a bit lacking when it comes to types... Removed "some stuff" that was if-defed. Different solution when win32 support for sockets has been improved. Make sure the socket_*.c util modules are not included in the building for windows. OTP-15526 --- erts/emulator/nifs/common/socket_tarray.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'erts/emulator/nifs/common/socket_tarray.c') diff --git a/erts/emulator/nifs/common/socket_tarray.c b/erts/emulator/nifs/common/socket_tarray.c index a327e014c4..def22c4919 100644 --- a/erts/emulator/nifs/common/socket_tarray.c +++ b/erts/emulator/nifs/common/socket_tarray.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2018-2018. All Rights Reserved. + * Copyright Ericsson AB 2018-2019. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,12 +24,16 @@ * */ -#include +/* #ifdef HAVE_CONFIG_H */ +/* #include "config.h" */ +/* #endif */ + #include #include #include "socket_int.h" +#include #include "socket_util.h" #include "socket_tarray.h" @@ -40,8 +44,8 @@ */ typedef struct { - uint32_t sz; - uint32_t idx; + Uint32 sz; + Uint32 idx; ERL_NIF_TERM* array; } SocketTArrayInt; @@ -51,7 +55,7 @@ typedef struct { */ static void esock_tarray_add1(SocketTArrayInt* taP, ERL_NIF_TERM t); -static void esock_tarray_ensure_fits(SocketTArrayInt* taP, uint32_t needs); +static void esock_tarray_ensure_fits(SocketTArrayInt* taP, Uint32 needs); /* ---------------------------------------------------------------------- @@ -59,7 +63,7 @@ static void esock_tarray_ensure_fits(SocketTArrayInt* taP, uint32_t needs); */ extern -void* esock_tarray_create(uint32_t sz) +void* esock_tarray_create(Uint32 sz) { SocketTArrayInt* tarrayP; @@ -87,7 +91,7 @@ void esock_tarray_delete(SocketTArray ta) extern -uint32_t esock_tarray_sz(SocketTArray a) +Uint32 esock_tarray_sz(SocketTArray a) { return ( ((SocketTArrayInt*) a)->idx ); } @@ -125,11 +129,11 @@ void esock_tarray_add1(SocketTArrayInt* taP, ERL_NIF_TERM t) } static -void esock_tarray_ensure_fits(SocketTArrayInt* taP, uint32_t needs) +void esock_tarray_ensure_fits(SocketTArrayInt* taP, Uint32 needs) { if (taP->sz < (taP->idx + needs)) { - uint32_t newSz = (needs < taP->sz) ? 2*taP->sz : 2*needs; - void* mem = REALLOC(taP->array, newSz * sizeof(ERL_NIF_TERM)); + Uint32 newSz = (needs < taP->sz) ? 2*taP->sz : 2*needs; + void* mem = REALLOC(taP->array, newSz * sizeof(ERL_NIF_TERM)); ESOCK_ASSERT( (mem != NULL) ); -- cgit v1.2.3