Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a per thread buffer and related tests for OMR socket API #4555

Merged
merged 10 commits into from
Feb 5, 2020
5 changes: 3 additions & 2 deletions fvtest/porttest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2018 IBM Corp. and others
# Copyright (c) 2017, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -42,7 +42,8 @@ if(OMR_OPT_CUDA)
)
endif()
caohaley marked this conversation as resolved.
Show resolved Hide resolved

if(OMR_PORT_SOCKET_SUPPORT)
# TODO: Remove AND (NOT OMR_HOST_OS STREQUAL "win") after OMRSOCK API is implemented on Windows.
if((OMR_PORT_SOCKET_SUPPORT) AND (NOT OMR_HOST_OS STREQUAL "win"))
caohaley marked this conversation as resolved.
Show resolved Hide resolved
set(socketSources
omrsockTest.cpp
)
Expand Down
7 changes: 5 additions & 2 deletions fvtest/porttest/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2015, 2016 IBM Corp. and others
# Copyright (c) 2015, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -54,7 +54,10 @@ OBJECTS := \
main_function
caohaley marked this conversation as resolved.
Show resolved Hide resolved

ifeq (1,$(OMR_PORT_SOCKET_SUPPORT))
OBJECTS += omrsockTest
# TODO: Remove ifneq (win,$(OMR_HOST_OS)) after OMRSOCK API is implemented on Windows.
ifneq (win,$(OMR_HOST_OS))
caohaley marked this conversation as resolved.
Show resolved Hide resolved
OBJECTS += omrsockTest
endif
endif

vpath main_function.cpp $(top_srcdir)/util/main_function
Expand Down
42 changes: 35 additions & 7 deletions fvtest/porttest/omrsockTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -23,6 +23,7 @@
#if defined(OMR_PORT_SOCKET_SUPPORT)
caohaley marked this conversation as resolved.
Show resolved Hide resolved
#include "omrport.h"
#include "omrportsock.h"
#include "omrportsocktypes.h"
#include "testHelpers.hpp"

/**
Expand All @@ -41,7 +42,7 @@
int32_t
start_server(struct OMRPortLibrary *portLibrary, const char *addrStr, const char *port, int32_t family, omrsock_socket_t *serverSocket, omrsock_sockaddr_t serverAddr)
{
return OMRPORT_ERROR_NOTEXIST;
return OMRPORT_ERROR_NOTEXIST;
}

/**
Expand All @@ -59,7 +60,7 @@ start_server(struct OMRPortLibrary *portLibrary, const char *addrStr, const char
int32_t
connect_client_to_server(struct OMRPortLibrary *portLibrary, const char *addrStr, const char *port, int32_t family, omrsock_socket_t *sessionClientSocket, omrsock_sockaddr_t sessionClientAddr)
{
return OMRPORT_ERROR_NOTEXIST;
return OMRPORT_ERROR_NOTEXIST;
}

/**
Expand All @@ -72,7 +73,24 @@ connect_client_to_server(struct OMRPortLibrary *portLibrary, const char *addrStr
*/
TEST(PortSockTest, library_function_pointers_not_null)
{
/* Unimplemented. */
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());

EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_create_hints, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_length, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_family, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_socktype, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_protocol, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_freeaddrinfo, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_socket, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_bind, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_listen, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_accept, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_send, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_sendto, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_recv, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_recvfrom, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_close, (void *)NULL);
}

/**
Expand All @@ -83,7 +101,17 @@ TEST(PortSockTest, library_function_pointers_not_null)
*/
TEST(PortSockTest, per_thread_buffer_functionality)
{
/* Unimplemented. */
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());

omrsock_addrinfo_t hints = NULL;
int32_t family = 0;
int32_t sockType = 1;
int32_t protocol = 1;
int32_t flags = 0;

OMRPORTLIB->sock_getaddrinfo_create_hints(OMRPORTLIB, &hints, family, sockType, protocol, flags);

ASSERT_NE(hints, (void *)NULL);
}

