Skip to content

Commit

Permalink
Setting Up Support for Socket Options
Browse files Browse the repository at this point in the history
Setting up socket option definitions and function prototype

- Set up omrsock_linger_t pointer, OMRLinger struct to be used
  in the linger socket option.
- Set up omrsock_timeval_t pointer, OMRTimeval struct to be used
  in the timeval socket option.
- Set up omr public socket option definitions and private os
  socket option definitions.
- Set up functions prototypes for the socket option related
  functions for types integer, timeval and linger struct.

Issue: eclipse-omr#5158

Signed-off-by: Haley Cao <haleycao88@hotmail.com>
  • Loading branch information
Haley Cao committed May 22, 2020
1 parent 45f1b9b commit cdd54d5
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 4 deletions.
24 changes: 24 additions & 0 deletions include_core/omrport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,22 @@ typedef struct OMRPortLibrary {
uint32_t (*sock_htonl)(struct OMRPortLibrary *portLibrary, uint32_t val) ;
/** see @ref omrsock.c::omrsock_inet_pton "omrsock_inet_pton"*/
int32_t (*sock_inet_pton)(struct OMRPortLibrary *portLibrary, int32_t addrFamily, const char *addr, uint8_t *addrNetworkOrder) ;
/** see @ref omrsock.c::omrsock_timeval_init "omrsock_timeval_init"*/
int32_t (*sock_timeval_init)(struct OMRPortLibrary *portLibrary, omrsock_timeval_t handle, uint32_t secTime, uint32_t uSecTime) ;
/** see @ref omrsock.c::omrsock_linger_init "omrsock_linger_init"*/
int32_t (*sock_linger_init)(struct OMRPortLibrary *portLibrary, omrsock_linger_t handle, int32_t enabled, uint32_t timeout) ;
/** see @ref omrsock.c::omrsock_setsockopt_int "omrsock_setsockopt_int"*/
int32_t (*sock_setsockopt_int)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval) ;
/** see @ref omrsock.c::omrsock_setsockopt_linger "omrsock_setsockopt_linger"*/
int32_t (*sock_setsockopt_linger)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval) ;
/** see @ref omrsock.c::omrsock_setsockopt_timeval "omrsock_setsockopt_timeval"*/
int32_t (*sock_setsockopt_timeval)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval) ;
/** see @ref omrsock.c::omrsock_getsockopt_int "omrsock_getsockopt_int"*/
int32_t (*sock_getsockopt_int)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval) ;
/** see @ref omrsock.c::omrsock_getsockopt_linger "omrsock_getsockopt_linger"*/
int32_t (*sock_getsockopt_linger)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval) ;
/** see @ref omrsock.c::omrsock_getsockopt_timeval "omrsock_getsockopt_timeval"*/
int32_t (*sock_getsockopt_timeval)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval) ;
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
#if defined(OMR_OPT_CUDA)
/** CUDA configuration data */
Expand Down Expand Up @@ -2631,6 +2647,14 @@ extern J9_CFUNC int32_t omrport_getVersion(struct OMRPortLibrary *portLibrary);
#define omrsock_htons(param1) privateOmrPortLibrary->sock_htons(privateOmrPortLibrary, (param1))
#define omrsock_htonl(param1) privateOmrPortLibrary->sock_htonl(privateOmrPortLibrary, (param1))
#define omrsock_inet_pton(param1) privateOmrPortLibrary->sock_inet_pton(privateOmrPortLibrary, (param1))
#define omrsock_timeval_init(param1,param2,param3) privateOmrPortLibrary->sock_timeval_init(privateOmrPortLibrary, (param1), (param2), (param3))
#define omrsock_linger_init(param1,param2,param3) privateOmrPortLibrary->sock_linger_init(privateOmrPortLibrary, (param1), (param2), (param3))
#define omrsock_setsockopt_int(param1,param2,param3,param4) privateOmrPortLibrary->sock_setsockopt_int(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_setsockopt_linger(param1,param2,param3,param4) privateOmrPortLibrary->sock_setsockopt_linger(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_setsockopt_timeval(param1,param2,param3,param4) privateOmrPortLibrary->sock_setsockopt_timeval(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_getsockopt_int(param1,param2,param3,param4) privateOmrPortLibrary->sock_getsockopt_int(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_getsockopt_linger(param1,param2,param3,param4) privateOmrPortLibrary->sock_getsockopt_linger(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_getsockopt_timeval(param1,param2,param3,param4) privateOmrPortLibrary->sock_getsockopt_timeval(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */

