11 #ifndef SERVICES_STREAM_SOCKET_SERVICE_HPP 12 #define SERVICES_STREAM_SOCKET_SERVICE_HPP 15 #include <boost/noncopyable.hpp> 16 #include <boost/lexical_cast.hpp> 22 template <
typename Protocol>
50 logger_(io_service,
"stream_socket")
75 logger_.
log(
"Opening new socket");
76 return service_impl_.
open(impl, protocol, ec);
81 const protocol_type& protocol,
const native_handle_type& native_socket,
84 logger_.
log(
"Assigning from a native socket");
85 return service_impl_.
assign(impl, protocol, native_socket, ec);
89 bool is_open(
const implementation_type& impl)
const 91 logger_.
log(
"Checking if socket is open");
92 return service_impl_.
is_open(impl);
99 logger_.
log(
"Closing socket");
100 return service_impl_.
close(impl, ec);
107 logger_.
log(
"Checking if socket is at out-of-band data mark");
108 return service_impl_.
at_mark(impl, ec);
115 logger_.
log(
"Determining number of bytes available for reading");
116 return service_impl_.
available(impl, ec);
123 logger_.
log(
"Binding socket");
124 return service_impl_.
bind(impl, endpoint, ec);
131 logger_.
log(
"Connecting socket to " +
132 boost::lexical_cast<std::string>(peer_endpoint));
133 return service_impl_.
connect(impl, peer_endpoint, ec);
137 template <
typename Handler>
151 std::string msg =
"Asynchronous connect failed: ";
157 logger_.
log(
"Asynchronous connect succeeded");
169 template <
typename Handler>
171 const endpoint_type& peer_endpoint, Handler handler)
173 logger_.
log(
"Starting asynchronous connect to " +
174 boost::lexical_cast<std::string>(peer_endpoint));
175 service_impl_.async_connect(impl, peer_endpoint,
180 template <
typename Option>
184 logger_.
log(
"Setting socket option");
185 return service_impl_.set_option(impl, option, ec);
189 template <
typename Option>
193 logger_.
log(
"Getting socket option");
194 return service_impl_.get_option(impl, option, ec);
198 template <
typename IO_Control_Command>
202 logger_.
log(
"Performing IO control command on socket");
203 return service_impl_.io_control(impl, command, ec);
210 logger_.
log(
"Getting socket's local endpoint");
211 return service_impl_.local_endpoint(impl, ec);
218 logger_.
log(
"Getting socket's remote endpoint");
219 return service_impl_.remote_endpoint(impl, ec);
227 logger_.
log(
"Shutting down socket");
228 return service_impl_.shutdown(impl, what, ec);
232 template <
typename Const_Buffers>
233 std::size_t
send(implementation_type& impl,
const Const_Buffers&
buffers,
237 logger_.
log(
"Sending data on socket");
238 return service_impl_.send(impl, buffers, flags, ec);
242 template <
typename Handler>
253 std::size_t bytes_transferred)
257 std::string msg =
"Asynchronous send failed: ";
263 logger_.log(
"Asynchronous send succeeded");
266 handler_(e, bytes_transferred);
275 template <
typename Const_Buffers,
typename Handler>
279 logger_.log(
"Starting asynchronous send");
280 service_impl_.async_send(impl, buffers, flags,
285 template <
typename Mutable_Buffers>
286 std::size_t
receive(implementation_type& impl,
287 const Mutable_Buffers&
buffers,
291 logger_.log(
"Receiving data on socket");
292 return service_impl_.receive(impl, buffers, flags, ec);
296 template <
typename Handler>
307 std::size_t bytes_transferred)
311 std::string msg =
"Asynchronous receive failed: ";
317 logger_.log(
"Asynchronous receive succeeded");
320 handler_(e, bytes_transferred);
329 template <
typename Mutable_Buffers,
typename Handler>
333 logger_.log(
"Starting asynchronous receive");
334 service_impl_.async_receive(impl, buffers, flags,
340 service_impl_type& service_impl_;
346 template <
typename Protocol>
351 #endif // SERVICES_STREAM_SOCKET_SERVICE_HPP void operator()(const asio::error_code &e)
int message_flags
Bitmask type for flags that can be passed to send and receive operations.
void construct(implementation_type &impl)
Construct a new stream socket implementation.
void async_receive(implementation_type &impl, const Mutable_Buffers &buffers, asio::socket_base::message_flags flags, Handler handler)
Start an asynchronous receive.
asio::error_code open(implementation_type &impl, const protocol_type &protocol, asio::error_code &ec)
Open a new stream socket implementation.
bool at_mark(const implementation_type &impl, asio::error_code &ec) const
Determine whether the socket is at the out-of-band data mark.
endpoint_type local_endpoint(const implementation_type &impl, asio::error_code &ec) const
Get the local endpoint.
Class used to uniquely identify a service.
Provides core I/O functionality.
asio::error_code bind(implementation_type &impl, const endpoint_type &endpoint, asio::error_code &ec)
Bind the stream socket to the specified local endpoint.
std::size_t available(const implementation_type &impl, asio::error_code &ec) const
Determine the number of bytes available for reading.
stream_socket_service(asio::io_service &io_service)
Construct a new stream socket service for the specified io_service.
bool is_open(const implementation_type &impl) const
Determine whether the socket is open.
asio::error_code assign(implementation_type &impl, const protocol_type &protocol, const native_handle_type &native_socket, asio::error_code &ec)
Open a stream socket from an existing native socket.
Protocol::endpoint endpoint_type
The endpoint type.
pylon Camera Software Suite for Linux for Use with Basler Gigabit the pylon Viewer and the IP Configurator applications might not be available System I340 and I350 series Although the pylon software will work with any GigE network we would recommend to use one of these adapters USB For U3V devices a USB3 capable USB controller is necessary For best performance and stability we highly recommend a kernel the following settings should be i e
asio::error_code assign(implementation_type &impl, const protocol_type &protocol, const native_handle_type &native_socket, asio::error_code &ec)
Assign an existing native socket to a stream socket.
Default service implementation for a stream socket.
bool at_mark(const implementation_type &impl, asio::error_code &ec) const
Determine whether the socket is at the out-of-band data mark.
receive_handler(Handler h, logger &l)
void destroy(implementation_type &impl)
Destroy a stream socket implementation.
Service & use_service(io_service &ios)
ASIO_DECL service(asio::io_service &owner)
Constructor.
endpoint_type remote_endpoint(const implementation_type &impl, asio::error_code &ec) const
Get the remote endpoint.
std::size_t receive(implementation_type &impl, const Mutable_Buffers &buffers, asio::socket_base::message_flags flags, asio::error_code &ec)
Receive some data from the peer.
bool is_open(const implementation_type &impl) const
Determine whether the socket is open.
const MutableBufferSequence & buffers
std::size_t send(implementation_type &impl, const Const_Buffers &buffers, asio::socket_base::message_flags flags, asio::error_code &ec)
Send the given data to the peer.
asio::error_code close(implementation_type &impl, asio::error_code &ec)
Close a stream socket implementation.
void destroy(implementation_type &impl)
Destroy a stream socket implementation.
asio::error_code connect(implementation_type &impl, const endpoint_type &peer_endpoint, asio::error_code &ec)
Connect the stream socket to the specified endpoint.
service_impl_type::native_handle_type native_handle_type
The native type of a stream socket.
send_handler(Handler h, logger &l)
asio::error_code connect(implementation_type &impl, const endpoint_type &peer_endpoint, asio::error_code &ec)
Connect the stream socket to the specified endpoint.
static asio::io_service::id id
The unique service identifier.
asio::error_code shutdown(implementation_type &impl, asio::socket_base::shutdown_type what, asio::error_code &ec)
Disable sends or receives on the socket.
shutdown_type
Different ways a socket may be shutdown.
asio::error_code open(implementation_type &impl, const protocol_type &protocol, asio::error_code &ec)
Open a stream socket.
void log(const std::string &message)
Log a message.
asio::error_code close(implementation_type &impl, asio::error_code &ec)
Close a stream socket implementation.
Class to represent an error code value.
asio::error_code get_option(const implementation_type &impl, Option &option, asio::error_code &ec) const
Get a socket option.
asio::error_code set_option(implementation_type &impl, const Option &option, asio::error_code &ec)
Set a socket option.
service_impl_type::implementation_type implementation_type
The implementation type of a stream socket.
service_impl_type::native_handle_type native_handle_type
The native socket type.
void construct(implementation_type &impl)
Construct a new stream socket implementation.
Debugging stream socket service that wraps the normal stream socket service.
Handler to wrap asynchronous connect completion.
asio::error_code bind(implementation_type &impl, const endpoint_type &endpoint, asio::error_code &ec)
Bind the stream socket to the specified local endpoint.
connect_handler(Handler h, logger &l)
Handler to wrap asynchronous send completion.
std::string message() const
Get the message associated with the error.
void operator()(const asio::error_code &e, std::size_t bytes_transferred)
void async_send(implementation_type &impl, const Const_Buffers &buffers, asio::socket_base::message_flags flags, Handler handler)
Start an asynchronous send.
Handler to wrap asynchronous receive completion.
asio::error_code io_control(implementation_type &impl, IO_Control_Command &command, asio::error_code &ec)
Perform an IO control command on the socket.
std::size_t available(const implementation_type &impl, asio::error_code &ec) const
Determine the number of bytes available for reading.
Base class for all io_service services.
Protocol protocol_type
The protocol type.
void shutdown_service()
Destroy all user-defined handler objects owned by the service.
void async_connect(implementation_type &impl, const endpoint_type &peer_endpoint, Handler handler)
Start an asynchronous connect.
void operator()(const asio::error_code &e, std::size_t bytes_transferred)