/**
Expand All @@ -104,7 +132,7 @@ TEST(PortSockTest, per_thread_buffer_functionality)
*/
TEST(PortSockTest, getaddrinfo_creation_and_extraction)
{
/* Unimplemented. */
/* Unimplemented. */
}

/**
Expand All @@ -122,7 +150,7 @@ TEST(PortSockTest, getaddrinfo_creation_and_extraction)
*/
TEST(PortSockTest, two_socket_communication)
{
/* Unimplemented. */
/* Unimplemented. */
}

#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
6 changes: 6 additions & 0 deletions include_core/omrport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,8 @@ typedef struct OMRPortLibrary {
/** see @ref omrheap.c::omrheap_grow "omrheap_grow"*/
BOOLEAN (*heap_grow)(struct OMRPortLibrary *portLibrary, struct J9Heap *heap, uintptr_t growAmount) ;
#if defined(OMR_PORT_SOCKET_SUPPORT)
/** see @ref omrsock.c::omrsock_startup "omrsock_startup"*/
caohaley marked this conversation as resolved.
Show resolved Hide resolved
int32_t (*sock_startup)(struct OMRPortLibrary *portLibrary) ;
/** see @ref omrsock.c::omrsock_getaddrinfo_create_hints "omrsock_getaddrinfo_create_hints"*/
int32_t (*sock_getaddrinfo_create_hints)(struct OMRPortLibrary *portLibrary, omrsock_addrinfo_t *hints, int32_t family, int32_t socktype, int32_t protocol, int32_t flags) ;
/** see @ref omrsock.c::omrsock_getaddrinfo "omrsock_getaddrinfo"*/
Expand Down Expand Up @@ -2040,6 +2042,8 @@ typedef struct OMRPortLibrary {
int32_t (*sock_recvfrom)(struct OMRPortLibrary *portLibrary, omrsock_socket_t sock, uint8_t *buf, int32_t nbyte, int32_t flags, omrsock_sockaddr_t addrHandle) ;
/** see @ref omrsock.c::omrsock_close "omrsock_close"*/
int32_t (*sock_close)(struct OMRPortLibrary *portLibrary, omrsock_socket_t *sock) ;
/** see @ref omrsock.c::omrsock_shutdown "omrsock_shutdown"*/
int32_t (*sock_shutdown)(struct OMRPortLibrary *portLibrary) ;
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
#if defined(OMR_OPT_CUDA)
/** CUDA configuration data */
Expand Down Expand Up @@ -2484,6 +2488,7 @@ extern J9_CFUNC int32_t omrport_getVersion(struct OMRPortLibrary *portLibrary);
#define omrheap_query_size(param1,param2) privateOmrPortLibrary->heap_query_size(privateOmrPortLibrary, (param1), (param2))
#define omrheap_grow(param1,param2) privateOmrPortLibrary->heap_grow(privateOmrPortLibrary, (param1), (param2))
#if defined(OMR_PORT_SOCKET_SUPPORT)
#define omrsock_startup() privateOmrPortLibrary->sock_startup(privateOmrPortLibrary)
#define omrsock_getaddrinfo_create_hints(param1,param2,param3,param4,param5) privateOmrPortLibrary->sock_getaddrinfo_create_hints(privateOmrPortLibrary, (param1), (param2), (param3), (param4), (param5))
#define omrsock_getaddrinfo(param1,param2,param3,param4) privateOmrPortLibrary->sock_getaddrinfo(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_getaddrinfo_length(param1,param2) privateOmrPortLibrary->sock_getaddrinfo_length(privateOmrPortLibrary, (param1), (param2))
Expand All @@ -2501,6 +2506,7 @@ extern J9_CFUNC int32_t omrport_getVersion(struct OMRPortLibrary *portLibrary);
#define omrsock_recv(param1,param2,param3,param4) privateOmrPortLibrary->sock_recv(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_recvfrom(param1,param2,param3,param4,param5) privateOmrPortLibrary->sock_recvfrom(privateOmrPortLibrary, (param1), (param2), (param3), (param4), (param5))
#define omrsock_close(param1) privateOmrPortLibrary->sock_close(privateOmrPortLibrary, (param1))
#define omrsock_shutdown() privateOmrPortLibrary->sock_shutdown(privateOmrPortLibrary)
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */

#if defined(OMR_OPT_CUDA)
Expand Down
16 changes: 15 additions & 1 deletion include_core/omrporterror.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1998, 2016 IBM Corp. and others
* Copyright (c) 1998, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -314,4 +314,18 @@
* @}
*/

/**
* @name OMR Socket API Errors
* Error code returned by the socket API
*
* @internal OMRPORT_ERROR_SOCK_* range from -500 to -549 avoid overlap
* @{
*/
#define OMRPORT_ERROR_SOCK_BASE -500
#define OMRPORT_ERROR_SOCK_PTB_FAILED (OMRPORT_ERROR_SOCK_BASE - 0)
#define OMRPORT_ERROR_SOCK_SYSTEM_FULL (OMRPORT_ERROR_SOCK_BASE - 1)
/**
* @}
*/
caohaley marked this conversation as resolved.
Show resolved Hide resolved

#endif /* omrporterror_h */
8 changes: 5 additions & 3 deletions include_core/omrportsock.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -26,10 +26,12 @@
/* Pointer to OMRAddInfoNode, a struct that contains addrinfo information. */
typedef struct OMRAddrInfoNode *omrsock_addrinfo_t;

/* Pointer to ip address. It has enough space for Ipv4 or IPv6 addresses. */
/* Pointer to OMRSockAddrStorage, a struct that contains socket address
* information. It has enough space for Ipv4 or IPv6 addresses.
*/
typedef struct OMRSockAddrStorage *omrsock_sockaddr_t;

/* Pointer to a socket descriptor */
/* Pointer to OMRSocket, a struct that contains socket descriptor. */
typedef struct OMRSocket *omrsock_socket_t;

#endif /* !defined(OMRPORTSOCK_H_) */
103 changes: 103 additions & 0 deletions include_core/omrportsocktypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2020, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

#if !defined(OMRPORTSOCKTYPES_H_)
#define OMRPORTSOCKTYPES_H_

/**
* WIN32_LEAN_AND_MEAN determines what is included in Windows.h. If it is
* defined, some unneeded header files in Windows.h will not be included.
*/
#if defined(OMR_OS_WINDOWS) && !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif /* defined(OMR_OS_WINDOWS) && !defined(WIN32_LEAN_AND_MEAN) */

/**
* To avoid WINSOCK redefinition errors.
*/
#if defined(OMR_OS_WINDOWS) && defined(_WINSOCKAPI_)
#undef _WINSOCKAPI_
#endif /* defined(OMR_OS_WINDOWS) && defined(_WINSOCKAPI_) */

#if defined(OMR_OS_WINDOWS)
/**
* windows.h defined UDATA. Ignore its definition to avoid redefinition errors.
*/
#define UDATA UDATA_win32_
#include <windows.h>
#undef UDATA
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Mswsock.lib")
#pragma comment(lib, "AdvApi32.lib")
#else /* defined(OMR_OS_WINDOWS) */
#include <netinet/in.h>
#include <sys/socket.h>
#endif /* defined(OMR_OS_WINDOWS) */

#include <stdlib.h>
#include <stdio.h>

/**
* Data types required for the socket API.
*/
#if defined(OMR_OS_WINDOWS)
typedef SOCKET omr_os_socket;
typedef struct sockaddr_storage omr_os_sockaddr_storage; /* For IPv4 or IPv6 addresses */
typedef struct addrinfoW omr_os_addrinfo; /* addrinfo structure – Unicode, for IPv4 or IPv6 */
#else /* defined(OMR_OS_WINDOWS) */
typedef int omr_os_socket;
typedef struct sockaddr_storage omr_os_sockaddr_storage; /* For IPv4 or IPv6 addresses */
typedef struct addrinfo omr_os_addrinfo; /* addrinfo structure for IPv4 or IPv6*/
#endif /* defined(OMR_OS_WINDOWS) */

/**
* A struct for storing socket address information. Big enough to store IPv4 and IPv6 addresses.
*/
typedef struct OMRSockAddrStorage {
omr_os_sockaddr_storage data;
} OMRSockAddrStorage;

/**
* A struct for storing socket information.
*/
typedef struct OMRSocket {
omr_os_socket data;
} OMRSocket;

/**
* A node in a linked-list of addrinfo. Filled in using @ref omr_getaddrinfo.
*/
typedef struct OMRAddrInfoNode {
/**
* Pointer to the first addrinfo node in listed list. Defined differently depending on the operating system.
*/
omr_os_addrinfo *addrInfo;

/**
rwy7 marked this conversation as resolved.
Show resolved Hide resolved
* Number of addrinfo nodes in linked list.
*/
rwy7 marked this conversation as resolved.
Show resolved Hide resolved
uint32_t length;
} OMRAddrInfoNode;

#endif /* !defined(OMRPORTSOCKTYPES_H_) */
4 changes: 2 additions & 2 deletions port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2019 IBM Corp. and others
# Copyright (c) 2017, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -183,7 +183,7 @@ list(APPEND OBJECTS
)

