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

checker: define missing C fn args & check C & JS args (#8770)

This commit is contained in:
joe-conigliaro
2021-03-06 01:41:11 +11:00
committed by GitHub
parent ead2ba6004
commit 2d73411396
34 changed files with 358 additions and 284 deletions

View File

@@ -11,10 +11,14 @@ enum Select {
pub enum SocketType {
udp = C.SOCK_DGRAM
tcp = C.SOCK_STREAM
dgram = C.SOCK_DGRAM
stream = C.SOCK_STREAM
seqpacket = C.SOCK_SEQPACKET
}
// SocketFamily are the available address families
pub enum SocketFamily {
unix = C.AF_UNIX
inet = C.AF_INET
}
@@ -55,59 +59,71 @@ mut:
struct C.sockaddr_storage {
}
fn C.socket() int
fn C.socket(domain SocketFamily, typ SocketType, protocol int) int
fn C.setsockopt() int
// 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
fn C.htonl() int
fn C.htonl(hostlong u32) int
fn C.htons() int
fn C.htons(netshort u16) int
fn C.bind() int
// 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
fn C.listen() int
fn C.listen(sockfd int, backlog int) int
fn C.accept() int
// fn C.accept(sockfd int, addr &C.sockaddr, addrlen &C.socklen_t) int
fn C.accept(sockfd int, addr &C.sockaddr, addrlen &u32) int
fn C.getaddrinfo() int
fn C.getaddrinfo(node charptr, service charptr, hints &C.addrinfo, res &&C.addrinfo) int
fn C.connect() int
// fn C.connect(sockfd int, addr &C.sockaddr, addrlen C.socklen_t) int
fn C.connect(sockfd int, addr &C.sockaddr, addrlen u32) int
fn C.send() int
// 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() 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
fn C.recv() int
// 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() 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
fn C.shutdown() int
fn C.shutdown(socket int, how int) int
fn C.ntohs() int
fn C.ntohs(netshort u16) int
fn C.getpeername() int
// 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 int, src voidptr, dst charptr, dst_size int) charptr
fn C.inet_ntop(af SocketFamily, src voidptr, dst charptr, dst_size int) charptr
fn C.WSAAddressToStringA() int
fn C.WSAAddressToStringA(lpsaAddress &C.sockaddr, dwAddressLength u32, lpProtocolInfo voidptr, lpszAddressString charptr, lpdwAddressStringLength &u32) int
fn C.getsockname() 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
// defined in builtin
// fn C.read() int
// fn C.close() int
fn C.ioctlsocket() int
fn C.ioctlsocket(s int, cmd int, argp &u32) int
fn C.fcntl() int
fn C.fcntl(fd int, cmd int, arg ...voidptr) int
fn C.@select() int
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()
fn C.FD_ZERO(fdset &C.fd_set)
fn C.FD_SET()
fn C.FD_SET(fd int, fdset &C.fd_set)
fn C.FD_ISSET() bool
fn C.FD_ISSET(fd int, fdset &C.fd_set) bool
[typedef]
pub struct C.fd_set {}

View File

@@ -34,49 +34,52 @@ pub struct SSL {
pub struct SSL_METHOD {
}
fn C.BIO_new_ssl_connect() voidptr
fn C.BIO_new_ssl_connect(ctx &C.SSL_CTX) &C.BIO
fn C.BIO_set_conn_hostname() int
fn C.BIO_set_conn_hostname(b &C.BIO, name charptr) int
fn C.BIO_get_ssl()
// there are actually 2 macros for BIO_get_ssl
// fn C.BIO_get_ssl(bp &C.BIO, ssl charptr, c int)
// fn C.BIO_get_ssl(bp &C.BIO, sslp charptr)
fn C.BIO_get_ssl(bp &C.BIO, vargs ...voidptr)
fn C.BIO_do_connect() int
fn C.BIO_do_connect(b &C.BIO) int
fn C.BIO_do_handshake() int
fn C.BIO_do_handshake(b &C.BIO) int
fn C.BIO_puts()
fn C.BIO_puts(b &C.BIO, buf charptr)
fn C.BIO_read() int
fn C.BIO_read(b &C.BIO, buf voidptr, len int) int
fn C.BIO_free_all()
fn C.BIO_free_all(a &C.BIO)
fn C.SSL_CTX_new() &C.SSL_CTX
fn C.SSL_CTX_new(method &C.SSL_METHOD) &C.SSL_CTX
fn C.SSL_CTX_set_options()
fn C.SSL_CTX_set_options(ctx &C.SSL_CTX, options int)
fn C.SSL_CTX_set_verify_depth()
fn C.SSL_CTX_set_verify_depth(s &C.SSL_CTX, depth int)
fn C.SSL_CTX_load_verify_locations() int
fn C.SSL_CTX_load_verify_locations(ctx &C.SSL_CTX, ca_file charptr, ca_path charptr) int
fn C.SSL_CTX_free()
fn C.SSL_CTX_free(ctx &C.SSL_CTX)
fn C.SSL_new(&C.SSL_CTX) &C.SSL
fn C.SSL_set_fd(&C.SSL) int
fn C.SSL_set_fd(ssl &C.SSL, fd int) int
fn C.SSL_connect(&C.SSL) int
fn C.SSL_set_cipher_list() int
fn C.SSL_set_cipher_list(ctx &SSL, str charptr) int
fn C.SSL_get_peer_certificate() int
fn C.SSL_get_peer_certificate(ssl &SSL) &C.X509
fn C.ERR_clear_error()
fn C.SSL_get_error() int
fn C.SSL_get_error(ssl &C.SSL, ret int) int
fn C.SSL_get_verify_result() int
fn C.SSL_get_verify_result(ssl &SSL) int
fn C.SSL_set_tlsext_host_name() int
fn C.SSL_set_tlsext_host_name(s &SSL, name charptr) int
fn C.SSL_shutdown(&C.SSL) int

View File

@@ -157,7 +157,7 @@ pub fn (c &TcpConn) peer_ip() ?string {
peeraddr := C.sockaddr_in{}
speeraddr := sizeof(peeraddr)
socket_error(C.getpeername(c.sock.handle, unsafe { &C.sockaddr(&peeraddr) }, &speeraddr)) ?
cstr := charptr(C.inet_ntop(C.AF_INET, &peeraddr.sin_addr, buf, sizeof(buf)))
cstr := charptr(C.inet_ntop(SocketFamily.inet, &peeraddr.sin_addr, buf, sizeof(buf)))
if cstr == 0 {
return error('net.peer_ip: inet_ntop failed')
}
@@ -264,7 +264,7 @@ fn new_tcp_socket() ?TcpSocket {
// s.set_option_bool(.reuse_addr, true)?
s.set_option_int(.reuse_addr, 1) ?
$if windows {
t := true
t := u32(1) // true
socket_error(C.ioctlsocket(sockfd, fionbio, &t)) ?
} $else {
socket_error(C.fcntl(sockfd, C.F_SETFL, C.fcntl(sockfd, C.F_GETFL) | C.O_NONBLOCK)) ?
@@ -279,7 +279,7 @@ fn tcp_socket_from_handle(sockfd int) ?TcpSocket {
// s.set_option_bool(.reuse_addr, true)?
s.set_option_int(.reuse_addr, 1) ?
$if windows {
t := true
t := u32(1) // true
socket_error(C.ioctlsocket(sockfd, fionbio, &t)) ?
} $else {
socket_error(C.fcntl(sockfd, C.F_SETFL, C.fcntl(sockfd, C.F_GETFL) | C.O_NONBLOCK)) ?

View File

@@ -181,7 +181,7 @@ fn new_udp_socket(local_port int) ?&UdpSocket {
}
s.set_option_bool(.reuse_addr, true) ?
$if windows {
t := true
t := u32(1) // true
socket_error(C.ioctlsocket(sockfd, fionbio, &t)) ?
} $else {
socket_error(C.fcntl(sockfd, C.F_SETFD, C.O_NONBLOCK)) ?

View File

@@ -8,11 +8,11 @@ enum Select {
}
// SocketType are the available sockets
enum SocketType {
dgram = C.SOCK_DGRAM
stream = C.SOCK_STREAM
seqpacket = C.SOCK_SEQPACKET
}
// enum SocketType {
// dgram = C.SOCK_DGRAM
// stream = C.SOCK_STREAM
// seqpacket = C.SOCK_SEQPACKET
// }
struct C.sockaddr {
sa_family u16
@@ -44,43 +44,43 @@ mut:
struct C.sockaddr_storage {
}
fn C.socket() int
// fn C.socket() int
fn C.setsockopt() int
// fn C.setsockopt() int
fn C.htonl() int
// fn C.htonl() int
fn C.htons() int
// fn C.htons() int
fn C.bind() int
// fn C.bind() int
fn C.listen() int
// fn C.listen() int
fn C.accept() int
// fn C.accept() int
fn C.getaddrinfo() int
// fn C.getaddrinfo() int
fn C.connect() int
// fn C.connect() int
fn C.send() int
// fn C.send() int
fn C.sendto() int
// fn C.sendto() int
fn C.recv() int
// fn C.recv() int
fn C.recvfrom() int
// fn C.recvfrom() int
fn C.shutdown() int
// fn C.shutdown() int
fn C.ntohs() int
// fn C.ntohs() int
fn C.getpeername() int
// fn C.getpeername() int
fn C.inet_ntop(af int, src voidptr, dst charptr, dst_size int) charptr
// fn C.inet_ntop(af int, src voidptr, dst charptr, dst_size int) charptr
fn C.WSAAddressToStringA() int
fn C.getsockname() int
// fn C.getsockname() int
// defined in builtin
// fn C.read() int
@@ -88,15 +88,15 @@ fn C.getsockname() int
fn C.ioctlsocket() int
fn C.fcntl() int
// fn C.fcntl() int
fn C.@select() int
// fn C.@select() int
fn C.FD_ZERO()
// fn C.FD_ZERO()
fn C.FD_SET()
// fn C.FD_SET()
fn C.FD_ISSET() bool
// fn C.FD_ISSET() bool
[typedef]
struct C.fd_set {}

View File

@@ -7,7 +7,7 @@ const (
error_ewouldblock = C.EWOULDBLOCK
)
fn C.SUN_LEN(C.sockaddr_un) int
fn C.SUN_LEN(ptr &C.sockaddr_un) int
fn C.strncpy(charptr, charptr, int)

View File

@@ -41,7 +41,7 @@ fn error_code() int {
}
fn new_stream_socket() ?StreamSocket {
sockfd := net.socket_error(C.socket(C.AF_UNIX, SocketType.stream, 0)) ?
sockfd := net.socket_error(C.socket(net.SocketFamily.unix, net.SocketType.stream, 0)) ?
mut s := StreamSocket{
handle: sockfd
}