usb-asio icon indicating copy to clipboard operation
usb-asio copied to clipboard

can't use `boost::bind` as completion token

Open diggit opened this issue 2 years ago • 2 comments

Hi, I am trying to pass std::bind as completion token to async bulk read. My inspiration is this boost example. As I am total asio noob, I am quite lost. Do you know what could be the issue?


class Pump : public boost::enable_shared_from_this<Pump> {
public:
	std::array<std::byte, 512> buffer {};

	void start() {
		boost::asio::async_read(
			source,
			boost::asio::buffer(buffer),
			boost::bind(
				&Pump::handle_read, shared_from_this(),
				boost::asio::placeholders::error,
				boost::asio::placeholders::bytes_transferred
			)
		);
	}

  private:
	Pump(std::deque<std::byte> &sink, usb_asio::usb_in_bulk_transfer &source, const unsigned int id) :
		sink(sink),
		source(source),
		id(id)
		{}

	void handle_read(boost::system::error_code error_code, std::size_t bytes_read) {
		assert(error_code);
		if (bytes_read) {
			sink.insert(sink.end(), buffer.begin(), buffer.begin()+bytes_read);
		}
		start();
	}

	std::deque<std::byte> &sink;
	usb_asio::usb_in_bulk_transfer &source;
	unsigned int id {};
};
[error.txt](https://github.com/MiSo1289/usb-asio/files/10483346/error.txt)

diggit avatar Jan 23 '23 20:01 diggit

removing forward from here https://github.com/MiSo1289/usb-asio/blob/eb10616677d9f9037bb6d7f683bfd94f8fb8a506/include/usb_asio/usb_transfer.hpp#L580 solves the issue. Though, I am not sure it that's the right way.

diggit avatar Jan 27 '23 10:01 diggit

removing forward from here

https://github.com/MiSo1289/usb-asio/blob/eb10616677d9f9037bb6d7f683bfd94f8fb8a506/include/usb_asio/usb_transfer.hpp#L580

solves the issue. Though, I am not sure it that's the right way.

You are correct, the forward should not be there

MiSo1289 avatar Jan 27 '23 14:01 MiSo1289