-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RTEMS TCP/UDP Support #283
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f43e596
Fixes memory leak due to not deleting freertos socket set (#270)
bjv-capra b20b8cd
RTEMS support
roncapat 7fe7719
Add RTEMS discovery support
roncapat 8ea7240
Fix FDSET issue
roncapat fa8cc12
Merge branch 'foxy' of https://github.com/eProsima/Micro-XRCE-DDS-Cli…
roncapat a8126de
Cleanup
roncapat e31c747
Uncrustify
roncapat 48489e8
Update src/c/profile/transport/ip/tcp/tcp_transport_rtems_bsd_net.c
roncapat ac18bed
Update CMakeLists.txt
roncapat a9fb179
Update udp_transport_datagram_rtems_bsd_net.c
roncapat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
include/uxr/client/profile/transport/ip/tcp/tcp_transport_rtems_bsd_net.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef _UXR_CLIENT_TCP_TRANSPORT_RTEMS_H_ | ||
#define _UXR_CLIENT_TCP_TRANSPORT_RTEMS_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif // ifdef __cplusplus | ||
|
||
#include "arpa/inet.h" | ||
#include "sys/socket.h" | ||
#include "sys/select.h" | ||
#include "netinet/in.h" | ||
|
||
|
||
typedef struct uxrTCPPlatform | ||
{ | ||
struct sockaddr_in remote_addr; | ||
struct fd_set select_fd; | ||
int fd; | ||
} uxrTCPPlatform; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // ifdef __cplusplus | ||
|
||
#endif //_UXR_CLIENT_TCP_TRANSPORT_RTEMS_H_ |
39 changes: 39 additions & 0 deletions
39
include/uxr/client/profile/transport/ip/udp/udp_transport_rtems_bsd_net.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef _UXR_CLIENT_UDP_TRANSPORT_RTEMS_H_ | ||
#define _UXR_CLIENT_UDP_TRANSPORT_RTEMS_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif // ifdef __cplusplus | ||
|
||
#include "arpa/inet.h" | ||
#include "sys/socket.h" | ||
#include "sys/select.h" | ||
#include "netinet/in.h" | ||
|
||
typedef struct uxrUDPPlatform | ||
{ | ||
struct sockaddr_in remote_addr; | ||
struct fd_set select_fd; | ||
int fd; | ||
} uxrUDPPlatform; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // ifdef __cplusplus | ||
|
||
#endif //_UXR_CLIENT_UDP_TRANSPORT_RTEMS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/c/profile/discovery/transport/udp_transport_datagram_rtems_bsd_net.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright 2018 eSOL Co.,Ltd. | ||
// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "udp_transport_datagram_internal.h" | ||
#include "arpa/inet.h" | ||
#include "sys/socket.h" | ||
#include "netinet/in.h" | ||
|
||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
|
||
bool uxr_init_udp_transport_datagram( | ||
uxrUDPTransportDatagram* transport) | ||
{ | ||
bool rv = false; | ||
|
||
transport->fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
|
||
if (-1 != transport->fd) | ||
{ | ||
/* Poll setup. */ | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wsign-conversion" | ||
FD_ZERO(&transport->select_fd); | ||
FD_SET(transport->fd, &transport->select_fd); | ||
#pragma GCC diagnostic pop | ||
rv = true; | ||
} | ||
|
||
return rv; | ||
} | ||
|
||
bool uxr_close_udp_transport_datagram( | ||
uxrUDPTransportDatagram* transport) | ||
{ | ||
(void) close(transport->fd); | ||
|
||
return true; | ||
} | ||
|
||
bool uxr_udp_send_datagram_to( | ||
uxrUDPTransportDatagram* transport, | ||
const uint8_t* buf, | ||
size_t len, | ||
const TransportLocator* locator) | ||
{ | ||
bool rv = true; | ||
|
||
struct sockaddr_in remote_addr; | ||
memcpy(&remote_addr.sin_addr.s_addr, &locator->_.medium_locator.address, sizeof(locator->_.medium_locator.address)); | ||
if (0 != remote_addr.sin_addr.s_addr) | ||
{ | ||
remote_addr.sin_family = AF_INET; | ||
remote_addr.sin_port = htons(locator->_.medium_locator.locator_port); | ||
|
||
int32_t bytes_sent = sendto(transport->fd, (void*)buf, len, 0, | ||
(struct sockaddr*)&remote_addr, sizeof(remote_addr)); | ||
|
||
if (0 >= bytes_sent) | ||
{ | ||
rv = false; | ||
} | ||
} | ||
|
||
return rv; | ||
} | ||
|
||
bool uxr_udp_recv_datagram( | ||
uxrUDPTransportDatagram* transport, | ||
uint8_t** buf, | ||
size_t* len, | ||
int timeout) | ||
{ | ||
bool rv = false; | ||
|
||
struct timeval tv; | ||
tv.tv_sec = timeout / 1000; | ||
tv.tv_usec = (timeout % 1000) * 1000; | ||
|
||
|
||
int32_t poll_rv = select(transport->fd + 1, &transport->select_fd, NULL, NULL, &tv); | ||
if (0 < poll_rv) | ||
{ | ||
int32_t bytes_received = recvfrom(transport->fd, (void*)transport->buffer, sizeof(transport->buffer), | ||
0, NULL, NULL); | ||
if (0 < bytes_received) | ||
{ | ||
*len = (size_t)bytes_received; | ||
*buf = transport->buffer; | ||
rv = true; | ||
} | ||
} | ||
else if (0 == poll_rv) | ||
{ | ||
errno = ETIME; | ||
} | ||
|
||
return rv; | ||
} | ||
|
||
void uxr_bytes_to_ip( | ||
const uint8_t* bytes, | ||
char* ip) | ||
{ | ||
uint32_t addr; | ||
addr = (uint32_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); | ||
struct in_addr saddr; | ||
saddr.s_addr = addr; | ||
char* res = inet_ntoa(saddr); | ||
strncpy(ip, res, 16); // 16 == MAX_IPv4_LEN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <uxr/client/profile/transport/ip/ip.h> | ||
#include <uxr/client/config.h> | ||
|
||
#include "sys/socket.h" | ||
#include "arpa/inet.h" | ||
#include <netinet/in.h> | ||
#include <string.h> | ||
|
||
bool uxr_ip_to_locator( | ||
char const* ip, | ||
uint16_t port, | ||
uxrIpProtocol ip_protocol, | ||
TransportLocator* locator) | ||
{ | ||
bool result = false; | ||
switch (ip_protocol) | ||
{ | ||
case UXR_IPv4: | ||
locator->format = ADDRESS_FORMAT_MEDIUM; | ||
locator->_.medium_locator.locator_port = port; | ||
uint32_t addr = inet_addr(ip); | ||
memcpy(&locator->_.medium_locator.address, &addr, sizeof(locator->_.medium_locator.address)); | ||
result = locator->_.medium_locator.address != 0; | ||
break; | ||
case UXR_IPv6: | ||
break; | ||
default: | ||
break; | ||
} | ||
return result; | ||
} | ||
|
||
bool uxr_locator_to_ip( | ||
TransportLocator const* locator, | ||
char* ip, | ||
size_t size, | ||
uint16_t* port, | ||
uxrIpProtocol* ip_protocol) | ||
{ | ||
bool result = false; | ||
(void)size; | ||
switch (locator->format) | ||
{ | ||
case ADDRESS_FORMAT_MEDIUM: | ||
*port = locator->_.medium_locator.locator_port; | ||
*ip_protocol = UXR_IPv4; | ||
struct in_addr saddr; | ||
uint32_t addr; | ||
memcpy(&addr, &locator->_.medium_locator.address, sizeof(locator->_.medium_locator.address)); | ||
saddr.s_addr = addr; | ||
char* res = inet_ntoa(saddr); | ||
strncpy(ip, res, 16); // 16 == MAX_IPv4_LEN | ||
result = true; | ||
break; | ||
case ADDRESS_FORMAT_LARGE: | ||
break; | ||
default: | ||
break; | ||
} | ||
return result; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The same FD_ZERO FD_SET treatment before select() should be done here. Will post a new PR soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks. We will handle it in a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! We missed that the set object is modified.
We also use a select approach on the multi-serial agent, where it is enough to copy the set on a local variable, check here: link (
read_fds
is equivalent to yourtransport->select_fd
).With this approach you avoid modifications on external data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, cleaner! I will also then update the other two usages of select() like this.