简体   繁体   English

如何使用libuv以通用方式(tcp / pipe)接受客户端?

[英]How to accept clients in a generic way (tcp / pipe ) with libuv?

I would like to have a generic on_connection callback that works with any type of server stream (pipe or tcp), but to accept the connection, you should provide an initialized client... 我想有一个通用的on_connection回调,它可以与任何类型的服务器流(管道或tcp)一起使用,但是要接受连接,您应该提供一个初始化的客户端...

However uv_stream_t is an abstract struct. 但是uv_stream_t是抽象结构。

Is there an official way to do that ? 有官方的方法吗? Else, can I do a switch relying on the private and undocumented uv_hundle_t.type member ? 另外,我可以依靠私有uv_hundle_t.type记录的uv_hundle_t.type成员进行切换吗?

Or should I use my own way of knowing the type using the .data pointer ? 还是我应该使用自己的方式通过.data指针知道类型?

You can use uv_handle_t.type, it's not "private". 您可以使用uv_handle_t.type,它不是“私有”的。 I just realized we haven't documented it, so I created an issue . 我只是意识到我们还没有记录在案,所以我创建了一个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM