From eed82253ac83973a9c38bb6dc9d03610a89c8a25 Mon Sep 17 00:00:00 2001 From: Haley Cao Date: Mon, 27 Apr 2020 04:06:00 +0000 Subject: [PATCH] Added Unix Implementations for Send and Recv Added Send and Recv to OMRSOCK API - Simply calls the system socket api send and recv. - System send and recv will block until the message is sent or received. - Added small argument testing and set the error codes from system socket api. Issue: #5069 Signed-off-by: Haley Cao --- include_core/omrporterror.h | 2 ++ port/unix/omrsock.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include_core/omrporterror.h b/include_core/omrporterror.h index 54fada50b83..9e5c6cd8def 100644 --- a/include_core/omrporterror.h +++ b/include_core/omrporterror.h @@ -333,6 +333,8 @@ #define OMRPORT_ERROR_SOCK_LISTEN_FAILED (OMRPORT_ERROR_SOCK_BASE - 8) #define OMRPORT_ERROR_SOCK_CONNECT_FAILED (OMRPORT_ERROR_SOCK_BASE - 9) #define OMRPORT_ERROR_SOCK_ACCEPT_FAILED (OMRPORT_ERROR_SOCK_BASE - 10) +#define OMRPORT_ERROR_SOCK_SEND_FAILED (OMRPORT_ERROR_SOCK_BASE - 11) +#define OMRPORT_ERROR_SOCK_RECV_FAILED (OMRPORT_ERROR_SOCK_BASE - 12) /** * @} */ diff --git a/port/unix/omrsock.c b/port/unix/omrsock.c index a5acabd6c10..c961b5aa3e9 100644 --- a/port/unix/omrsock.c +++ b/port/unix/omrsock.c @@ -550,7 +550,19 @@ omrsock_accept(struct OMRPortLibrary *portLibrary, omrsock_socket_t serverSock, int32_t omrsock_send(struct OMRPortLibrary *portLibrary, omrsock_socket_t sock, uint8_t *buf, int32_t nbyte, int32_t flags) { - return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM; + int32_t bytesSent = 0; + + if (NULL == sock || 0 >= nbyte) { + return OMRPORT_ERROR_INVALID_ARGUMENTS; + } + + bytesSent = send(sock->data, buf, nbyte, flags); + if(-1 == bytesSent) { + portLibrary->error_set_last_error(portLibrary, errno, OMRPORT_ERROR_SOCK_SEND_FAILED); + return OMRPORT_ERROR_SOCK_SEND_FAILED; + } + + return bytesSent; } int32_t @@ -562,7 +574,19 @@ omrsock_sendto(struct OMRPortLibrary *portLibrary, omrsock_socket_t sock, uint8_ int32_t omrsock_recv(struct OMRPortLibrary *portLibrary, omrsock_socket_t sock, uint8_t *buf, int32_t nbyte, int32_t flags) { - return OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM; + int32_t bytesRecv = 0; + + if (NULL == sock || 0 >= nbyte) { + return OMRPORT_ERROR_INVALID_ARGUMENTS; + } + + bytesRecv = recv(sock->data, buf, nbyte, flags); + if (-1 == bytesRecv) { + portLibrary->error_set_last_error(portLibrary, errno, OMRPORT_ERROR_SOCK_RECV_FAILED); + return OMRPORT_ERROR_SOCK_RECV_FAILED; + } + + return bytesRecv; } int32_t