mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: C++ compiler support
This commit is contained in:
@ -18,8 +18,8 @@ import strings
|
||||
#flag darwin -I/usr/local/opt/openssl/include
|
||||
#flag darwin -L/usr/local/opt/openssl/lib
|
||||
#include <openssl/ssl.h>
|
||||
struct C.SSL {
|
||||
}
|
||||
|
||||
struct C.ssl_st
|
||||
|
||||
fn C.SSL_library_init()
|
||||
|
||||
@ -108,7 +108,7 @@ fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response {
|
||||
res = C.BIO_set_conn_hostname(web, addr.str)
|
||||
if res != 1 {
|
||||
}
|
||||
ssl := &C.SSL(0)
|
||||
ssl := &C.ssl_st(0)
|
||||
C.BIO_get_ssl(web, &ssl)
|
||||
if isnil(ssl) {
|
||||
}
|
||||
|
@ -6,10 +6,11 @@ pub fn hostname() ?string {
|
||||
mut name := [256]byte
|
||||
// https://www.ietf.org/rfc/rfc1035.txt
|
||||
// The host name is returned as a null-terminated string.
|
||||
res := C.gethostname(&name, 256)
|
||||
namebp := byteptr(name)
|
||||
res := C.gethostname(namebp, 256)
|
||||
if res != 0 {
|
||||
return error('net.hostname: failed with $res')
|
||||
}
|
||||
return tos_clone(name)
|
||||
return tos_clone(namebp)
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,9 @@ mut:
|
||||
s_addr int
|
||||
}
|
||||
|
||||
struct C.sockaddr {
|
||||
}
|
||||
|
||||
struct C.sockaddr_in {
|
||||
mut:
|
||||
sin_family int
|
||||
@ -108,7 +111,9 @@ pub fn (s Socket) bind(port int) ?int {
|
||||
addr.sin_port = C.htons(port)
|
||||
addr.sin_addr.s_addr = C.htonl(C.INADDR_ANY)
|
||||
size := 16 // sizeof(C.sockaddr_in)
|
||||
res := C.bind(s.sockfd, &addr, size)
|
||||
tmp := voidptr(&addr)
|
||||
skaddr := &C.sockaddr(tmp)
|
||||
res := C.bind(s.sockfd, skaddr, size)
|
||||
if res < 0 {
|
||||
return error('net.bind: failed with $res')
|
||||
}
|
||||
@ -165,7 +170,9 @@ pub fn (s Socket) accept() ?Socket {
|
||||
}
|
||||
addr := C.sockaddr_storage{}
|
||||
size := 128 // sizeof(sockaddr_storage)
|
||||
sockfd := C.accept(s.sockfd, &addr, &size)
|
||||
tmp := voidptr(&addr)
|
||||
skaddr := &C.sockaddr(tmp)
|
||||
sockfd := C.accept(s.sockfd, skaddr, &size)
|
||||
if sockfd < 0 {
|
||||
return error('net.accept: failed with $sockfd')
|
||||
}
|
||||
@ -255,8 +262,8 @@ pub fn (s Socket) cread(buffer byteptr, buffersize int) int {
|
||||
|
||||
// Receive a message from the socket, and place it in a preallocated buffer buf,
|
||||
// with maximum message size bufsize. Returns the length of the received message.
|
||||
pub fn (s Socket) crecv(buffer byteptr, buffersize int) int {
|
||||
return C.recv(s.sockfd, buffer, buffersize, 0)
|
||||
pub fn (s Socket) crecv(buffer voidptr, buffersize int) int {
|
||||
return C.recv(s.sockfd, byteptr(buffer), buffersize, 0)
|
||||
}
|
||||
|
||||
// shutdown and close socket
|
||||
@ -325,7 +332,8 @@ pub fn (s Socket) read_line() string {
|
||||
break
|
||||
}
|
||||
}
|
||||
line = tos_clone(buf)
|
||||
bufbp := byteptr(buf)
|
||||
line = tos_clone(bufbp)
|
||||
if eol_idx > 0 {
|
||||
// At this point, we are sure that recv returned valid data,
|
||||
// that contains *at least* one line.
|
||||
@ -357,7 +365,8 @@ pub fn (s Socket) read_all() string {
|
||||
if n == 0 {
|
||||
return res
|
||||
}
|
||||
res += tos_clone(buf)
|
||||
bufbp := byteptr(buf)
|
||||
res += tos_clone(bufbp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@ -365,6 +374,8 @@ pub fn (s Socket) read_all() string {
|
||||
pub fn (s Socket) get_port() int {
|
||||
mut addr := C.sockaddr_in{}
|
||||
size := 16 // sizeof(sockaddr_in)
|
||||
C.getsockname(s.sockfd, &addr, &size)
|
||||
tmp := voidptr(&addr)
|
||||
skaddr := &C.sockaddr(tmp)
|
||||
C.getsockname(s.sockfd, skaddr, &size)
|
||||
return C.ntohs(addr.sin_port)
|
||||
}
|
||||
|
Reference in New Issue
Block a user