zoukankan      html  css  js  c++  java
  • tcp.go

    package nsqd

    import (
        "io"
        "net"

        "github.com/nsqio/nsq/internal/protocol"
    )

    type tcpServer struct {
        ctx *context
    }

    func (p *tcpServer) Handle(clientConn net.Conn) {
        p.ctx.nsqd.logf("TCP: new client(%s)", clientConn.RemoteAddr())

        // The client should initialize itself by sending a 4 byte sequence indicating
        // the version of the protocol that it intends to communicate, this will allow us
        // to gracefully upgrade the protocol away from text/line oriented to whatever...
        buf := make([]byte, 4)
        _, err := io.ReadFull(clientConn, buf)
        if err != nil {
            p.ctx.nsqd.logf("ERROR: failed to read protocol version - %s", err)
            return
        }
        protocolMagic := string(buf)

        p.ctx.nsqd.logf("CLIENT(%s): desired protocol magic '%s'",
            clientConn.RemoteAddr(), protocolMagic)

        var prot protocol.Protocol
        switch protocolMagic {
        case "  V2":
            prot = &protocolV2{ctx: p.ctx}
        default:
            protocol.SendFramedResponse(clientConn, frameTypeError, []byte("E_BAD_PROTOCOL"))
            clientConn.Close()
            p.ctx.nsqd.logf("ERROR: client(%s) bad protocol magic '%s'",
                clientConn.RemoteAddr(), protocolMagic)
            return
        }

        err = prot.IOLoop(clientConn)
        if err != nil {
            p.ctx.nsqd.logf("ERROR: client(%s) - %s", clientConn.RemoteAddr(), err)
            return
        }
    }

  • 相关阅读:
    kafka 配置权限
    转战 rocketmq
    从 spring-cloud-alibaba-nacos-config 进入 nacos-client
    sc 使用了配置中心后,如何设置远程和本地配置的优先级
    nacos 使用 servlet 异步处理客户端配置长轮询
    NacosValue 注解
    curl 使用 post 请求,传递 json 参数,下载文件
    nginx 代理 https 后,应用变成 http
    数据集市
    支付宝数据建模介绍
  • 原文地址:https://www.cnblogs.com/zhangboyu/p/7457384.html
Copyright © 2011-2022 走看看