本文整理汇总了Golang中bufio.ReadWriter类的典型用法代码### 示例。如果您正苦于以下问题:Golang ReadWriter类的具体用法?Golang ReadWriter怎么用?Golang ReadWriter使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。

在下文中一共展示了ReadWriter类的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: socksAuthRFC1929

// socksAuthRFC1929 authenticates the client via RFC 1929 username/password
// auth.  As a design decision any valid username/password is accepted as this
// field is primarily used as an out-of-band argument passing mechanism for
// pluggable transports.
func socksAuthRFC1929(rw *bufio.ReadWriter, req *SocksRequest) (err error) {
    sendErrResp := func() {
        // Swallow the write/flush error here, we are going to close the
        // connection and the original failure is more useful.
        resp := []byte{socksAuthRFC1929Ver, socksAuthRFC1929Fail}
        rw.Write(resp[:])
        socksFlushBuffers(rw)
    }

    // Validate the fixed parts of the command message.
    if err = socksReadByteVerify(rw, "auth version", socksAuthRFC1929Ver); err != nil {
        sendErrResp()
        return
    }

    // Read the username.
    var ulen byte
    if ulen, err = socksReadByte(rw); err != nil {
        return
    }
    if ulen < 1 {
        sendErrResp()
        err = fmt.Errorf("RFC1929 username with 0 length")
        return
    }
    var uname []byte
    if uname, err = socksReadBytes(rw, int(ulen)); err != nil {
        return
    }
    req.Username = string(uname)

    // Read the password.
    var plen byte
    if plen, err = socksReadByte(rw); err != nil {
        return
    }
    if plen < 1 {
        sendErrResp()
        err = fmt.Errorf("RFC1929 password with 0 length")
        return
    }
    var passwd []byte
    if passwd, err = socksReadBytes(rw, int(plen)); err != nil {
        return
    }
    if !(plen == 1 && passwd[0] == 0x00) {
        // tor will set the password to 'NUL' if there are no arguments.
        req.Password = string(passwd)
    }

    // Mash the username/password together and parse it as a pluggable
    // transport argument string.
    if req.Args, err = parseClientParameters(req.Username + req.Password); err != nil {
        sendErrResp()
    } else {
        resp := []byte{socksAuthRFC1929Ver, socksAuthRFC1929Success}
        _, err = rw.Write(resp[:])
    }
    return
}

开发者ID:thomasf,项目名称:alkasir,代码行数:64,代码来源:socks.go

示例2: recvMsg

func recvMsg(rwr *bufio.ReadWriter, userId int64) {
    var (
        ok       bool
        conn     net.Conn
        closeErr error
    )

    //close old connection and channel
    if _, ok = us.chs[userId]; ok {
        conn = us.conns[userId]
        if closeErr = conn.Close(); closeErr != nil {
            println("close old connection error:", userId)
        }
    }

    //是为了其他的服务器可以读取redis的值来判断是否在线
    set(userId)

    res, _ := get(userId)
    log.Debug("%v", res)
    pushKafka(userId)

    var ta = make(chan Talk, 1)
    var ch Channel
    ch.ch = ta
    us.chs[userId] = ch
    for {
        talk := <-us.chs[userId].ch
        log.Debug("recv:%v", talk)
        str := fmt.Sprintf("<script>alert(\"%d:%s\")</script>", talk.userId, talk.msg)
        rwr.WriteString(str)
        rwr.Flush()
    }
}

开发者ID:qinlodestar,项目名称:simplecomet,代码行数:34,代码来源:server.go

示例3: getLocal

func getLocal(rw *bufio.ReadWriter) (data []byte, flags uint32, err error) {
    if err := rw.Flush(); err != nil {
        return nil, 0, err
    }

    resHeader, err := binprot.ReadResponseHeader(rw)
    if err != nil {
        return nil, 0, err
    }

    err = binprot.DecodeError(resHeader)
    if err != nil {
        if _, ioerr := rw.Discard(int(resHeader.TotalBodyLength)); ioerr != nil {
            return nil, 0, ioerr
        }
        return nil, 0, err
    }

    var serverFlags uint32
    binary.Read(rw, binary.BigEndian, &serverFlags)

    // total body - key - extra
    dataLen := resHeader.TotalBodyLength - uint32(resHeader.KeyLength) - uint32(resHeader.ExtraLength)
    buf := make([]byte, dataLen)

    // Read in value
    if _, err := io.ReadFull(rw, buf); err != nil {
        return nil, 0, err
    }

    return buf, serverFlags, nil
}

开发者ID:hardiku,项目名称:rend,代码行数:32,代码来源:localComm.go

示例4: hijacked500

func hijacked500(brw *bufio.ReadWriter, protoMinor int, statuses *statusStats) {
    statuses.status5xx.Add(1)
    // Assumes HTTP/1.x
    s := fmt.Sprintf(resp500Format, protoMinor, time.Now().Format(http.TimeFormat))
    brw.WriteString(s)
    brw.Flush()
}

