diff --git a/c/libuv/fs.go b/c/libuv/fs.go index 9bb8f57f..35152ffd 100644 --- a/c/libuv/fs.go +++ b/c/libuv/fs.go @@ -1,5 +1,9 @@ package libuv +//#cgo pkg-config: libuv +//#include +import "C" + import ( _ "unsafe" @@ -68,9 +72,7 @@ type File c.Int /* Handle types. */ -type Fs struct { - Unused [440]byte -} +type Fs C.uv_fs_t type FsEvent struct { Unused [0]byte diff --git a/c/libuv/net.go b/c/libuv/net.go index c04e4705..3ceb10f2 100644 --- a/c/libuv/net.go +++ b/c/libuv/net.go @@ -71,17 +71,9 @@ type UdpFlags c.Int type Tcp C.uv_tcp_t -// TODO(spongehah): Handle -type Handle struct { - Data c.Pointer - Unused [88]byte - // TODO(spongehah): Stream -} +type Handle C.uv_handle_t -type Stream struct { - Data c.Pointer - Unused [256]byte -} +type Stream C.uv_stream_t type Shutdown struct { Unused [0]byte @@ -101,17 +93,9 @@ type UdpSend struct { Unused [0]byte } -// TODO(spongehah): Connect -type Connect struct { - Data c.Pointer - Unused [88]byte -} +type Connect C.uv_connect_t -// TODO(spongehah): Write -type Write struct { - Data c.Pointer - Unused [184]byte -} +type Write C.uv_write_t type GetAddrInfo struct { Unused [0]byte @@ -153,6 +137,12 @@ type ShutdownCb func(req *Shutdown, status c.Int) /* Handle related function and method */ +//go:linkname HandleSize C.uv_handle_size +func HandleSize(handleType HandleType) uintptr + +//go:linkname HandleTypeName C.uv_handle_type_name +func HandleTypeName(handleType HandleType) *c.Char + // llgo:link (*Handle).Ref C.uv_ref func (handle *Handle) Ref() {} @@ -164,17 +154,11 @@ func (handle *Handle) HasRef() c.Int { return 0 } -//go:linkname HandleSize C.uv_handle_size -func HandleSize(handleType HandleType) uintptr - // llgo:link (*Handle).GetType C.uv_handle_get_type func (handle *Handle) GetType() HandleType { return 0 } -//go:linkname HandleTypeName C.uv_handle_type_name -func HandleTypeName(handleType HandleType) *c.Char - // llgo:link (*Handle).GetData C.uv_handle_get_data func (handle *Handle) GetData() c.Pointer { return nil @@ -211,16 +195,6 @@ func (handle *Handle) Fileno(fd *OsFd) c.Int { return 0 } -//go:linkname Pipe C.uv_pipe -func Pipe(fds [2]File, readFlags c.Int, writeFlags c.Int) c.Int { - return 0 -} - -//go:linkname Socketpair C.uv_socketpair -func Socketpair(_type c.Int, protocol c.Int, socketVector [2]OsSock, flag0 c.Int, flag1 c.Int) c.Int { - return 0 -} - // llgo:link (*Handle).IsClosing C.uv_is_closing func (handle *Handle) IsClosing() c.Int { return 0 @@ -236,6 +210,16 @@ func (handle *Handle) IsWritable() c.Int { return 0 } +//go:linkname Pipe C.uv_pipe +func Pipe(fds [2]File, readFlags c.Int, writeFlags c.Int) c.Int { + return 0 +} + +//go:linkname Socketpair C.uv_socketpair +func Socketpair(_type c.Int, protocol c.Int, socketVector [2]OsSock, flag0 c.Int, flag1 c.Int) c.Int { + return 0 +} + // ---------------------------------------------- /* Req related function and method */ @@ -243,6 +227,9 @@ func (handle *Handle) IsWritable() c.Int { //go:linkname ReqSize C.uv_req_size func ReqSize(reqType ReqType) uintptr +//go:linkname TypeName C.uv_req_type_name +func TypeName(reqType ReqType) *c.Char + // llgo:link (*Req).GetData C.uv_req_get_data func (req *Req) GetData() c.Pointer { return nil @@ -256,9 +243,6 @@ func (req *Req) GetType() ReqType { return 0 } -//go:linkname TypeName C.uv_req_type_name -func TypeName(reqType ReqType) *c.Char - // ---------------------------------------------- /* Stream related function and method */ @@ -378,14 +362,14 @@ func (tcp *Tcp) CloseReset(closeCb CloseCb) c.Int { return 0 } -//go:linkname TcpConnect C.uv_tcp_connect -func TcpConnect(req *Connect, tcp *Tcp, addr *net.SockAddr, connectCb ConnectCb) c.Int - func (tcp *Tcp) GetIoWatcherFd() c.Int { tcp_s := (*C.uv_tcp_t)(c.Pointer(tcp)) return c.Int(tcp_s.io_watcher.fd) } +//go:linkname TcpConnect C.uv_tcp_connect +func TcpConnect(req *Connect, tcp *Tcp, addr *net.SockAddr, connectCb ConnectCb) c.Int + // ---------------------------------------------- /* Udp related function and method */ @@ -456,9 +440,6 @@ func (udp *Udp) SetTTL(ttl c.Int) c.Int { return 0 } -//go:linkname Send C.uv_udp_send -func Send(req *UdpSend, udp *Udp, bufs *Buf, nbufs c.Uint, addr *net.SockAddr, sendCb UdpSendCb) c.Int - // llgo:link (*Udp).TrySend C.uv_udp_try_send func (udp *Udp) TrySend(bufs *Buf, nbufs c.Uint, addr *net.SockAddr) c.Int { return 0 @@ -489,8 +470,13 @@ func (udp *Udp) GetSendQueueCount() uintptr { return 0 } +//go:linkname Send C.uv_udp_send +func Send(req *UdpSend, udp *Udp, bufs *Buf, nbufs c.Uint, addr *net.SockAddr, sendCb UdpSendCb) c.Int + // ---------------------------------------------- +/* DNS related function and method */ + //go:linkname Ip4Addr C.uv_ip4_addr func Ip4Addr(ip *c.Char, port c.Int, addr *net.SockaddrIn) c.Int