llgo/c/hyper_related

This commit is contained in:
赵英杰
2024-07-18 10:28:14 +08:00
parent 519c850f17
commit 254acbbbe2
11 changed files with 105 additions and 138 deletions

View File

@@ -1,24 +0,0 @@
package fddef
import (
"github.com/goplus/llgo/c"
_ "unsafe"
)
const (
LLGoFiles = "_wrap/fddef.c"
LLGoPackage = "link: c"
)
type FdSet struct {
Unused [8]byte
}
//go:linkname FdZero C.fd_zero
func FdZero(fdSet *FdSet)
//go:linkname Fdset C.fdSet
func Fdset(fd c.Int, fdSet *FdSet)
//go:linkname FdIsset C.fd_isset
func FdIsset(fd c.Int, fdSet *FdSet) c.Int

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package socket
package net
import (
_ "unsafe"
@@ -101,7 +101,6 @@ type SockAddr struct {
Data [14]c.Char
}
// (TODO) merge to netdb
type Hostent struct {
Name *c.Char // official name of host
Aliases **c.Char // null-terminated array of alternate names for the host
@@ -110,6 +109,17 @@ type Hostent struct {
AddrList **c.Char // null-terminated array of addresses for the host
}
type AddrInfo struct {
AiFlags c.Int
AiFamily c.Int
AiSockType c.Int
AiProtocol c.Int
AiAddrLen c.Uint
AiCanOnName *c.Char
AiAddr *SockAddr
AiNext *AddrInfo
}
//go:linkname Socket C.socket
func Socket(domain c.Int, typ c.Int, protocol c.Int) c.Int
@@ -125,8 +135,6 @@ func Listen(sockfd c.Int, backlog c.Int) c.Int
//go:linkname Accept C.accept
func Accept(sockfd c.Int, addr *SockaddrIn, addrlen *c.Uint) c.Int
// (TODO) merge to netdb
//
//go:linkname GetHostByName C.gethostbyname
func GetHostByName(name *c.Char) *Hostent
@@ -143,8 +151,6 @@ func Htons(x uint16) uint16 {
return SwapInt16(x)
}
// (TODO) merge to netdb
//
//go:linkname InetAddr C.inet_addr
func InetAddr(s *c.Char) c.Uint
@@ -153,3 +159,9 @@ func Send(c.Int, c.Pointer, uintptr, c.Int) c.Long
//go:linkname Recv C.recv
func Recv(c.Int, c.Pointer, uintptr, c.Int) c.Long
//go:linkname Getaddrinfo C.getaddrinfo
func Getaddrinfo(host *c.Char, port *c.Char, addrInfo *AddrInfo, result **AddrInfo) c.Int
//go:linkname Freeaddrinfo C.freeaddrinfo
func Freeaddrinfo(addrInfo *AddrInfo) c.Int

View File

@@ -1,29 +0,0 @@
package netdb
import (
"github.com/goplus/llgo/c/socket"
_ "unsafe"
"github.com/goplus/llgo/c"
)
const (
LLGoPackage = "decl"
)
type AddrInfo struct {
AiFlags c.Int
AiFamily c.Int
AiSockType c.Int
AiProtocol c.Int
AiAddrLen c.Uint
AiCanOnName *c.Char
AiAddr *socket.SockAddr
AiNext *AddrInfo
}
//go:linkname Getaddrinfo C.getaddrinfo
func Getaddrinfo(host *c.Char, port *c.Char, addrInfo *AddrInfo, result **AddrInfo) c.Int
//go:linkname Freeaddrinfo C.freeaddrinfo
func Freeaddrinfo(addrInfo *AddrInfo) c.Int

View File

@@ -1,22 +0,0 @@
package _select
import (
"github.com/goplus/llgo/c/fddef"
_ "unsafe"
"github.com/goplus/llgo/c"
)
const (
LLGoPackage = "decl"
)
// (TODO) merge to timeval
//
type TimeVal struct {
TvSec c.Long
TvUSec c.Int
}
//go:linkname Select C.select
func Select(n c.Int, r *fddef.FdSet, w *fddef.FdSet, e *fddef.FdSet, timeout *TimeVal) c.Int

31
c/sys/select.go Normal file
View File

@@ -0,0 +1,31 @@
package sys
import (
"github.com/goplus/llgo/c/syscall"
_ "unsafe"
"github.com/goplus/llgo/c"
)
const (
LLGoFiles = "_wrap/fddef.c"
LLGoPackage = "link"
)
// (TODO) merge to timeval
type TimeVal struct {
TvSec c.Long
TvUSec c.Int
}
//go:linkname FD_ZERO C.fd_zero
func FD_ZERO(fdSet *syscall.FdSet)
//go:linkname FD_SET C.fdSet
func FD_SET(fd c.Int, fdSet *syscall.FdSet)
//go:linkname FD_ISSET C.fd_isset
func FD_ISSET(fd c.Int, fdSet *syscall.FdSet) c.Int
//go:linkname Select C.select
func Select(n c.Int, r *syscall.FdSet, w *syscall.FdSet, e *syscall.FdSet, timeout *TimeVal) c.Int