开发者ID:jwise,项目名称:howsmyssl,代码行数:7,代码来源:howsmyssl.go

示例5: callRPC

func (w *rpcWorker) callRPC(conn *bufio.ReadWriter, req *pdpb.Request) (resp *pdpb.Response, err error) {
    // Record some metrics.
    start := time.Now()
    label := metrics.GetCmdLabel(req)
    defer func() {
        if err == nil {
            cmdCounter.WithLabelValues(label).Inc()
            cmdDuration.WithLabelValues(label).Observe(time.Since(start).Seconds())
        } else {
            cmdFailedCounter.WithLabelValues(label).Inc()
            cmdFailedDuration.WithLabelValues(label).Observe(time.Since(start).Seconds())
        }
    }()

    msg := &msgpb.Message{
        MsgType: msgpb.MessageType_PdReq,
        PdReq:   req,
    }
    if err = util.WriteMessage(conn, newMsgID(), msg); err != nil {
        return nil, errors.Errorf("[pd] rpc failed: %v", err)
    }
    conn.Flush()
    if _, err = util.ReadMessage(conn, msg); err != nil {
        return nil, errors.Errorf("[pd] rpc failed: %v", err)
    }
    if msg.GetMsgType() != msgpb.MessageType_PdResp {
        return nil, errors.Trace(errInvalidResponse)
    }
    resp = msg.GetPdResp()
    if err = w.checkResponse(resp); err != nil {
        return nil, errors.Trace(err)
    }

    return resp, nil
}

开发者ID:jmptrader,项目名称:tidb,代码行数:35,代码来源:rpc_worker.go

示例6: getMetadataCommon

func getMetadataCommon(rw *bufio.ReadWriter) (metadata, error) {
    if err := rw.Flush(); err != nil {
        return metadata{}, err
    }

    resHeader, err := binprot.ReadResponseHeader(rw)
    if err != nil {
        return metadata{}, err
    }

    err = binprot.DecodeError(resHeader)
    if err != nil {
        // read in the message "Not found" after a miss
        if _, ioerr := rw.Discard(int(resHeader.TotalBodyLength)); ioerr != nil {
            return metadata{}, ioerr
        }
        return metadata{}, err
    }

    serverFlags := make([]byte, 4)
    binary.Read(rw, binary.BigEndian, &serverFlags)

    var metaData metadata
    binary.Read(rw, binary.BigEndian, &metaData)

    return metaData, nil
}

开发者ID:hardiku,项目名称:rend,代码行数:27,代码来源:localComm.go

示例7: complex_handshake

func complex_handshake(rw *bufio.ReadWriter, input []byte) bool {
    result, scheme, challenge, digest := validateClient(input)
    if !result {
        return result
    }
    log.Debugf("Validate Client %v scheme %v challenge %0X digest %0X", result, scheme, challenge, digest)
    s1 := create_s1()
    log.Debug("s1 length", len(s1))
    off := getDigestOffset(s1, scheme)
    log.Debug("s1 digest offset", off)
    buf := new(bytes.Buffer)
    buf.Write(s1[:off])
    buf.Write(s1[off+32:])
    tempHash, _ := HMACsha256(buf.Bytes(), GENUINE_FMS_KEY[:36])
    copy(s1[off:], tempHash)
    log.Debug("s1 length", len(s1))
    //compute the challenge digest
    tempHash, _ = HMACsha256(digest, GENUINE_FMS_KEY[:68])
    log.Debug("s2 length tempHash", len(tempHash))
    randBytes := create_s2()
    log.Debug("s2 length", len(randBytes))
    lastHash, _ := HMACsha256(randBytes, tempHash)
    log.Debug("s2 length lastHash", len(lastHash))
    log.Debug("s2 length", len(randBytes))
    buf = new(bytes.Buffer)
    buf.WriteByte(0x03)
    buf.Write(s1)
    buf.Write(randBytes)
    buf.Write(lastHash)
    log.Debug("send s0s1s2", buf.Len())
    rw.Write(buf.Bytes())
    rw.Flush()
    ReadBuf(rw, HANDSHAKE_SIZE)
    return true
}

开发者ID:sichuanyl,项目名称:babylon,代码行数:35,代码来源:rtmp_handshake.go

示例8: readCmd

/*
 * Read command/input from connection.
 * @param b *bufioReadWriter - reader
 * @return cmd string - read input
 * @return err error - error state
 */
func readCmd(b *bufio.ReadWriter) (cmd string, err error) {
    line, err := b.ReadBytes('\n')
    if err != nil {
        return "", err
    }
    // get rid of enclosing white spaces
    return strings.Trim(string(line), " \t\n\v\r"), nil
}

开发者ID:bfix,项目名称:sid,代码行数:14,代码来源:control.go

示例9: writeLine

func (ms MemcachedProtocolServer) writeLine(buf *bufio.ReadWriter, s string) error {
    _, err := buf.WriteString(fmt.Sprintf("%s\r\n", s))
    if err != nil {
        return err
    }
    err = buf.Flush()
    return err
}

