Skip to content

Commit

Permalink
Add Unix implementation for omrsock_getaddrinfo_create_hints
Browse files Browse the repository at this point in the history
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 <sbabneet@ca.ibm.com>

Signed-off-by: Haley Cao <haleycao88@hotmail.com>
  • Loading branch information
Haley Cao committed Jan 27, 2020
1 parent 4edb544 commit 6ace67c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion port/unix/omrsock.c
Expand Up @@ -26,6 +26,9 @@
* @brief Sockets
*/

#include <netdb.h>
#include <string.h>

#include "omrcfg.h"
#if defined(OMR_PORT_SOCKET_SUPPORT)
#include "omrport.h"
Expand All @@ -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
Expand Down

0 comments on commit 6ace67c

Please sign in to comment.