if(OMR_PORT_SOCKET_SUPPORT)
list(APPEND OBJECTS omrsock.c)
list(APPEND OBJECTS omrsock.c omrsockptb.c)
endif()

if(NOT OMR_HOST_OS STREQUAL "win")
Expand Down
14 changes: 13 additions & 1 deletion port/common/omrport.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2019 IBM Corp. and others
* Copyright (c) 2015, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -302,6 +302,7 @@ static OMRPortLibrary MasterPortLibraryTable = {
omrheap_query_size, /* heap_query_size */
omrheap_grow, /* heap_grow*/
#if defined(OMR_PORT_SOCKET_SUPPORT)
omrsock_startup, /* sock_startup */
omrsock_getaddrinfo_create_hints, /* sock_getaddrinfo_create_hints */
omrsock_getaddrinfo, /* sock_getaddrinfo */
omrsock_getaddrinfo_length, /* sock_getaddrinfo_length */
Expand All @@ -319,6 +320,7 @@ static OMRPortLibrary MasterPortLibraryTable = {
omrsock_recv, /* sock_recv */
omrsock_recvfrom, /* sock_recvfrom */
omrsock_close, /* sock_close */
omrsock_shutdown, /* sock_shutdown */
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
#if defined(OMR_OPT_CUDA)
NULL, /* cuda_configData */
Expand Down Expand Up @@ -446,6 +448,9 @@ omrport_shutdown_library(struct OMRPortLibrary *portLibrary)
#if defined(OMR_OPT_CUDA)
portLibrary->cuda_shutdown(portLibrary);
#endif /* OMR_OPT_CUDA */
#if defined(OMR_PORT_SOCKET_SUPPORT)
portLibrary->sock_shutdown(portLibrary);
caohaley marked this conversation as resolved.
Show resolved Hide resolved
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
portLibrary->introspect_shutdown(portLibrary);
portLibrary->sig_shutdown(portLibrary);
portLibrary->str_shutdown(portLibrary);
Expand Down Expand Up @@ -647,6 +652,13 @@ omrport_startup_library(struct OMRPortLibrary *portLibrary)
goto cleanup;
}

#if defined(OMR_PORT_SOCKET_SUPPORT)
rc = portLibrary->sock_startup(portLibrary);
caohaley marked this conversation as resolved.
Show resolved Hide resolved
if (0 != rc) {
goto cleanup;
}
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */

caohaley marked this conversation as resolved.
Show resolved Hide resolved
#if defined(OMR_OPT_CUDA)
rc = portLibrary->cuda_startup(portLibrary);
if (0 != rc) {
Expand Down
Loading