@@ -61,23 +61,35 @@ UdpSocket<EndpointType> &UdpSocket<EndpointType>::operator=(UdpSocket &&socket)
61
61
62
62
// ==================================================================================================
63
63
template <typename EndpointType>
64
- size_t UdpSocket<EndpointType>::send(const EndpointType &endpoint, std::string_view message) const
64
+ size_t UdpSocket<EndpointType>::send(const EndpointType &endpoint, std::string_view message)
65
65
{
66
66
bool would_block = false ;
67
67
68
- return fly::net::detail::send_to (
68
+ std:: size_t bytes_sent = fly::net::detail::send_to (
69
69
handle (),
70
70
endpoint,
71
71
std::move (message),
72
72
m_packet_size,
73
73
would_block);
74
+
75
+ if (bytes_sent == 0 )
76
+ {
77
+ SLOGW (handle (), " Error sending to {}, closing" , endpoint);
78
+ close ();
79
+ }
80
+ else
81
+ {
82
+ SLOGD (handle (), " Sent {} bytes to {}" , bytes_sent, endpoint);
83
+ }
84
+
85
+ return bytes_sent;
74
86
}
75
87
76
88
// ==================================================================================================
77
89
template <typename EndpointType>
78
90
size_t
79
91
UdpSocket<EndpointType>::send(std::string_view hostname, port_type port, std::string_view message)
80
- const
92
+
81
93
{
82
94
if (auto endpoint = hostname_to_endpoint (std::move (hostname)); endpoint)
83
95
{
@@ -130,12 +142,25 @@ bool UdpSocket<EndpointType>::send_async(
130
142
131
143
// ==================================================================================================
132
144
template <typename EndpointType>
133
- std::string UdpSocket<EndpointType>::receive() const
145
+ std::string UdpSocket<EndpointType>::receive()
134
146
{
135
147
EndpointType endpoint;
136
148
bool would_block = false ;
137
149
138
- return fly::net::detail::recv_from (handle (), endpoint, m_packet_size, would_block);
150
+ const std::string received =
151
+ fly::net::detail::recv_from (handle (), endpoint, m_packet_size, would_block);
152
+
153
+ if (received.size () == 0 )
154
+ {
155
+ SLOGW (handle (), " Error receiving, closing" );
156
+ close ();
157
+ }
158
+ else
159
+ {
160
+ SLOGD (handle (), " Received {} bytes from {}" , received.size (), endpoint);
161
+ }
162
+
163
+ return received;
139
164
}
140
165
141
166
// ==================================================================================================
0 commit comments