Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't use boost::bind as completion token #5

Open
diggit opened this issue Jan 23, 2023 · 2 comments
Open

can't use boost::bind as completion token #5

diggit opened this issue Jan 23, 2023 · 2 comments

Comments

@diggit
Copy link
Contributor

diggit commented Jan 23, 2023

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
Copy link
Contributor Author

diggit commented Jan 27, 2023

removing forward from here

std::forward<CompletionToken>(token),

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

@MiSo1289
Copy link
Owner

MiSo1289 commented Jan 27, 2023

removing forward from here

std::forward<CompletionToken>(token),

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

You are correct, the forward should not be there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants