85 m_SocketFD = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
87 throw std::runtime_error(
"PositionListener::ListenLoop()::socket()");
92 throw std::runtime_error(
"PositionListener::ListenLoop::setsockopt::reuse");
95 int rx_buffer_size = 1024;
97 throw std::runtime_error(
"PositionListener::ListenLoop()::setsockopt::rcvbuf");
100 struct sockaddr_in dg_addr;
101 memset(&dg_addr, 0,
sizeof(dg_addr));
102 dg_addr.sin_family = AF_INET;
104 dg_addr.sin_addr.s_addr = htonl(INADDR_ANY);
105 dg_addr.sin_port = htons(
m_Port);
107 if (bind(
m_SocketFD, (
struct sockaddr *)&dg_addr,
sizeof(dg_addr)) == -1)
108 throw std::runtime_error(
"PositionListener::ListenLoop()::bind");
112 std::vector<char> incoming_buffer(pd.
size() * 2);
117 if (
p_Owner->debugLevel() >= 3)
119 int num_bytes_read = recvfrom(
m_SocketFD, (
char *)incoming_buffer.data(), (
int)incoming_buffer.size(), 0, 0, 0);
120 if (num_bytes_read < 0)
122 LOG_MSG_ERROR(
"Error reading from UDP port: " << num_bytes_read);
125 if (
p_Owner->debugLevel() >= 3)
126 LOG_MSG_INFO(
"Received " << num_bytes_read <<
" bytes from peer");
129 pd.
deserialize(incoming_buffer.data(), incoming_buffer.size());
132 catch (
const std::exception &e)
134 LOG_MSG_ERROR(
"Caught exception while reading position data: " << e.what() <<
" - " << std::strerror(errno));
140 catch (
const std::exception &e)
142 LOG_MSG_ERROR(
"Caught exception in listening thread: " << e.what() <<
" - " << std::strerror(errno));