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.

Issue: eclipse-omr#5158

Signed-off-by: Haley Cao <haleycao88@hotmail.com>
  • Loading branch information
Haley Cao committed May 20, 2020
1 parent 45f1b9b commit 34077ca
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 4 deletions.
12 changes: 12 additions & 0 deletions include_core/omrport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,14 @@ 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 "omrsock_setsockopt"*/
int32_t (*sock_setsockopt)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval) ;
/** see @ref omrsock.c::omrsock_getsockopt "omrsock_getsockopt"*/
int32_t (*sock_getsockopt)(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval) ;
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
#if defined(OMR_OPT_CUDA)
/** CUDA configuration data */
Expand Down Expand Up @@ -2631,6 +2639,10 @@ 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(param1,param2,param3,param4) privateOmrPortLibrary->sock_setsockopt(privateOmrPortLibrary, (param1), (param2), (param3), (param4))
#define omrsock_getsockopt(param1,param2,param3,param4) privateOmrPortLibrary->sock_getsockopt(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_) */
4 changes: 4 additions & 0 deletions port/common/omrport.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ 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, /* sock_setsockopt */
omrsock_getsockopt, /* sock_getsockopt */
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
#if defined(OMR_OPT_CUDA)
NULL, /* cuda_configData */
Expand Down
73 changes: 73 additions & 0 deletions port/common/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,77 @@ 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 value of the socket option.
* Refer to the private platform_socket_level & platform_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(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval) {
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

/**
* Answer the value of the socket option.
* Refer to the private platform_socket_level & platform_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(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval) {
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
8 changes: 8 additions & 0 deletions port/omrportpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ 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(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval);
extern J9_CFUNC int32_t
omrsock_getsockopt(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval);
#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */

/* J9SourceJ9Str*/
Expand Down
20 changes: 20 additions & 0 deletions port/unix/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,24 @@ 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(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval) {
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

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

#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */
9 changes: 9 additions & 0 deletions port/unix_include/omrsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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 OSK_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_) */
21 changes: 21 additions & 0 deletions port/win32/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,25 @@ omrsock_inet_pton(struct OMRPortLibrary *portLibrary, int32_t addrFamily, const
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

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(struct OMRPortLibrary *portLibrary, omrsock_socket_t handle, int32_t optlevel, int32_t optname, void *optval) {
return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM;
}

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


#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */

0 comments on commit 34077ca

Please sign in to comment.