zoukankan      html  css  js  c++  java
  • conn.go 源码阅读

    import (
        "net"
    )

    // 封装连接
    type Connect struct {
        // 标准包conn接口实例,继承该接口所有方法
        net.Conn
        // 标记连接是否有效
        Usable bool
        // 是否为短链接模式
        Short bool
        // 专用写入数据缓存通道
        WriteChan chan *NetData
        // 从连接循环接收数据
        Buffer []byte
        // 临时缓冲区,用来存储被截断的数据
        TmpBuffer []byte
    }

    // 创建Connect实例,默认为长连接(Short=false)
    func NewConnect(conn net.Conn, bufferLen int, wChanCap int) (k string, v *Connect) {
        k = conn.RemoteAddr().String()

        v = &Connect{
            WriteChan: make(chan *NetData, wChanCap),
            Buffer:    make([]byte, bufferLen),
            TmpBuffer: make([]byte, 0),
            Conn:      conn,
        }
        return k, v
    }

    // 返回远程节点地址
    func (self *Connect) Addr() string {
        return self.Conn.RemoteAddr().String()
    }

  • 相关阅读:
    xshell安装错解决方案
    (转)进程process和线程thread的关系
    selenium Gird
    python发布文件(windows)
    (转)ci
    selenium通过python字典获取配置
    selenium断言的分类
    C#从Image上读取文本
    C#屏幕截图
    WPF实现TextBox水印效果
  • 原文地址:https://www.cnblogs.com/zhangboyu/p/7462047.html
Copyright © 2011-2022 走看看