check empty buffer on read/write

master
fangdingjun 6 years ago
parent 402a2c41f0
commit 00f5076672

@ -201,6 +201,10 @@ func (c *Conn) Read(buf []byte) (n int, err error) {
return return
} }
if len(buf) == 0 {
return 0, nil
}
bufLen := len(buf) bufLen := len(buf)
cbuf := C.malloc(C.size_t(bufLen)) cbuf := C.malloc(C.size_t(bufLen))
defer C.free(cbuf) defer C.free(cbuf)
@ -227,6 +231,12 @@ func (c *Conn) Write(buf []byte) (n int, err error) {
if err != nil { if err != nil {
return return
} }
// user may call Write(nil) to do handshake
if len(buf) == 0 {
return 0, nil
}
cbuf := C.CBytes(buf) cbuf := C.CBytes(buf)
defer C.free(cbuf) defer C.free(cbuf)

Loading…
Cancel
Save