Add flags parameter to send_to and receive_from functions.
This commit is contained in:
parent
f9b5f8f0cb
commit
ee3d7250b9
@ -400,6 +400,8 @@ public:
|
||||
*
|
||||
* @param length The size of the data to be sent, in bytes.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
@ -407,9 +409,10 @@ public:
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
size_t send_to(const void* data, size_t length, const Endpoint& destination)
|
||||
size_t send_to(const void* data, size_t length, message_flags flags,
|
||||
const Endpoint& destination)
|
||||
{
|
||||
return service_.send_to(impl_, data, length, destination,
|
||||
return service_.send_to(impl_, data, length, flags, destination,
|
||||
default_error_handler());
|
||||
}
|
||||
|
||||
@ -423,6 +426,8 @@ public:
|
||||
*
|
||||
* @param length The size of the data to be sent, in bytes.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param error_handler The handler to be called when an error occurs. Copies
|
||||
@ -435,10 +440,11 @@ public:
|
||||
* @returns The number of bytes sent.
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t send_to(const void* data, size_t length, const Endpoint& destination,
|
||||
Error_Handler error_handler)
|
||||
size_t send_to(const void* data, size_t length, message_flags flags,
|
||||
const Endpoint& destination, Error_Handler error_handler)
|
||||
{
|
||||
return service_.send_to(impl_, data, length, destination, error_handler);
|
||||
return service_.send_to(impl_, data, length, flags, destination,
|
||||
error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@ -452,6 +458,8 @@ public:
|
||||
*
|
||||
* @param length The size of the data to be sent, in bytes.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
@ -464,10 +472,10 @@ public:
|
||||
* ); @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_send_to(const void* data, size_t length,
|
||||
void async_send_to(const void* data, size_t length, message_flags flags,
|
||||
const Endpoint& destination, Handler handler)
|
||||
{
|
||||
service_.async_send_to(impl_, data, length, destination, handler);
|
||||
service_.async_send_to(impl_, data, length, flags, destination, handler);
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
@ -481,6 +489,8 @@ public:
|
||||
* @param max_length The maximum length, in bytes, of data that can be held
|
||||
* in the supplied buffer.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
@ -489,10 +499,11 @@ public:
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
size_t receive_from(void* data, size_t max_length, Endpoint& sender_endpoint)
|
||||
size_t receive_from(void* data, size_t max_length, message_flags flags,
|
||||
Endpoint& sender_endpoint)
|
||||
{
|
||||
return service_.receive_from(impl_, data, max_length, sender_endpoint,
|
||||
default_error_handler());
|
||||
return service_.receive_from(impl_, data, max_length, flags,
|
||||
sender_endpoint, default_error_handler());
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
@ -506,6 +517,8 @@ public:
|
||||
* @param max_length The maximum length, in bytes, of data that can be held
|
||||
* in the supplied buffer.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
@ -519,11 +532,11 @@ public:
|
||||
* @returns The number of bytes received.
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t receive_from(void* data, size_t max_length, Endpoint& sender_endpoint,
|
||||
Error_Handler error_handler)
|
||||
size_t receive_from(void* data, size_t max_length, message_flags flags,
|
||||
Endpoint& sender_endpoint, Error_Handler error_handler)
|
||||
{
|
||||
return service_.receive_from(impl_, data, max_length, sender_endpoint,
|
||||
error_handler);
|
||||
return service_.receive_from(impl_, data, max_length, flags,
|
||||
sender_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@ -538,6 +551,8 @@ public:
|
||||
* @param max_length The maximum length, in bytes, of data that can be held
|
||||
* in the supplied buffer.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
@ -552,10 +567,10 @@ public:
|
||||
* ); @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_receive_from(void* data, size_t max_length,
|
||||
void async_receive_from(void* data, size_t max_length, message_flags flags,
|
||||
Endpoint& sender_endpoint, Handler handler)
|
||||
{
|
||||
service_.async_receive_from(impl_, data, max_length, sender_endpoint,
|
||||
service_.async_receive_from(impl_, data, max_length, flags, sender_endpoint,
|
||||
handler);
|
||||
}
|
||||
|
||||
|
@ -565,8 +565,7 @@ public:
|
||||
*/
|
||||
size_t write(const void* data, size_t length)
|
||||
{
|
||||
return service_.send(impl_, data, length,
|
||||
message_flags(0), default_error_handler());
|
||||
return service_.send(impl_, data, length, 0, default_error_handler());
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
@ -595,7 +594,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
size_t write(const void* data, size_t length, Error_Handler error_handler)
|
||||
{
|
||||
return service_.send(impl_, data, length, message_flags(0), error_handler);
|
||||
return service_.send(impl_, data, length, 0, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
@ -624,7 +623,7 @@ public:
|
||||
template <typename Handler>
|
||||
void async_write(const void* data, size_t length, Handler handler)
|
||||
{
|
||||
service_.async_send(impl_, data, length, message_flags(0), handler);
|
||||
service_.async_send(impl_, data, length, 0, handler);
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
@ -647,8 +646,8 @@ public:
|
||||
*/
|
||||
size_t read(void* data, size_t max_length)
|
||||
{
|
||||
return service_.receive(impl_, data,
|
||||
max_length, message_flags(0), default_error_handler());
|
||||
return service_.receive(impl_, data, max_length, 0,
|
||||
default_error_handler());
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
@ -677,8 +676,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
size_t read(void* data, size_t max_length, Error_Handler error_handler)
|
||||
{
|
||||
return service_.receive(impl_, data,
|
||||
max_length, message_flags(0), error_handler);
|
||||
return service_.receive(impl_, data, max_length, 0, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
@ -708,7 +706,7 @@ public:
|
||||
template <typename Handler>
|
||||
void async_read(void* data, size_t max_length, Handler handler)
|
||||
{
|
||||
service_.async_receive(impl_, data, max_length, message_flags(0), handler);
|
||||
service_.async_receive(impl_, data, max_length, 0, handler);
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream socket.
|
||||
|
@ -179,18 +179,21 @@ public:
|
||||
/// Send a datagram to the specified endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t send_to(impl_type& impl, const void* data, size_t length,
|
||||
const Endpoint& destination, Error_Handler error_handler)
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_impl_.send_to(impl, data, length, destination,
|
||||
return service_impl_.send_to(impl, data, length, flags, destination,
|
||||
error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_send_to(impl_type& impl, const void* data, size_t length,
|
||||
const Endpoint& destination, Handler handler)
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
Handler handler)
|
||||
{
|
||||
service_impl_.async_send_to(impl, data, length, destination, handler);
|
||||
service_impl_.async_send_to(impl, data, length, flags, destination,
|
||||
handler);
|
||||
}
|
||||
|
||||
/// Receive some data from the peer.
|
||||
@ -212,19 +215,21 @@ public:
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t receive_from(impl_type& impl, void* data, size_t max_length,
|
||||
Endpoint& sender_endpoint, Error_Handler error_handler)
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_impl_.receive_from(impl, data, max_length, sender_endpoint,
|
||||
error_handler);
|
||||
return service_impl_.receive_from(impl, data, max_length, flags,
|
||||
sender_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive that will get the endpoint of the sender.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_receive_from(impl_type& impl, void* data, size_t max_length,
|
||||
Endpoint& sender_endpoint, Handler handler)
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
service_impl_.async_receive_from(impl, data, max_length, sender_endpoint,
|
||||
handler);
|
||||
service_impl_.async_receive_from(impl, data, max_length, flags,
|
||||
sender_endpoint, handler);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -237,9 +237,10 @@ public:
|
||||
// sent.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t send_to(impl_type& impl, const void* data, size_t length,
|
||||
const Endpoint& destination, Error_Handler error_handler)
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
int bytes_sent = socket_ops::sendto(impl, data, length, 0,
|
||||
int bytes_sent = socket_ops::sendto(impl, data, length, flags,
|
||||
destination.native_data(), destination.native_size());
|
||||
if (bytes_sent < 0)
|
||||
{
|
||||
@ -254,11 +255,13 @@ public:
|
||||
{
|
||||
public:
|
||||
send_to_handler(impl_type impl, Demuxer& demuxer, const void* data,
|
||||
size_t length, const Endpoint& endpoint, Handler handler)
|
||||
size_t length, socket_base::message_flags flags,
|
||||
const Endpoint& endpoint, Handler handler)
|
||||
: impl_(impl),
|
||||
demuxer_(demuxer),
|
||||
data_(data),
|
||||
length_(length),
|
||||
flags_(flags),
|
||||
destination_(endpoint),
|
||||
handler_(handler)
|
||||
{
|
||||
@ -266,7 +269,7 @@ public:
|
||||
|
||||
void do_operation()
|
||||
{
|
||||
int bytes = socket_ops::sendto(impl_, data_, length_, 0,
|
||||
int bytes = socket_ops::sendto(impl_, data_, length_, flags_,
|
||||
destination_.native_data(), destination_.native_size());
|
||||
asio::error error(bytes < 0
|
||||
? socket_ops::get_error() : asio::error::success);
|
||||
@ -286,6 +289,7 @@ public:
|
||||
Demuxer& demuxer_;
|
||||
const void* data_;
|
||||
size_t length_;
|
||||
socket_base::message_flags flags_;
|
||||
Endpoint destination_;
|
||||
Handler handler_;
|
||||
};
|
||||
@ -294,7 +298,8 @@ public:
|
||||
// lifetime of the asynchronous operation.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_send_to(impl_type& impl, const void* data, size_t length,
|
||||
const Endpoint& destination, Handler handler)
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
Handler handler)
|
||||
{
|
||||
if (impl == null())
|
||||
{
|
||||
@ -305,7 +310,7 @@ public:
|
||||
{
|
||||
demuxer_.work_started();
|
||||
reactor_.start_write_op(impl, send_to_handler<Endpoint, Handler>(
|
||||
impl, demuxer_, data, length, destination, handler));
|
||||
impl, demuxer_, data, length, flags, destination, handler));
|
||||
}
|
||||
}
|
||||
|
||||
@ -397,10 +402,11 @@ public:
|
||||
// bytes received.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t receive_from(impl_type& impl, void* data, size_t max_length,
|
||||
Endpoint& sender_endpoint, Error_Handler error_handler)
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
socket_addr_len_type addr_len = sender_endpoint.native_size();
|
||||
int bytes_recvd = socket_ops::recvfrom(impl, data, max_length, 0,
|
||||
int bytes_recvd = socket_ops::recvfrom(impl, data, max_length, flags,
|
||||
sender_endpoint.native_data(), &addr_len);
|
||||
if (bytes_recvd < 0)
|
||||
{
|
||||
@ -418,11 +424,13 @@ public:
|
||||
{
|
||||
public:
|
||||
receive_from_handler(impl_type impl, Demuxer& demuxer, void* data,
|
||||
size_t max_length, Endpoint& endpoint, Handler handler)
|
||||
size_t max_length, socket_base::message_flags flags,
|
||||
Endpoint& endpoint, Handler handler)
|
||||
: impl_(impl),
|
||||
demuxer_(demuxer),
|
||||
data_(data),
|
||||
max_length_(max_length),
|
||||
flags_(flags),
|
||||
sender_endpoint_(endpoint),
|
||||
handler_(handler)
|
||||
{
|
||||
@ -431,7 +439,7 @@ public:
|
||||
void do_operation()
|
||||
{
|
||||
socket_addr_len_type addr_len = sender_endpoint_.native_size();
|
||||
int bytes = socket_ops::recvfrom(impl_, data_, max_length_, 0,
|
||||
int bytes = socket_ops::recvfrom(impl_, data_, max_length_, flags_,
|
||||
sender_endpoint_.native_data(), &addr_len);
|
||||
asio::error error(bytes < 0
|
||||
? socket_ops::get_error() : asio::error::success);
|
||||
@ -452,6 +460,7 @@ public:
|
||||
Demuxer& demuxer_;
|
||||
void* data_;
|
||||
size_t max_length_;
|
||||
socket_base::message_flags flags_;
|
||||
Endpoint& sender_endpoint_;
|
||||
Handler handler_;
|
||||
};
|
||||
@ -461,7 +470,8 @@ public:
|
||||
// asynchronous operation.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_receive_from(impl_type& impl, void* data, size_t max_length,
|
||||
Endpoint& sender_endpoint, Handler handler)
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
if (impl == null())
|
||||
{
|
||||
@ -472,7 +482,7 @@ public:
|
||||
{
|
||||
demuxer_.work_started();
|
||||
reactor_.start_read_op(impl, receive_from_handler<Endpoint, Handler>(
|
||||
impl, demuxer_, data, max_length, sender_endpoint, handler));
|
||||
impl, demuxer_, data, max_length, flags, sender_endpoint, handler));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,9 +245,10 @@ public:
|
||||
// sent.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t send_to(impl_type& impl, const void* data, size_t length,
|
||||
const Endpoint& destination, Error_Handler error_handler)
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
int bytes_sent = socket_ops::sendto(impl, data, length, 0,
|
||||
int bytes_sent = socket_ops::sendto(impl, data, length, flags,
|
||||
destination.native_data(), destination.native_size());
|
||||
if (bytes_sent < 0)
|
||||
{
|
||||
@ -295,7 +296,8 @@ public:
|
||||
// lifetime of the asynchronous operation.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_send_to(impl_type& impl, const void* data, size_t length,
|
||||
const Endpoint& destination, Handler handler)
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
Handler handler)
|
||||
{
|
||||
send_to_operation<Handler>* send_to_op =
|
||||
new send_to_operation<Handler>(handler);
|
||||
@ -307,7 +309,7 @@ public:
|
||||
buf.buf = static_cast<char*>(const_cast<void*>(data));
|
||||
DWORD bytes_transferred = 0;
|
||||
|
||||
int result = ::WSASendTo(impl, &buf, 1, &bytes_transferred, 0,
|
||||
int result = ::WSASendTo(impl, &buf, 1, &bytes_transferred, flags,
|
||||
destination.native_data(), destination.native_size(), send_to_op, 0);
|
||||
DWORD last_error = ::WSAGetLastError();
|
||||
|
||||
@ -402,10 +404,11 @@ public:
|
||||
// bytes received.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
size_t receive_from(impl_type& impl, void* data, size_t max_length,
|
||||
Endpoint& sender_endpoint, Error_Handler error_handler)
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
socket_addr_len_type addr_len = sender_endpoint.native_size();
|
||||
int bytes_recvd = socket_ops::recvfrom(impl, data, max_length, 0,
|
||||
int bytes_recvd = socket_ops::recvfrom(impl, data, max_length, flags,
|
||||
sender_endpoint.native_data(), &addr_len);
|
||||
if (bytes_recvd < 0)
|
||||
{
|
||||
@ -467,7 +470,8 @@ public:
|
||||
// asynchronous operation.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_receive_from(impl_type& impl, void* data, size_t max_length,
|
||||
Endpoint& sender_endpoint, Handler handler)
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
receive_from_operation<Endpoint, Handler>* receive_from_op =
|
||||
new receive_from_operation<Endpoint, Handler>(sender_endpoint, handler);
|
||||
@ -478,9 +482,9 @@ public:
|
||||
buf.len = static_cast<u_long>(max_length);
|
||||
buf.buf = static_cast<char*>(data);
|
||||
DWORD bytes_transferred = 0;
|
||||
DWORD flags = 0;
|
||||
DWORD recv_flags = flags;
|
||||
|
||||
int result = ::WSARecvFrom(impl, &buf, 1, &bytes_transferred, &flags,
|
||||
int result = ::WSARecvFrom(impl, &buf, 1, &bytes_transferred, &recv_flags,
|
||||
sender_endpoint.native_data(), &receive_from_op->endpoint_size(),
|
||||
receive_from_op, 0);
|
||||
DWORD last_error = ::WSAGetLastError();
|
||||
|
@ -48,24 +48,26 @@ public:
|
||||
#endif
|
||||
};
|
||||
|
||||
/// Flags that can be passed to send and receive operations.
|
||||
enum message_flags
|
||||
{
|
||||
/// Bitmask type for flags that can be passed to send and receive operations.
|
||||
typedef int message_flags;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Peek at incoming data without removing it from the input queue.
|
||||
message_peek = implementation_defined,
|
||||
/// Peek at incoming data without removing it from the input queue.
|
||||
static const int message_peek = implementation_defined,
|
||||
|
||||
/// Process out-of-band data.
|
||||
message_out_of_band = implementation_defined,
|
||||
/// Process out-of-band data.
|
||||
static const int message_out_of_band = implementation_defined,
|
||||
|
||||
/// Specify that the data should not be subject to routing.
|
||||
message_do_not_route = implementation_defined
|
||||
/// Specify that the data should not be subject to routing.
|
||||
static const int message_do_not_route = implementation_defined
|
||||
};
|
||||
#else
|
||||
enum {
|
||||
message_peek = asio::detail::message_peek,
|
||||
message_out_of_band = asio::detail::message_out_of_band,
|
||||
message_do_not_route = asio::detail::message_do_not_route
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Socket option to permit sending of broadcast messages.
|
||||
typedef asio::socket_option::boolean<
|
||||
|
@ -10,7 +10,7 @@ public:
|
||||
: demuxer_(d),
|
||||
socket_(d, asio::ipv4::udp::endpoint(port))
|
||||
{
|
||||
socket_.async_receive_from(data_, max_length, sender_endpoint_,
|
||||
socket_.async_receive_from(data_, max_length, 0, sender_endpoint_,
|
||||
boost::bind(&server::handle_receive_from, this,
|
||||
asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
}
|
||||
@ -19,13 +19,13 @@ public:
|
||||
{
|
||||
if (!error && bytes_recvd > 0)
|
||||
{
|
||||
socket_.async_send_to(data_, bytes_recvd, sender_endpoint_,
|
||||
socket_.async_send_to(data_, bytes_recvd, 0, sender_endpoint_,
|
||||
boost::bind(&server::handle_send_to, this,
|
||||
asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
}
|
||||
else
|
||||
{
|
||||
socket_.async_receive_from(data_, max_length, sender_endpoint_,
|
||||
socket_.async_receive_from(data_, max_length, 0, sender_endpoint_,
|
||||
boost::bind(&server::handle_receive_from, this,
|
||||
asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
}
|
||||
@ -33,7 +33,7 @@ public:
|
||||
|
||||
void handle_send_to(const asio::error& error, size_t bytes_sent)
|
||||
{
|
||||
socket_.async_receive_from(data_, max_length, sender_endpoint_,
|
||||
socket_.async_receive_from(data_, max_length, 0, sender_endpoint_,
|
||||
boost::bind(&server::handle_receive_from, this,
|
||||
asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
}
|
||||
|
@ -29,11 +29,11 @@ int main(int argc, char* argv[])
|
||||
char request[max_length];
|
||||
std::cin.getline(request, max_length);
|
||||
size_t request_length = strlen(request);
|
||||
s.send_to(request, request_length, receiver_endpoint);
|
||||
s.send_to(request, request_length, 0, receiver_endpoint);
|
||||
|
||||
char reply[max_length];
|
||||
asio::ipv4::udp::endpoint sender_endpoint;
|
||||
size_t reply_length = s.receive_from(reply, max_length, sender_endpoint);
|
||||
size_t reply_length = s.receive_from(reply, max_length, 0, sender_endpoint);
|
||||
std::cout << "Reply is: ";
|
||||
std::cout.write(reply, reply_length);
|
||||
std::cout << "\n";
|
||||
|
@ -11,8 +11,8 @@ void server(asio::demuxer& d, short port)
|
||||
{
|
||||
char data[max_length];
|
||||
asio::ipv4::udp::endpoint sender_endpoint;
|
||||
size_t length = sock.receive_from(data, max_length, sender_endpoint);
|
||||
sock.send_to(data, length, sender_endpoint);
|
||||
size_t length = sock.receive_from(data, max_length, 0, sender_endpoint);
|
||||
sock.send_to(data, length, 0, sender_endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
// Join the multicast group.
|
||||
socket_.set_option(asio::ipv4::multicast::add_membership(multicast_addr));
|
||||
|
||||
socket_.async_receive_from(data_, max_length, sender_endpoint_,
|
||||
socket_.async_receive_from(data_, max_length, 0, sender_endpoint_,
|
||||
boost::bind(&receiver::handle_receive_from, this,
|
||||
asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
}
|
||||
@ -32,7 +32,7 @@ public:
|
||||
std::cout.write(data_, bytes_recvd);
|
||||
std::cout << std::endl;
|
||||
|
||||
socket_.async_receive_from(data_, max_length, sender_endpoint_,
|
||||
socket_.async_receive_from(data_, max_length, 0, sender_endpoint_,
|
||||
boost::bind(&receiver::handle_receive_from, this,
|
||||
asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
message_ = os.str();
|
||||
|
||||
asio::ipv4::udp::endpoint target(multicast_port, multicast_addr);
|
||||
socket_.async_send_to(message_.data(), message_.length(), target,
|
||||
socket_.async_send_to(message_.data(), message_.length(), 0, target,
|
||||
boost::bind(&sender::handle_send_to, this, asio::placeholders::error));
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ public:
|
||||
message_ = os.str();
|
||||
|
||||
asio::ipv4::udp::endpoint target(multicast_port, multicast_addr);
|
||||
socket_.async_send_to(message_.data(), message_.length(), target,
|
||||
socket_.async_send_to(message_.data(), message_.length(), 0, target,
|
||||
boost::bind(&sender::handle_send_to, this,
|
||||
asio::placeholders::error));
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
timer_(d),
|
||||
socket_(d, ipv4::udp::endpoint(32124))
|
||||
{
|
||||
socket_.async_receive_from(data_, max_length, sender_endpoint_,
|
||||
socket_.async_receive_from(data_, max_length, 0, sender_endpoint_,
|
||||
boost::bind(&datagram_handler::handle_receive_from, this,
|
||||
asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
|
||||
|
@ -21,12 +21,12 @@ int main(int argc, char* argv[])
|
||||
asio::ipv4::udp::endpoint receiver_endpoint(13, host.addresses[0]);
|
||||
|
||||
char send_buf[1] = { 0 };
|
||||
socket.send_to(send_buf, sizeof(send_buf), receiver_endpoint);
|
||||
socket.send_to(send_buf, sizeof(send_buf), 0, receiver_endpoint);
|
||||
|
||||
char recv_buf[128];
|
||||
asio::ipv4::udp::endpoint sender_endpoint;
|
||||
size_t len = socket.receive_from(recv_buf,
|
||||
sizeof(recv_buf), sender_endpoint);
|
||||
sizeof(recv_buf), 0, sender_endpoint);
|
||||
std::cout.write(recv_buf, len);
|
||||
}
|
||||
catch (asio::error& e)
|
||||
|
@ -15,14 +15,14 @@ int main()
|
||||
{
|
||||
char recv_buf[1];
|
||||
asio::ipv4::udp::endpoint remote_endpoint;
|
||||
socket.receive_from(recv_buf, sizeof(recv_buf), remote_endpoint,
|
||||
socket.receive_from(recv_buf, sizeof(recv_buf), 0, remote_endpoint,
|
||||
asio::throw_error_if(asio::the_error != asio::error::message_size));
|
||||
|
||||
using namespace std; // For time_t, time and ctime.
|
||||
time_t now = time(0);
|
||||
std::string msg = ctime(&now);
|
||||
|
||||
socket.send_to(msg.c_str(), msg.length(), remote_endpoint,
|
||||
socket.send_to(msg.c_str(), msg.length(), 0, remote_endpoint,
|
||||
asio::ignore_error());
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ void handle_receive_from(asio::datagram_socket* socket, char* recv_buf,
|
||||
char* send_buf = strdup(ctime(&now));
|
||||
size_t send_length = strlen(send_buf);
|
||||
|
||||
socket->async_send_to(send_buf, send_length, *remote_endpoint,
|
||||
socket->async_send_to(send_buf, send_length, 0, *remote_endpoint,
|
||||
boost::bind(handle_send_to, send_buf, asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred));
|
||||
|
||||
socket->async_receive_from(recv_buf, recv_length, *remote_endpoint,
|
||||
socket->async_receive_from(recv_buf, recv_length, 0, *remote_endpoint,
|
||||
boost::bind(handle_receive_from, socket, recv_buf, recv_length,
|
||||
remote_endpoint, asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred));
|
||||
@ -44,7 +44,7 @@ int main()
|
||||
size_t recv_length = sizeof(recv_buf);
|
||||
asio::ipv4::udp::endpoint remote_endpoint;
|
||||
|
||||
socket.async_receive_from(recv_buf, recv_length, remote_endpoint,
|
||||
socket.async_receive_from(recv_buf, recv_length, 0, remote_endpoint,
|
||||
boost::bind(handle_receive_from, &socket, recv_buf, recv_length,
|
||||
&remote_endpoint, asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred));
|
||||
|
@ -52,10 +52,10 @@ void handle_udp_receive_from(asio::datagram_socket* socket, char* recv_buf,
|
||||
char* send_buf = strdup(ctime(&now));
|
||||
size_t send_length = strlen(send_buf);
|
||||
|
||||
socket->async_send_to(send_buf, send_length, *remote_endpoint,
|
||||
socket->async_send_to(send_buf, send_length, 0, *remote_endpoint,
|
||||
boost::bind(handle_udp_send_to, send_buf));
|
||||
|
||||
socket->async_receive_from(recv_buf, recv_length, *remote_endpoint,
|
||||
socket->async_receive_from(recv_buf, recv_length, 0, *remote_endpoint,
|
||||
boost::bind(handle_udp_receive_from, socket, recv_buf, recv_length,
|
||||
remote_endpoint, asio::placeholders::error));
|
||||
}
|
||||
@ -81,7 +81,7 @@ int main()
|
||||
size_t recv_length = sizeof(recv_buf);
|
||||
asio::ipv4::udp::endpoint remote_endpoint;
|
||||
|
||||
udp_socket.async_receive_from(recv_buf, recv_length, remote_endpoint,
|
||||
udp_socket.async_receive_from(recv_buf, recv_length, 0, remote_endpoint,
|
||||
boost::bind(handle_udp_receive_from, &udp_socket, recv_buf, recv_length,
|
||||
&remote_endpoint, asio::placeholders::error));
|
||||
|
||||
|
@ -44,11 +44,11 @@ void datagram_socket_test()
|
||||
s2.open(ipv4::udp());
|
||||
s2.bind(ipv4::udp::endpoint(0));
|
||||
char send_msg[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
s2.send_to(send_msg, sizeof(send_msg), target_endpoint);
|
||||
s2.send_to(send_msg, sizeof(send_msg), 0, target_endpoint);
|
||||
|
||||
char recv_msg[sizeof(send_msg)];
|
||||
ipv4::udp::endpoint sender_endpoint;
|
||||
size_t bytes_recvd = s1.receive_from(recv_msg, sizeof(recv_msg),
|
||||
size_t bytes_recvd = s1.receive_from(recv_msg, sizeof(recv_msg), 0,
|
||||
sender_endpoint);
|
||||
|
||||
UNIT_TEST_CHECK(bytes_recvd == sizeof(send_msg));
|
||||
@ -57,10 +57,10 @@ void datagram_socket_test()
|
||||
memset(recv_msg, 0, sizeof(recv_msg));
|
||||
|
||||
target_endpoint = sender_endpoint;
|
||||
s1.async_send_to(send_msg, sizeof(send_msg), target_endpoint,
|
||||
s1.async_send_to(send_msg, sizeof(send_msg), 0, target_endpoint,
|
||||
boost::bind(handle_send, sizeof(send_msg),
|
||||
placeholders::error, placeholders::bytes_transferred));
|
||||
s2.async_receive_from(recv_msg, sizeof(recv_msg), sender_endpoint,
|
||||
s2.async_receive_from(recv_msg, sizeof(recv_msg), 0, sender_endpoint,
|
||||
boost::bind(handle_recv, sizeof(recv_msg),
|
||||
placeholders::error, placeholders::bytes_transferred));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user