简体   繁体   English

向异步传输添加方法

[英]Adding methods to an asyncio Transport

Is it possible to add new methods to a standard asyncio transport? 是否可以向标准异步传输中添加新方法?

eg: Adding a send method to the SSL transport that serializes a protocol buffer, constructs a frame and uses the transports own write method to do a buffered write to the underlying socket. 例如:在SSL传输中添加一个send方法,以对协议缓冲区进行序列化,构造帧并使用传输自身的write方法对基础套接字进行缓冲写入。

There are plenty of asyncio server/client examples out there, but I have not been able to find ones that implement their own transport or extends an already existing one. 那里有很多异步服务器/客户端示例,但是我找不到能够实现自己的传输或扩展现有传输的示例。

No. You cannot add a new method or inherit from existing asyncio transport. 不能。您不能添加新方法或从现有异步传输中继承。 Consider transports as final or sealed , like sockets. 将运输视为最终运输或密封运输,例如插座。

You should never want to inherit from socket but make your class that embeds the socket instance inside, right? 您永远不应该希望从套接字继承,而是让您的类将套接字实例嵌入其中,对吗?

The same for transport. 运输也一样。 See asyncio.streams as example of building new API layer on top of transport/protocol pair. 请参阅asyncio.streams作为在传输/协议对之上构建新API层的示例。

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

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