Merge pull request #523 from spongehah/c/hyper_related
[feat] llgo/c/hyper-related c lib
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -142,3 +150,18 @@ func SwapInt16(data uint16) uint16 {
|
||||
func Htons(x uint16) uint16 {
|
||||
return SwapInt16(x)
|
||||
}
|
||||
|
||||
//go:linkname InetAddr C.inet_addr
|
||||
func InetAddr(s *c.Char) c.Uint
|
||||
|
||||
//go:linkname Send C.send
|
||||
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
|
||||
@@ -58,6 +58,10 @@ const (
|
||||
O_TRUNC = 0x00000400
|
||||
)
|
||||
|
||||
const (
|
||||
EAGAIN = 35
|
||||
)
|
||||
|
||||
type (
|
||||
ModeT C.mode_t
|
||||
UidT C.uid_t
|
||||
|
||||
13
c/sys/_wrap/fddef.c
Normal file
13
c/sys/_wrap/fddef.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
int fd_isset(int n, fd_set *fd) {
|
||||
return FD_ISSET(n, fd);
|
||||
}
|
||||
|
||||
void fdSet(int n, fd_set *fd) {
|
||||
FD_SET(n, fd);
|
||||
}
|
||||
|
||||
void fd_zero(fd_set *fd) {
|
||||
FD_ZERO(fd);
|
||||
}
|
||||
31
c/sys/select.go
Normal file
31
c/sys/select.go
Normal 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
|
||||
Reference in New Issue
Block a user