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