Skip to content

Commit

Permalink
Added Unix Implementations for Send and Recv
Browse files Browse the repository at this point in the history
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: eclipse-omr#5069

Signed-off-by: Haley Cao <haleycao88@hotmail.com>
  • Loading branch information
Haley Cao committed Apr 28, 2020
1 parent 412230d commit aaab428
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include_core/omrporterror.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@
#define OMRPORT_ERROR_SOCK_LISTEN_FAILED (OMRPORT_ERROR_SOCK_BASE - 7)
#define OMRPORT_ERROR_SOCK_CONNECT_FAILED (OMRPORT_ERROR_SOCK_BASE - 8)
#define OMRPORT_ERROR_SOCK_ACCEPT_FAILED (OMRPORT_ERROR_SOCK_BASE - 9)
#define OMRPORT_ERROR_SOCK_SEND_FAILED (OMRPORT_ERROR_SOCK_BASE - 10)
#define OMRPORT_ERROR_SOCK_RECV_FAILED (OMRPORT_ERROR_SOCK_BASE - 11)
/**
* @}
*/
Expand Down
29 changes: 27 additions & 2 deletions port/unix/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,20 @@ 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
Expand All @@ -559,7 +572,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
Expand Down

0 comments on commit aaab428

Please sign in to comment.