* The new @if directive.
This commit is contained in:
Christoffer Lerno
2023-06-10 23:16:28 +02:00
committed by GitHub
parent 82c3facb65
commit 4c1edfb941
102 changed files with 1272 additions and 1720 deletions

View File

@@ -1,21 +1,32 @@
module std::net::os;
$if $defined(PLATFORM_AF_INET):
struct AddrInfo
{
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
usz ai_addrlen;
void* ai_addr;
char* ai_canonname;
AddrInfo* ai_next;
}
$if !$defined(PLATFORM_O_NONBLOCK):
const PLATFORM_O_NONBLOCK = 0;
$endif
const bool SUPPORTS_INET = env::WIN32 || env::DARWIN || env::LINUX;
const PLATFORM_O_NONBLOCK @if(!$defined(PLATFORM_O_NONBLOCK)) = 0;
const AI_PASSIVE = 0x1;
const AI_CANONNAME = 0x2;
const AI_NUMERICHOST = 0x4;
const int AF_UNSPEC = 0;
const int AF_INET = PLATFORM_AF_INET;
const int AF_APPLETALK = PLATFORM_AF_APPLETALK;
const int AF_IPX = PLATFORM_AF_IPX;
const int AF_INET6 = PLATFORM_AF_INET6;
const int AF_INET @if(SUPPORTS_INET) = PLATFORM_AF_INET;
const int AF_APPLETALK @if(SUPPORTS_INET) = PLATFORM_AF_APPLETALK;
const int AF_IPX @if(SUPPORTS_INET) = PLATFORM_AF_IPX;
const int AF_INET6 @if(SUPPORTS_INET) = PLATFORM_AF_INET6;
const O_NONBLOCK = PLATFORM_O_NONBLOCK;
$endif

View File

@@ -1,8 +1,6 @@
module std::net::os;
module std::net::os @if(env::DARWIN);
import libc;
$if env::os_is_darwin():
const AI_NUMERICSERV = 0x1000;
const AI_ALL = 0x100;
const AI_V4MAPPED_CFG = 0x200;
@@ -11,18 +9,6 @@ const AI_V4MAPPED = 0x800;
const AI_UNUSABLE = 0x10000000;
const AI_DEFAULT = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
struct AddrInfo
{
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
usz ai_addrlen;
void* ai_addr;
char* ai_canonname;
AddrInfo* ai_next;
}
const int PLATFORM_AF_UNIX = 1;
const int PLATFORM_AF_INET = 2;
const int PLATFORM_AF_IMPLINK = 3;
@@ -61,7 +47,4 @@ const int PLATFORM_AF_IEEE80211 = 37;
const int PLATFORM_AF_UTUN = 38;
const int PLATFORM_AF_VSOCK = 40;
const int PLATFORM_AF_MAX = 41;
const int PLATFORM_O_NONBLOCK = 0x30;
$endif
const int PLATFORM_O_NONBLOCK = 0x30;

View File

@@ -1,20 +1,6 @@
module std::net::os;
module std::net::os @if(env::LINUX);
import libc;
$if env::OS_TYPE == LINUX:
struct AddrInfo
{
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
usz ai_addrlen;
void* ai_addr;
char* ai_canonname;
AddrInfo* ai_next;
}
const int PLATFORM_AF_UNIX = 1;
const int PLATFORM_AF_INET = 2;
const int PLATFORM_AF_AX25 = 3;
@@ -26,6 +12,4 @@ const int PLATFORM_AF_AAL5 = 8;
const int PLATFORM_AF_X25 = 9;
const int PLATFORM_AF_INET6 = 10;
const PLATFORM_O_NONBLOCK = 0o4000;
$endif
const PLATFORM_O_NONBLOCK = 0o4000;

View File

@@ -1,8 +1,6 @@
module std::net::os;
module std::net::os @if(env::POSIX && SUPPORTS_INET);
import libc;
$if !env::os_is_win32() && $defined(AddrInfo):
const int F_GETFL = 3;
const int F_SETFL = 4;
@@ -37,6 +35,4 @@ macro void! NativeSocket.set_non_blocking(NativeSocket this)
macro bool NativeSocket.is_non_blocking(NativeSocket this)
{
return fcntl(this, F_GETFL, 0) & O_NONBLOCK == O_NONBLOCK;
}
$endif
}

View File

@@ -1,6 +1,4 @@
module std::net::os;
$if env::os_is_win32():
module std::net::os @if(env::WIN32);
const int PLATFORM_AF_INET = 1;
const int PLATFORM_AF_IPX = 6;
@@ -10,18 +8,6 @@ const int PLATFORM_AF_INET6 = 23;
const int PLATFORM_AF_IRDA = 26;
const int PLATFORM_AF_BTH = 32;
struct AddrInfo
{
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
usz ai_addrlen;
char* ai_canonname;
void* ai_addr;
AddrInfo* ai_next;
}
def NativeSocket = distinct uptr;
extern fn int wsa_startup(int, void*) @extern("WSAStartup");
@@ -29,5 +15,3 @@ extern fn int ioctlsocket(NativeSocket, long cmd, ulong *argp);
extern fn int closesocket(NativeSocket);
macro NativeSocket.close(NativeSocket this) => closesocket(this);
$endif