Win32 API 日本語リファレンス
ホームNetworking.WinSock › WSAPoll

WSAPoll

関数
複数ソケットの状態変化をポーリングで監視する。
DLLWS2_32.dll呼出規約winapiSetLastErrorあり対応OSWindows 8.1 以降

シグネチャ

// WS2_32.dll
#include <windows.h>

INT WSAPoll(
    WSAPOLLFD* fdArray,
    DWORD fds,
    INT timeout
);

パラメーター

名前方向
fdArrayWSAPOLLFD*inout
fdsDWORDin
timeoutINTin

戻り値の型: INT

各言語での呼び出し定義

// WS2_32.dll
#include <windows.h>

INT WSAPoll(
    WSAPOLLFD* fdArray,
    DWORD fds,
    INT timeout
);
[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern int WSAPoll(
    IntPtr fdArray,   // WSAPOLLFD* in/out
    uint fds,   // DWORD
    int timeout   // INT
);
<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAPoll(
    fdArray As IntPtr,   ' WSAPOLLFD* in/out
    fds As UInteger,   ' DWORD
    timeout As Integer   ' INT
) As Integer
End Function
' fdArray : WSAPOLLFD* in/out
' fds : DWORD
' timeout : INT
Declare PtrSafe Function WSAPoll Lib "ws2_32" ( _
    ByVal fdArray As LongPtr, _
    ByVal fds As Long, _
    ByVal timeout As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WSAPoll = ctypes.windll.ws2_32.WSAPoll
WSAPoll.restype = ctypes.c_int
WSAPoll.argtypes = [
    ctypes.c_void_p,  # fdArray : WSAPOLLFD* in/out
    wintypes.DWORD,  # fds : DWORD
    ctypes.c_int,  # timeout : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WS2_32.dll')
WSAPoll = Fiddle::Function.new(
  lib['WSAPoll'],
  [
    Fiddle::TYPE_VOIDP,  # fdArray : WSAPOLLFD* in/out
    -Fiddle::TYPE_INT,  # fds : DWORD
    Fiddle::TYPE_INT,  # timeout : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "ws2_32")]
extern "system" {
    fn WSAPoll(
        fdArray: *mut WSAPOLLFD,  // WSAPOLLFD* in/out
        fds: u32,  // DWORD
        timeout: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern int WSAPoll(IntPtr fdArray, uint fds, int timeout);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAPoll' -Namespace Win32 -PassThru
# $api::WSAPoll(fdArray, fds, timeout)
#uselib "WS2_32.dll"
#func global WSAPoll "WSAPoll" sptr, sptr, sptr
; WSAPoll varptr(fdArray), fds, timeout   ; 戻り値は stat
; fdArray : WSAPOLLFD* in/out -> "sptr"
; fds : DWORD -> "sptr"
; timeout : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WS2_32.dll"
#cfunc global WSAPoll "WSAPoll" var, int, int
; res = WSAPoll(fdArray, fds, timeout)
; fdArray : WSAPOLLFD* in/out -> "var"
; fds : DWORD -> "int"
; timeout : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT WSAPoll(WSAPOLLFD* fdArray, DWORD fds, INT timeout)
#uselib "WS2_32.dll"
#cfunc global WSAPoll "WSAPoll" var, int, int
; res = WSAPoll(fdArray, fds, timeout)
; fdArray : WSAPOLLFD* in/out -> "var"
; fds : DWORD -> "int"
; timeout : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procWSAPoll = ws2_32.NewProc("WSAPoll")
)

// fdArray (WSAPOLLFD* in/out), fds (DWORD), timeout (INT)
r1, _, err := procWSAPoll.Call(
	uintptr(fdArray),
	uintptr(fds),
	uintptr(timeout),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function WSAPoll(
  fdArray: Pointer;   // WSAPOLLFD* in/out
  fds: DWORD;   // DWORD
  timeout: Integer   // INT
): Integer; stdcall;
  external 'WS2_32.dll' name 'WSAPoll';
result := DllCall("WS2_32\WSAPoll"
    , "Ptr", fdArray   ; WSAPOLLFD* in/out
    , "UInt", fds   ; DWORD
    , "Int", timeout   ; INT
    , "Int")   ; return: INT
●WSAPoll(fdArray, fds, timeout) = DLL("WS2_32.dll", "int WSAPoll(void*, dword, int)")
# 呼び出し: WSAPoll(fdArray, fds, timeout)
# fdArray : WSAPOLLFD* in/out -> "void*"
# fds : DWORD -> "dword"
# timeout : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。