1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/net/aasocket.c.v

130 lines
3.5 KiB
V
Raw Normal View History

2020-08-21 00:01:37 +03:00
module net
// Select represents a select operation
enum Select {
read
write
except
2020-08-21 00:01:37 +03:00
}
// SocketType are the available sockets
pub enum SocketType {
udp = C.SOCK_DGRAM
tcp = C.SOCK_STREAM
dgram = C.SOCK_DGRAM
stream = C.SOCK_STREAM
seqpacket = C.SOCK_SEQPACKET
2020-08-21 00:01:37 +03:00
}
// SocketFamily are the available address families
pub enum SocketFamily {
unix = C.AF_UNIX
inet = C.AF_INET
2020-08-21 00:01:37 +03:00
}
struct C.in_addr {
mut:
s_addr int
}
struct C.sockaddr {
sa_family u16
2020-08-21 00:01:37 +03:00
}
struct C.sockaddr_in {
mut:
sin_family int
sin_port int
sin_addr C.in_addr
}
struct C.sockaddr_un {
mut:
sun_family int
sun_path charptr
}
2020-08-21 00:01:37 +03:00
struct C.addrinfo {
mut:
ai_family int
ai_socktype int
ai_flags int
ai_protocol int
ai_addrlen int
ai_addr voidptr
ai_canonname voidptr
ai_next voidptr
}
struct C.sockaddr_storage {
}
fn C.socket(domain SocketFamily, typ SocketType, protocol int) int
2020-08-21 00:01:37 +03:00
// fn C.setsockopt(sockfd int, level int, optname int, optval voidptr, optlen C.socklen_t) int
fn C.setsockopt(sockfd int, level int, optname int, optval voidptr, optlen u32) int
2020-08-21 00:01:37 +03:00
fn C.htonl(hostlong u32) int
2020-08-21 00:01:37 +03:00
fn C.htons(netshort u16) int
2020-08-21 00:01:37 +03:00
// fn C.bind(sockfd int, addr &C.sockaddr, addrlen C.socklen_t) int
// use voidptr for arg 2 becasue sockaddr is a generic descriptor for any kind of socket operation,
// it can also take sockaddr_in depending on the type of socket used in arg 1
fn C.bind(sockfd int, addr voidptr, addrlen u32) int
2020-08-21 00:01:37 +03:00
fn C.listen(sockfd int, backlog int) int
2020-08-21 00:01:37 +03:00
// fn C.accept(sockfd int, addr &C.sockaddr, addrlen &C.socklen_t) int
fn C.accept(sockfd int, addr &C.sockaddr, addrlen &u32) int
2020-08-21 00:01:37 +03:00
fn C.getaddrinfo(node charptr, service charptr, hints &C.addrinfo, res &&C.addrinfo) int
2020-08-21 00:01:37 +03:00
// fn C.connect(sockfd int, addr &C.sockaddr, addrlen C.socklen_t) int
fn C.connect(sockfd int, addr &C.sockaddr, addrlen u32) int
2020-08-21 00:01:37 +03:00
// fn C.send(sockfd int, buf voidptr, len size_t, flags int) size_t
fn C.send(sockfd int, buf voidptr, len size_t, flags int) int
// fn C.sendto(sockfd int, buf voidptr, len size_t, flags int, dest_add &C.sockaddr, addrlen C.socklen_t) size_t
fn C.sendto(sockfd int, buf voidptr, len size_t, flags int, dest_add &C.sockaddr, addrlen u32) int
2020-08-21 00:01:37 +03:00
// fn C.recv(sockfd int, buf voidptr, len size_t, flags int) size_t
fn C.recv(sockfd int, buf voidptr, len size_t, flags int) int
// fn C.recvfrom(sockfd int, buf voidptr, len size_t, flags int, src_addr &C.sockaddr, addrlen &C.socklen_t) size_t
fn C.recvfrom(sockfd int, buf voidptr, len size_t, flags int, src_addr &C.sockaddr, addrlen &u32) int
2020-08-21 00:01:37 +03:00
fn C.shutdown(socket int, how int) int
2020-08-21 00:01:37 +03:00
fn C.ntohs(netshort u16) int
2020-08-21 00:01:37 +03:00
// fn C.getpeername(sockfd int, addr &C.sockaddr, addlen &C.socklen_t) int
fn C.getpeername(sockfd int, addr &C.sockaddr, addlen &u32) int
fn C.inet_ntop(af SocketFamily, src voidptr, dst charptr, dst_size int) charptr
2020-08-21 00:01:37 +03:00
fn C.WSAAddressToStringA(lpsaAddress &C.sockaddr, dwAddressLength u32, lpProtocolInfo voidptr, lpszAddressString charptr, lpdwAddressStringLength &u32) int
// fn C.getsockname(sockfd int, addr &C.sockaddr, addrlen &C.socklen_t) int
fn C.getsockname(sockfd int, addr &C.sockaddr, addrlen &u32) int
2020-08-21 00:01:37 +03:00
// defined in builtin
// fn C.read() int
// fn C.close() int
fn C.ioctlsocket(s int, cmd int, argp &u32) int
fn C.fcntl(fd int, cmd int, arg ...voidptr) int
2020-08-21 00:01:37 +03:00
fn C.@select(ndfs int, readfds &C.fd_set, writefds &C.fd_set, exceptfds &C.fd_set, timeout &C.timeval) int
fn C.FD_ZERO(fdset &C.fd_set)
fn C.FD_SET(fd int, fdset &C.fd_set)
fn C.FD_ISSET(fd int, fdset &C.fd_set) bool
2020-08-21 00:01:37 +03:00
[typedef]
pub struct C.fd_set {}