StereoMatching
StereoMatching

Reputation: 5019

Anything similar to QSocketNotifier in boost::asio?

SOCKET sock = generate_socket("fileWizard");
notifier = new QSocketNotifier(sock, QSocketNotifier::Read, this);

connect(notifier, SIGNAL(activate(int)), this, some_slot(int));

The SOCKET is a win32 SOCKET, the function of "generate_socket" is creating a socket connect to a local exe which called "fileWizard"(don't know the implementation details of the function generate_socket). With Qt, we always generate the socket and connect the signal and slot, but can't find a similar example in asio.

Do not familiar to socket and asio yet, please tell me what information you need. Thanks

Edit :

The purposes of the codes are monitoring the SOCKET, if there are any change of it, it will call the call back.

Similar to the example of asio(Daytime.3 - An asynchronous TCP daytime server) The part which make me confuse is

1 : How could I transform the SOCKET to one of the boost::asio socket?

2 : How could I monitor the "change"(anything can read) of the socket(our seniors called it file descriptor)?By read_async?

Upvotes: 0

Views: 478

Answers (1)

Tanner Sansbury
Tanner Sansbury

Reputation: 51911

  1. Boost.Asio sockets support being created on top of an existing native socket through an overloaded constructor. For example, this constructor could be used to build a basic_stream_socket on top of an existing native socket, such as a Windows SOCKET.
  2. While Boost.Asio does not provide the direct equivalent of Qt's QSocketNotifier class, Boost.Asio does supports reactor-style operations by using null_buffers(). Both approaches allow the application to be notified when an event occurs, such as when data is ready to be read from a file descriptor. This event notification capability allows for each event loop to integrate with other event loops or third-party libraries. For a complete example that uses null_buffers(), see the official Boost.Asio non-blocking example.

Upvotes: 1

Related Questions