From 6ace67c417c33d8283f943dce3cce45b28b459a5 Mon Sep 17 00:00:00 2001 From: Haley Cao Date: Mon, 13 Jan 2020 20:43:19 +0000 Subject: [PATCH] Add Unix implementation for omrsock_getaddrinfo_create_hints Added Unix implementation which uses OMRSOCK API per thread buffer - Used old j9sock API template to implement omrsock_getaddrinfo_create_hints which uses omrsockptb helper function omrsock_ptb_get. - The implementation checks and allocates memory for users to make a hints structure, which is later passed into omrsock_getaddrinfo. Issue: #4102 co-authored-by: Babneet Singh Signed-off-by: Haley Cao --- port/unix/omrsock.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/port/unix/omrsock.c b/port/unix/omrsock.c index c6d53aaf4d7..1d447022b63 100644 --- a/port/unix/omrsock.c +++ b/port/unix/omrsock.c @@ -26,6 +26,9 @@ * @brief Sockets */ +#include +#include + #include "omrcfg.h" #if defined(OMR_PORT_SOCKET_SUPPORT) #include "omrport.h" @@ -41,7 +44,33 @@ omrsock_startup(struct OMRPortLibrary *portLibrary) int32_t omrsock_getaddrinfo_create_hints(struct OMRPortLibrary *portLibrary, omrsock_addrinfo_t *hints, int32_t family, int32_t socktype, int32_t protocol, int32_t flags) { - return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM; + *hints = NULL; + omrsock_ptb_t ptBuffer = NULL; + omr_os_addrinfo *ptbHints = NULL; + + /* Initialized the pt buffers if necessary */ + ptBuffer = omrsock_ptb_get(portLibrary); + if (NULL == ptBuffer) { + return OMRPORT_ERROR_SOCK_PTB_FAILED; + } + + ptbHints = (ptBuffer->addrInfoHints).addrInfo; + if (NULL == ptbHints) { + ptbHints = portLibrary->mem_allocate_memory(portLibrary, sizeof(omr_os_addrinfo), OMR_GET_CALLSITE(), OMRMEM_CATEGORY_PORT_LIBRARY); + if (NULL == ptbHints) { + return OMRPORT_ERROR_SOCK_SYSTEM_FULL; + } + } + memset(ptbHints, 0, sizeof(omr_os_addrinfo)); + + ptbHints->ai_flags = flags; + ptbHints->ai_family = family; + ptbHints->ai_socktype = socktype; + ptbHints->ai_protocol = protocol; + + (ptBuffer->addrInfoHints).addrInfo = ptbHints; + *hints = &ptBuffer->addrInfoHints; + return 0; } int32_t