Esempio n. 1
0
func Send(socket *Socket, data *byte, length int) (retval int, err error) {

	retval = int(C.udt_send(socket.sock, (*C.char)(unsafe.Pointer(data)), C.int(length), C.int(0)))
	if retval < 0 {
		return retval, udtErrDesc("Unable to send data")
	}
	return
}
Esempio n. 2
0
func (fd *udtFD) Write(buf []byte) (writecnt int, err error) {
	if err = fd.writeLock(); err != nil {
		return 0, err
	}
	defer fd.writeUnlock()

	writecnt = 0
	for {
		n := int(C.udt_send(fd.sock, slice2cbuf(buf[writecnt:]), C.int(len(buf)-writecnt), 0))

		if C.int(n) == C.ERROR {
			// UDT Error?
			if err = fd.udtIOError(); err != nil {
				break
			}
			// everything's fine, proceed
		}

		// update our running count
		if n > 0 {
			writecnt += n
		}

		if writecnt == len(buf) { // done!
			break
		}
		if err != nil { // bad things happened
			break
		}
		if n == 0 { // early eof?
			err = io.ErrUnexpectedEOF
			break
		}
	}
	if err != nil {
		err = &net.OpError{"write", fd.net, fd.laddr, fd.raddr, err}
	}
	return writecnt, err
}