Esempio n. 1
0
// Read reads data the TLS connection into the given buffer.
func (t *TLS) Read(buf []byte) (int, error) {
	var inlen C.size_t
	if C.tls_read(t.ctx, unsafe.Pointer(&buf[0]), C.size_t(len(buf)), (*C.size_t)(unsafe.Pointer(&inlen))) != 0 {
		return -1, fmt.Errorf("read failed: %v", t.Error())
	}
	return int(inlen), nil
}
Esempio n. 2
0
// Read reads data the TLS connection into the given buffer.
func (t *TLS) Read(buf []byte) (int, error) {
	ret := C.tls_read(t.ctx, unsafe.Pointer(&buf[0]), C.size_t(len(buf)))
	switch {
	case ret == C.TLS_WANT_POLLIN:
		return -1, errWantPollIn
	case ret == C.TLS_WANT_POLLOUT:
		return -1, errWantPollOut
	case ret < 0:
		return -1, fmt.Errorf("read failed: %v", t.Error())
	}
	return int(ret), nil
}