WSAPoll

WSAPollは、複数のファイルディスクリプタを監視するWindowsAPI・・・。

WSAPoll function (Windows)

UNIX系OSのpollに当たるが、pollという関数は無く、これを使う・・・。
WSAPOLLFDは、UNIX系OSのpollfdに当たる・・・。
また、この関数自体Vistaから登場したもののため、環境によってはWindowsSDKが必要・・・。
WindowsSDKをインストールし、

f:id:BG1:20160115105006p:plain

[ツール]-[オプション]から、

f:id:BG1:20160115105137p:plain

WindowsSDKのインクルードパス、

f:id:BG1:20160115105321p:plain

ライブラリパスを通して、上のほうにセットしておく・・・。

クライアント側はWSASendプロジェクトを使い、サーバ側はWSAPollプロジェクトを新規作成・・・。
WSAPOLLFDの初期化とアクセプトループは、

このような感じ・・・。

WSAPollは、

WSAStartup success!
soc = 124
port = 0fa0, ns_port = a00f
setsockopt(SO_REUSEADDR) success.
bind Success.
listen success.
timeout!
timeout!
timeout!
timeout!
timeout!

2つコマンドプロンプトを起動し、

WSAStartup success!
hostname: localhost
port: 4000
host->h_addr_list[0][0] = 7f, host->h_addr_list[0][1] = 00, host->h_addr_list[0]
[3] = 00, host->h_addr_list[0][3] = 01
soc = 360
port = 0fa0, ns_port = a00f
WSAConnect success.
>hogehogebar

と、

WSAStartup success!
hostname: localhost
port: 4000
host->h_addr_list[0][0] = 7f, host->h_addr_list[0][1] = 00, host->h_addr_list[0]
[3] = 00, host->h_addr_list[0][3] = 01
soc = 360
port = 0fa0, ns_port = a00f
WSAConnect success.
>foofoobar

とすると、サーバは、

hogehogebar
timeout!
timeout!
timeout!
timeout!
foofoobar
timeout!
timeout!
timeout!
timeout!

2つのクライアントから送られたデータを出力・・・。

Sample/WSAPoll.cpp at master · bg1bgst333/Sample · GitHub
Sample/WSASend.cpp at master · bg1bgst333/Sample · GitHub