core.sys.windows so lean?

Jonathan Marler via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 6 09:51:20 PDT 2016


On Monday, 6 June 2016 at 16:13:48 UTC, Vladimir Panteleev wrote:
> On Monday, 6 June 2016 at 16:04:30 UTC, Jonathan Marler wrote:
>> I'm writing some platform specific D code and I've found that 
>> what the druntime exposes for the windows platform is pretty 
>> lean.  I'm guessing that the purpose of the druntime version 
>> of the windows api is to implement the minimum required to 
>> support the windows platform and not meant to be a 
>> full-featured interface to windows.  Is this the case?
>
> Erm, not since 2.070:
>

Hmmm...it seems to be missing quite alot though.  Especially the 
winsock api.  Over the weekend I was writing some code that uses 
a windows IOCompletionPort and had to add a fair amount of code 
that was missing:

   import core.sys.windows.windows;
   import core.sys.windows.winsock2;

   // NOTE: not sure if this stuff should be included in 
core.sys.windows.winsock2
   alias u_long = uint; // NOTE: not sure if uint is the best 
alias for u_long

   // The actual sockaddr_in structure in windows is 24 bytes long,
   // but the sockaddr_in defined in core.sys.windows.winsock2 is 
only 20.
   // This caused an error when calling AcceptEx that indicated 
the buffer
   // size for sockaddr_in was too small.
   union real_sockaddr_in {
     sockaddr_in addr;
     ubyte[24] padding; // make sure the sockaddr_in takes 24 bytes
   }

   struct WSABUF {
     u_long len;
     char* buf;
   }
   alias LPWSABUF = WSABUF*;

   // NOTE: WSAOVERLAPPED is supposed to be castable to and from 
OVERLAPPED.
   //       Maybe this doesn't need to be defined, maybe I could 
just always use OVERLAPPED?
   struct WSAOVERLAPPED {
     ULONG* Internal;
     ULONG* InternalHigh;
     union {
       struct {
	DWORD Offset;
	DWORD OffsetHigh;
       }
       PVOID Pointer;
     }
     HANDLE hEvent;
   }
   alias LPWSAOVERLAPPED = WSAOVERLAPPED*;
   alias LPWSAOVERLAPPED_COMPLETION_ROUTINE = void function(uint, 
uint, LPWSAOVERLAPPED, uint);

   enum : int {
     SIO_GET_EXTENSION_FUNCTION_POINTER = 0xc8000006,
   }

   enum GUID WSAID_ACCEPTEX = 
{0xb5367df1,0xcbac,0x11cf,[0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92]};
   alias LPFN_ACCEPTEX = extern(Windows) bool function(SOCKET 
listenSocket,
						      SOCKET acceptSocket,
						      PVOID outputBuffer,
						      DWORD receiveDataLength,
						      DWORD localAddressLength,
						      DWORD remoteAddressLength,
						      DWORD* bytesReceived,
						      OVERLAPPED* overlapped) nothrow @nogc;


   extern(Windows) int WSAIoctl(SOCKET s, uint dwIoControlCode,
			       void* lpvInBuffer, uint cbInBuffer,
			       void* lpvOutBuffer, uint cbOutBuffer,
			       uint* lpcbBytesReturned,
			       LPWSAOVERLAPPED lpOverlapped, 
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) nothrow 
@nogc;
   extern(Windows) int WSARecv(SOCKET s, LPWSABUF lpBuffer, DWORD 
bufferCount,
			      LPDWORD numberOfBytesReceived, LPDWORD flags,
			      LPWSAOVERLAPPED overlapped, 
LPWSAOVERLAPPED_COMPLETION_ROUTINE completionRoutine);


More information about the Digitalmars-d-learn mailing list