#if defined(OMR_OPT_CUDA)
Expand Down
21 changes: 18 additions & 3 deletions include_core/omrportsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ typedef struct OMRSockAddrStorage *omrsock_sockaddr_t;
/* Pointer to OMRSocket, a struct that contains socket descriptor. */
typedef struct OMRSocket *omrsock_socket_t;

/* Pointer to OMRTimeval, a struct that contains struct timeval. */
typedef struct OMRTimeval *omrsock_timeval_t;

/* Pointer to OMRLinger, a struct that contains struct linger.*/
typedef struct OMRLinger *omrsock_linger_t;

/* Bind to all available interfaces */
#define OMRSOCK_INADDR_ANY ((uint32_t)0)

Expand All @@ -47,9 +53,18 @@ typedef struct OMRSocket *omrsock_socket_t;
#define OMRSOCK_STREAM 1
#define OMRSOCK_DGRAM 2

/* Protocol Family */
/* Protocol Family and Socket Levels */
#define OMRSOCK_IPPROTO_DEFAULT 0
#define OMRSOCK_IPPROTO_TCP 1
#define OMRSOCK_IPPROTO_UDP 2
#define OMRSOCK_SOL_SOCKET 1
#define OMRSOCK_IPPROTO_TCP 2
#define OMRSOCK_IPPROTO_UDP 3

/* Socket Options */
#define OMRSOCK_SO_REUSEADDR 1
#define OMRSOCK_SO_KEEPALIVE 2
#define OMRSOCK_SO_LINGER 3
#define OMRSOCK_SO_RCVTIMEO 4
#define OMRSOCK_SO_SNDTIMEO 5
#define OMRSOCK_TCP_NODELAY 6

#endif /* !defined(OMRPORTSOCK_H_) */
16 changes: 15 additions & 1 deletion include_core/omrportsocktypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ typedef struct OMRSocket {
} OMRSocket;

