spacemonkeygo / openssl

OpenSSL bindings for Go
http://godoc.org/github.com/spacemonkeygo/openssl
Apache License 2.0
473 stars 236 forks source link

mutil-goroutine confused me #162

Open 578141611 opened 1 year ago

578141611 commented 1 year ago
// Handshake performs an SSL handshake. If a handshake is not manually
// triggered, it will run before the first I/O on the encrypted stream.
func (c *Conn) Handshake() error {
    err := tryAgain
    for err == tryAgain {
        err = c.handleError(c.handshake())
    }
    go c.flushOutputBuffer()
    return err
}

can not understand why need "go c.flushOutputBuffer()"

// Handshake performs an SSL handshake. If a handshake is not manually
// triggered, it will run before the first I/O on the encrypted stream.
func (c *Conn) Handshake() error {
    err := tryAgain
    for err == tryAgain {
        err = c.handleError(c.handshake())
    }
    c.flushOutputBuffer()
    return err
}

will better?

// Read reads up to len(b) bytes into b. It returns the number of bytes read
// and an error if applicable. io.EOF is returned when the caller can expect
// to see no more data.
func (c *Conn) Read(b []byte) (n int, err error) {
    if len(b) == 0 {
        return 0, nil
    }
    err = tryAgain
    for err == tryAgain {
        n, errcb := c.read(b)
        err = c.handleError(errcb)
        if err == nil {
            go c.flushOutputBuffer()
            return n, nil
        }
        if err == io.ErrUnexpectedEOF {
            err = io.EOF
        }
    }
    return 0, err
}