2019-10-09 21:01:31 +03:00
|
|
|
module net
|
|
|
|
|
|
|
|
#flag -lws2_32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <Ws2tcpip.h>
|
|
|
|
|
|
|
|
struct C.WSAData {
|
|
|
|
mut:
|
|
|
|
wVersion u16
|
2020-05-16 17:12:23 +03:00
|
|
|
wHighVersion u16
|
2019-10-09 21:01:31 +03:00
|
|
|
szDescription [257]byte
|
|
|
|
szSystemStatus [129]byte
|
|
|
|
iMaxSockets u16
|
|
|
|
iMaxUdpDg u16
|
|
|
|
lpVendorInfo byteptr
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
WSA_V22 = 0x202 // C.MAKEWORD(2, 2)
|
|
|
|
)
|
|
|
|
|
2019-10-12 13:54:58 +03:00
|
|
|
fn init() {
|
2019-10-09 21:01:31 +03:00
|
|
|
mut wsadata := C.WSAData{}
|
|
|
|
res := C.WSAStartup(WSA_V22, &wsadata)
|
|
|
|
if res != 0 {
|
|
|
|
panic('socket: WSAStartup failed')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 20:24:36 +03:00
|
|
|
fn error_code() int {
|
|
|
|
return C.WSAGetLastError()
|
|
|
|
}
|
|
|
|
|
2019-11-19 00:13:14 +03:00
|
|
|
pub const (
|
|
|
|
MSG_NOSIGNAL = 0
|
|
|
|
)
|