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..b70e713228b 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 -1; + } + + 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 -1; + } + + return bytesRecv; } int32_t