写点什么

长安链源码分析之网络模块 net-liquid(11)

作者:
  • 2022-10-20
    湖南
  • 本文字数:980 字

    阅读完需:约 1 分钟

本文已参与「开源摘星计划」,欢迎正在阅读的你加入。活动链接:https://github.com/weopenprojects/WeOpen-Star


//获取连接方向func (d Direction) String() string {	str := []string{"Unknown", "Inbound", "Outbound"}	if d < 0 || int(d) >= len(str) {		return "[unrecognized]"	}	return str[d]}
// Stat is an interface for storing metadata of a Conn or a Stream.//存储连接和流的元数据type Stat interface { //获取连接方向 Direction() Direction //建立连接的时间 EstablishedTime() time.Time //获取连接额外元数据 Extra() map[interface{}]interface{} //设置连接为关闭 SetClosed() //连接是否已经关闭 IsClosed() bool}
// BasicStat stores metadata of a Conn or a Stream.//Stat 的实现类type BasicStat struct { // direction specifies whether this is an inbound or an outbound connection. //连接方向是inbound/outboud direction Direction // establishedTime is the timestamp when this connection was established. //连接建立的时间 establishedTime time.Time // closed specifies whether this connection has been closed. 0 means open, 1 means closed //连接是否关闭 0是打开,1是关闭 closed int32 // extra stores other metadata of this connection. //存储连接的额外数据 extra map[interface{}]interface{}}
// NewStat create a new BasicStat instance.//用于创建一个BasicStatfunc NewStat(direction Direction, establishedTime time.Time, extra map[interface{}]interface{}) *BasicStat { return &BasicStat{direction: direction, establishedTime: establishedTime, closed: 0, extra: extra}}
复制代码


//定义一个流接口type stream interface {	io.Closer	Stat
Conn() Conn}
// SendStream is an interface defined a way to send data.//定义发送数据type SendStream interface { stream io.Writer}
// ReceiveStream is an interface defined a way to receive data.//定义接收数据type ReceiveStream interface { stream io.Reader}
// Stream is an interface defined both ways to send and receive data.//定义发送和接收数据type Stream interface { SendStream ReceiveStream}
复制代码


用户头像

关注

还未添加个人签名 2018-05-04 加入

还未添加个人简介

评论

发布
暂无评论
长安链源码分析之网络模块 net-liquid(11)_李_InfoQ写作社区