func (pipe *Pipe) Write(b []byte, cb func(*Request, int)) (err error) { cbi := (*callback_info)(pipe.p.data) cbi.write_cb = cb buf := C.uv_buf_init((*C.char)(unsafe.Pointer(&b[0])), C.uint(len(b))) r := uv_write((*C.uv_stream_t)(unsafe.Pointer(pipe.p)), &buf, 1) if r != 0 { return pipe.GetLoop().LastError().Error() } return nil }
func (udp *Udp) Send(b []byte, sa SockaddrIn, cb func(*Request, int)) (err error) { cbi := (*callback_info)(udp.u.data) cbi.udp_send_cb = cb buf := C.uv_buf_init((*C.char)(unsafe.Pointer(&b[0])), C.size_t(len(b))) var r int sa4, is_v4 := sa.(*SockaddrIn4) if is_v4 { r = uv_udp_send(udp.u, &buf, 1, sa4.sa) } else { sa6, is_v6 := sa.(*SockaddrIn6) if is_v6 { r = uv_udp_send6(udp.u, &buf, 1, sa6.sa) } } if r != 0 { return udp.GetLoop().LastError().Error() } return nil }
func uv_buf_init(b []byte) C.uv_buf_t { return C.uv_buf_init((*C.char)(unsafe.Pointer(&b[0])), C.uint(len(b))) }