/**
* A node in a linked-list of addrinfo. Filled in using @ref omr_getaddrinfo.
* A node in a linked-list of addrinfo. Filled in using @ref omrsock_getaddrinfo.
*/
typedef struct OMRAddrInfoNode {
/**
Expand All @@ -100,4 +100,18 @@ typedef struct OMRAddrInfoNode {
uint32_t length;
} OMRAddrInfoNode;

/**
* A struct for storing timeval values. Filled in using @ref omrsock_timeval_init.
*/
typedef struct OMRTimeval {
struct timeval data;
} OMRTimeval;

/**
* A struct for storing linger values. Filled in using @ref omrsock_linger_init.
*/
typedef struct OMRLinger {
struct linger data;
} OMRLinger;

#endif /* !defined(OMRPORTSOCKTYPES_H_) */
8 changes: 8 additions & 0 deletions port/common/omrport.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ static OMRPortLibrary MasterPortLibraryTable = {
omrsock_htons, /* sock_htons */
omrsock_htonl, /* sock_htonl */
omrsock_inet_pton, /* sock_inet_pton */
omrsock_timeval_init, /* sock_timeval_init */
omrsock_linger_init, /* sock_linger_init */
omrsock_setsockopt_int, /* sock_setsockopt_int */
omrsock_setsockopt_linger, /* sock_setsockopt_linger */
omrsock_setsockopt_timeval, /* sock_setsockopt_timeval */
omrsock_getsockopt_int, /* sock_getsockopt_int */
omrsock_getsockopt_linger, /* sock_getsockopt_linger */
omrsock_getsockopt_timeval, /* sock_getsockopt_timeval */
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
#if defined(OMR_OPT_CUDA)
NULL, /* cuda_configData */
Expand Down
149 changes: 149 additions & 0 deletions port/common/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,153 @@ omrsock_inet_pton(struct OMRPortLibrary *portLibrary, int32_t addrFamily, const
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Create a time structure, representing the timeout period defined in seconds & microSeconds. Timeval's could be
* used as timeout arguments in the @ref omrsock_setsockopt function.
*
* @param[in] portLibrary The port library.
* @param[out] handle Pointer pointer to the OMRTimeval to be allocated.
* @param[in] secTime The integer component of the timeout value (in seconds).
* @param[in] uSecTime The fractional component of the timeout value (in microseconds).
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_timeval_init(struct OMRPortLibrary *portLibrary, omrsock_timeval_t handle, uint32_t secTime, uint32_t uSecTime)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Initializes a new linger structure, enabled or disabled, with the timeout as specified. Linger defines the
* behavior when unsent messages exist for a socket that has been sent close.
*
* If linger is disabled, the default, close returns immediately and the stack attempts to deliver unsent messages.
* If linger is enabled:
* \arg if the timeout is 0, the close will block indefinitely until the messages are sent.
* \arg if the timeout is set, the close will return after the messages are sent or the timeout period expired.
*
* @param[in] portLibrary The port library.
* @param[in] handle Pointer to the linger struct to be accessed.
* @param[in] enabled Aero to disable, a non-zero value to enable linger.
* @param[in] timeout A positive timeout value from 0 to linger indefinitely (in seconds).
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_linger_init(struct OMRPortLibrary *portLibrary, omrsock_linger_t handle, int32_t enabled, uint32_t timeout)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Set the integer value of the socket option.
* Refer to the private get_os_socket_level & get_os_socket_option functions for details of the options
* supported.
*
* @param[in] portLibrary The port library.
* @param[in] handle Pointer to the socket to set the option in.
* @param[in] optlevel The level within the IP stack at which the option is defined.
* @param[in] optname The name of the option to set.
* @param[in] optval Pointer to the option value to update the socket option with.
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_setsockopt_int(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Set the linger value on the socket.
* See the @ref omrsock_linger_init for setting up the linger struct and details of the linger behavior.
*
* @param[in] portLibrary The port library.
* @param[in] handle Pointer to the socket to set the option in.
* @param[in] optlevel The level within the IP stack at which the option is defined.
* @param[in] optname The name of the option to set.
* @param[in] optval Pointer to the option value to update the socket option with.
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_setsockopt_linger(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Set the timeval value on the socket.
* See the @ref omrsock_timeval_init for setting up the timeval struct details of the timeval behavior.
*
* @param[in] portLibrary The port library.
* @param[in] handle Pointer to the socket to set the option in.
* @param[in] optlevel The level within the IP stack at which the option is defined.
* @param[in] optname The name of the option to set.
* @param[in] optval Pointer to the option value to update the socket option with.
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_setsockopt_timeval(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Answer the integer value of the socket option.
* Refer to the private get_os_socket_level & get_os_socket_option functions for details of the options
* supported.
*
* @param[in] portLibrary The port library.
* @param[in] handle Pointer to the socket to query for the option value.
* @param[in] optlevel The level within the IP stack at which the option is defined.
* @param[in] optname The name of the option to retrieve.
* @param[out] optval Pointer to the pre-allocated space to update with the option value.
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_getsockopt_int(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Answer the linger value on the socket.
* See the @ref omrsock_linger_init for setting up the linger struct and details of the linger behavior.
*
* @param[in] portLibrary The port library.
* @param[in] handle Pointer to the socket to query for the option value.
* @param[in] optlevel The level within the IP stack at which the option is defined.
* @param[in] optname The name of the option to retrieve.
* @param[out] optval Pointer to the pre-allocated space to update with the option value.
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_getsockopt_linger(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Answer the timeval value on the socket.
* See the @ref omrsock_timeval_init for setting up the timeval struct details of the timeval behavior.
*
* @param[in] portLibrary The port library.
* @param[in] handle Pointer to the socket to query for the option value.
* @param[in] optlevel The level within the IP stack at which the option is defined.
* @param[in] optname The name of the option to retrieve.
* @param[out] optval Pointer to the pre-allocated space to update with the option value.
*
* @return 0, if no errors occurred, otherwise return an error.
*/
int32_t
omrsock_getsockopt_timeval(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
16 changes: 16 additions & 0 deletions port/omrportpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,22 @@ extern J9_CFUNC uint32_t
omrsock_htonl(struct OMRPortLibrary *portLibrary, uint32_t val);
extern J9_CFUNC int32_t
omrsock_inet_pton(struct OMRPortLibrary *portLibrary, int32_t addrFamily, const char *addr, uint8_t *addrNetworkOrder);
extern J9_CFUNC int32_t
omrsock_timeval_init(struct OMRPortLibrary *portLibrary, omrsock_timeval_t handle, uint32_t secTime, uint32_t uSecTime);
extern J9_CFUNC int32_t
omrsock_linger_init(struct OMRPortLibrary *portLibrary, omrsock_linger_t handle, int32_t enabled, uint32_t timeout);
extern J9_CFUNC int32_t
omrsock_setsockopt_int(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval);
extern J9_CFUNC int32_t
omrsock_setsockopt_linger(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval);
extern J9_CFUNC int32_t
omrsock_setsockopt_timeval(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval);
extern J9_CFUNC int32_t
omrsock_getsockopt_int(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval);
extern J9_CFUNC int32_t
omrsock_getsockopt_linger(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval);
extern J9_CFUNC int32_t
omrsock_getsockopt_timeval(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval);
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */

/* J9SourceJ9Str*/
Expand Down
48 changes: 48 additions & 0 deletions port/unix/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,52 @@ omrsock_inet_pton(struct OMRPortLibrary *portLibrary, int32_t addrFamily, const

}

int32_t
omrsock_timeval_init(struct OMRPortLibrary *portLibrary, omrsock_timeval_t handle, uint32_t secTime, uint32_t uSecTime)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

int32_t
omrsock_linger_init(struct OMRPortLibrary *portLibrary, omrsock_linger_t handle, int32_t enabled, uint32_t timeout)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

int32_t
omrsock_setsockopt_int(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

int32_t
omrsock_setsockopt_linger(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

int32_t
omrsock_setsockopt_timeval(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

int32_t
omrsock_getsockopt_int(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, int32_t *optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

int32_t
omrsock_getsockopt_linger(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_linger_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

int32_t
omrsock_getsockopt_timeval(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, omrsock_timeval_t optval)
{
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
10 changes: 10 additions & 0 deletions port/unix_include/omrsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This exposes some definitions needed by the socket api
*/
#include <sys/types.h> /* Some historical implementations need this file, POSIX.1-2001 does not. */
#include <sys/socket.h>
#include <netinet/tcp.h>

typedef struct sockaddr omr_os_sockaddr;
typedef struct sockaddr_in omr_os_sockaddr_in; /* IPv4 */
Expand All @@ -57,7 +58,16 @@ typedef struct sockaddr_in6 omr_os_sockaddr_in6; /* IPv6 */

/* Protocol */
#define OS_SOCK_IPPROTO_DEFAULT 0
#define OS_SOL_SOCKET SOL_SOCKET
#define OS_SOCK_IPPROTO_TCP IPPROTO_TCP
#define OS_SOCK_IPPROTO_UDP IPPROTO_UDP

/* Socket options*/
#define OS_SO_REUSEADDR SO_REUSEADDR
#define OS_SO_KEEPALIVE SO_KEEPALIVE
#define OS_SO_LINGER SO_LINGER
#define OS_SO_RCVTIMEO SO_RCVTIMEO
#define OS_SO_SNDTIMEO SO_SNDTIMEO
#define OS_TCP_NODELAY TCP_NODELAY

#endif /* !defined(OMRSOCK_H_) */
Loading

0 comments on commit cdd54d5

Please sign in to comment.