socket: no need to initialize WinSock on each request
parent
febd532c4a
commit
0796e1dd69
|
@ -10,7 +10,6 @@ INT port_number = 443;
|
|||
BOOL use_proxy = FALSE;
|
||||
DWORD protocol = 0;
|
||||
ALG_ID aid_key_exch = 0;
|
||||
WSADATA wsa_data;
|
||||
|
||||
// TODO: joe-c
|
||||
// socket / tls ctx
|
||||
|
@ -70,7 +69,6 @@ void vschannel_cleanup(TlsContext *tls_ctx) {
|
|||
}
|
||||
|
||||
void vschannel_init(TlsContext *tls_ctx) {
|
||||
WSAStartup(0x202, &wsa_data);
|
||||
tls_ctx->sspi = InitSecurityInterface();
|
||||
|
||||
if(tls_ctx->sspi == NULL) {
|
||||
|
|
|
@ -4,3 +4,5 @@ module net
|
|||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
fn init() int { return 1 }
|
|
@ -0,0 +1,31 @@
|
|||
module net
|
||||
|
||||
#flag -lws2_32
|
||||
#include <winsock2.h>
|
||||
#include <Ws2tcpip.h>
|
||||
|
||||
struct C.WSAData {
|
||||
mut:
|
||||
wVersion u16
|
||||
wHighVersion u16
|
||||
szDescription [257]byte
|
||||
szSystemStatus [129]byte
|
||||
iMaxSockets u16
|
||||
iMaxUdpDg u16
|
||||
lpVendorInfo byteptr
|
||||
}
|
||||
|
||||
|
||||
const (
|
||||
WSA_V22 = 0x202 // C.MAKEWORD(2, 2)
|
||||
)
|
||||
|
||||
fn init() int {
|
||||
mut wsadata := C.WSAData{}
|
||||
res := C.WSAStartup(WSA_V22, &wsadata)
|
||||
if res != 0 {
|
||||
panic('socket: WSAStartup failed')
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
module net
|
||||
|
||||
const (
|
||||
_ = net.init()
|
||||
)
|
||||
|
||||
// hostname returns the host name reported by the kernel.
|
||||
pub fn hostname() ?string {
|
||||
mut name := [256]byte
|
||||
|
@ -11,3 +15,4 @@ pub fn hostname() ?string {
|
|||
}
|
||||
return tos_clone(name)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,24 +8,6 @@ pub:
|
|||
proto int
|
||||
}
|
||||
|
||||
struct C.WSAData {
|
||||
mut:
|
||||
wVersion u16
|
||||
wHighVersion u16
|
||||
szDescription [257]byte
|
||||
szSystemStatus [129]byte
|
||||
iMaxSockets u16
|
||||
iMaxUdpDg u16
|
||||
lpVendorInfo byteptr
|
||||
}
|
||||
|
||||
const (
|
||||
WSA_V1 = 0x100 // C.MAKEWORD(1, 0)
|
||||
WSA_V11 = 0x101 // C.MAKEWORD(1, 1)
|
||||
WSA_V2 = 0x200 // C.MAKEWORD(2, 0)
|
||||
WSA_V21 = 0x201 // C.MAKEWORD(2, 1)
|
||||
WSA_V22 = 0x202 // C.MAKEWORD(2, 2)
|
||||
)
|
||||
|
||||
struct C.in_addr {
|
||||
mut:
|
||||
|
@ -55,13 +37,6 @@ struct C.sockaddr_storage {}
|
|||
|
||||
// create socket
|
||||
pub fn socket(family int, _type int, proto int) ?Socket {
|
||||
$if windows {
|
||||
mut wsadata := C.WSAData{}
|
||||
res := C.WSAStartup(WSA_V22, &wsadata)
|
||||
if res != 0 {
|
||||
return error('socket: WSAStartup failed')
|
||||
}
|
||||
}
|
||||
|
||||
sockfd := C.socket(family, _type, proto)
|
||||
one:=1
|
||||
|
@ -316,5 +291,3 @@ pub fn (s Socket) get_port() int {
|
|||
sockname_res := C.getsockname(s.sockfd, &addr, &size)
|
||||
return int(C.ntohs(addr.sin_port))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
module net
|
||||
|
||||
#flag -lws2_32
|
||||
#include <winsock2.h>
|
||||
#include <Ws2tcpip.h>
|
Loading…
Reference in New Issue