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 tcp::socket and ssl::stream<tcp::socket> use the same set of interfaces? #1548

Open
kahotv opened this issue Oct 25, 2024 · 0 comments
Open

Comments

@kahotv
Copy link

kahotv commented Oct 25, 2024

In C#, there is a method like this (pseudo code):

class NetworkStream : Stream { ... }
class SslStream : AuthenticatedStream { ... }
class AuthenticatedStream : Stream { ... }

void Read(Stream local)
{
	byte[] buf = new byte[1024];
	while(true)
	{
		int n = await from.ReadAsync(buf, 0, buf.Length);
		...
	}
	
}
//Http:
var stream = new NetworkStream(socket);
//Https:
var stream = new SslStream(new NetworkStream(socket));
//Use:
Trans(stream);

In Asio, I tried this approach, but it requires writing code in the header file. Is there a better way?

template<typename StreamType>
auto Trans(StreamType& local) -> awaitable<void>
{
	char buf[1024];
	while(true)
	{
		size_t n = co_await local.async_read_some(buffer(buf), use_awaitable);
		...
	}
	
}

(I'm writing an HTTP and HTTPS proxy program, and I need to use this method.)

Thanks!

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

1 participant