Ejemplo n.º 1
0
func (fd *udtFD) Read(buf []byte) (readcnt int, err error) {
	if err = fd.readLock(); err != nil {
		return 0, err
	}
	defer fd.readUnlock()

	readcnt = 0
	for {
		n := int(C.udt_recv(fd.sock, slice2cbuf(buf[readcnt:]), C.int(len(buf)-readcnt), 0))
		if C.int(n) == C.ERROR {
			// got problems?
			if err = fd.udtIOError(); err != nil {
				break
			}
			// nope, everything's fine. read again.
			continue
		}

		if n > 0 {
			readcnt += n
		}
		if err != nil { // bad things happened
			break
		}
		if n == 0 {
			err = io.EOF
		}
		break // return the data we have.
	}
	if err != nil && err != io.EOF {
		err = &net.OpError{"read", fd.net, fd.laddr, fd.raddr, err}
	}
	return readcnt, err
}
Ejemplo n.º 2
0
func Recv(socket *Socket, data *byte, length int) (retval int, err error) {

	retval = int(C.udt_recv(socket.sock, (*C.char)(unsafe.Pointer(data)), C.int(length), C.int(0)))
	if retval < 0 {
		return retval, udtErrDesc("Unable to recive data")
	}
	return
}