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 Jun 11, 2020
1 parent 0801863 commit 0e7fff5
Show file tree
Hide file tree
Showing 2 changed files with 28 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 @@ -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)
/**
* @}
*/
Expand Down
28 changes: 26 additions & 2 deletions port/unix/omrsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0e7fff5

Please sign in to comment.