开发者ID:shitfSign,项目名称:beano,代码行数:8,代码来源:memcached.go

示例10: writeResponse

func writeResponse(bw *bufio.ReadWriter, body ...string) error {
    for _, chunk := range body {
        if _, err := bw.WriteString(chunk); err != nil {
            return err
        }
    }

    return bw.Flush()
}

开发者ID:htee,项目名称:htee,代码行数:9,代码来源:server.go

示例11: writeMessage

func writeMessage(w *bufio.ReadWriter, m Message) {
    raw := ""
    for k, v := range m {
        raw += k + ":" + v + "\r\n"
    }
    raw += "\r\n"
    w.WriteString(raw)
    w.Flush()
}

开发者ID:vyachin,项目名称:gami,代码行数:9,代码来源:gami_test.go

示例12: Prepend

func (t TextProt) Prepend(rw *bufio.ReadWriter, key []byte, value []byte) error {
    if _, err := fmt.Fprintf(rw, "prepend %s 0 0 %v\r\n%s\r\n", string(key), len(value), string(value)); err != nil {
        return err
    }

    rw.Flush()

    _, err := rw.ReadString('\n')
    return err
}

开发者ID:Netflix,项目名称:rend,代码行数:10,代码来源:prot.go

示例13: writeReadLine

func writeReadLine(rw *bufio.ReadWriter, format string, args ...interface{}) ([]byte, error) {
    _, err := fmt.Fprintf(rw, format, args...)
    if err != nil {
        return nil, err
    }
    if err := rw.Flush(); err != nil {
        return nil, err
    }
    line, err := rw.ReadSlice('\n')
    return line, err
}

开发者ID:qmdx,项目名称:gomemcache,代码行数:11,代码来源:memcache.go

示例14: pushResponse

func pushResponse(bufrw *bufio.ReadWriter, authCode string) bool {
    _, err := bufrw.Write([]byte(authCode))
    if err == nil {
        err = bufrw.Flush()
    }
    if err != nil {
        go_lib.LogErrorf("PushAuthCodeError: %s\n", err)
        return false
    }
    return true
}

开发者ID:hyl87,项目名称:hypermind,代码行数:11,代码来源:common.go

示例15: GetWithOpaque

func (b BinProt) GetWithOpaque(rw *bufio.ReadWriter, key []byte, opaque int) ([]byte, error) {
    // Header
    writeReq(rw, Get, len(key), 0, len(key), opaque)
    // Body
    rw.Write(key)

    rw.Flush()

    // consume all of the response and return
    return consumeResponseCheckOpaque(rw.Reader, opaque)
}

开发者ID:RSellathurai,项目名称:rend,代码行数:11,代码来源:prot.go

示例16: GetE

func (b BinProt) GetE(rw *bufio.ReadWriter, key []byte) ([]byte, uint32, uint32, error) {
    // Header
    writeReq(rw, GetE, len(key), 0, len(key), 0)
    // Body
    rw.Write(key)

    rw.Flush()

    // consume all of the response and return
    return consumeResponseE(rw.Reader)
}

开发者ID:RSellathurai,项目名称:rend,代码行数:11,代码来源:prot.go

示例17: Get

func (b BinProt) Get(rw *bufio.ReadWriter, key []byte) error {
    // Header
    writeReq(rw, Get, len(key), 0, len(key))
    // Body
    rw.Write(key)

    rw.Flush()

    // consume all of the response and discard
    return consumeResponse(rw.Reader)
}

开发者ID:mbrukman,项目名称:rend,代码行数:11,代码来源:prot.go

示例18: Part

func Part(rw *bufio.ReadWriter, channel string) error {
    var (
        str string = fmt.Sprintf("PART %s\r\n", channel)
        err error
    )
    _, err = rw.Write([]byte(str))
    if err != nil {
        return err
    }
    rw.Flush()
    return nil
}

开发者ID:napsy,项目名称:gorobot,代码行数:12,代码来源:irc.go

示例19: Quit

func Quit(rw *bufio.ReadWriter, reason string) error {
    var (
        str string = fmt.Sprintf("QUIT %s\r\n", reason)
        err error
    )
    _, err = rw.Write([]byte(str))
    if err != nil {
        return err
    }
    rw.Flush()
    return nil
}

开发者ID:napsy,项目名称:gorobot,代码行数:12,代码来源:irc.go

示例20: Register

func Register(rw *bufio.ReadWriter, user, real string) error {
    var (
        str string = fmt.Sprintf("USER %s 0 * :%s\r\n", user, real)
        err error
    )
    _, err = rw.Write([]byte(str))
    if err != nil {
        return err
    }
    rw.Flush()
    return nil
}

开发者ID:napsy,项目名称:gorobot,代码行数:12,代码来源:irc.go

最后编辑: goerone  文档更新时间: 2021-08-23 19:14   作者:goerone