Commit fc5f8768 authored by Kenton Varda's avatar Kenton Varda

win32Socketpair() shouldn't just fail if setupAsyncIo() hasn't been called

parent 14589b38
...@@ -49,6 +49,20 @@ namespace kj { ...@@ -49,6 +49,20 @@ namespace kj {
namespace _ { // private namespace _ { // private
struct WinsockInitializer {
WinsockInitializer() {
WSADATA dontcare;
int result = WSAStartup(MAKEWORD(2, 2), &dontcare);
if (result != 0) {
KJ_FAIL_WIN32("WSAStartup()", result);
}
}
};
void initWinsockOnce() {
static WinsockInitializer initializer;
}
int win32Socketpair(SOCKET socks[2]) { int win32Socketpair(SOCKET socks[2]) {
// This function from: https://github.com/ncm/selectable-socketpair/blob/master/socketpair.c // This function from: https://github.com/ncm/selectable-socketpair/blob/master/socketpair.c
// //
...@@ -84,6 +98,8 @@ int win32Socketpair(SOCKET socks[2]) { ...@@ -84,6 +98,8 @@ int win32Socketpair(SOCKET socks[2]) {
// TODO(cleanup): Consider putting this somewhere public? Note that since it depends on Winsock, // TODO(cleanup): Consider putting this somewhere public? Note that since it depends on Winsock,
// it needs to be in the kj-async library. // it needs to be in the kj-async library.
initWinsockOnce();
union { union {
struct sockaddr_in inaddr; struct sockaddr_in inaddr;
struct sockaddr addr; struct sockaddr addr;
...@@ -1116,11 +1132,7 @@ Own<AsyncIoProvider> newAsyncIoProvider(LowLevelAsyncIoProvider& lowLevel) { ...@@ -1116,11 +1132,7 @@ Own<AsyncIoProvider> newAsyncIoProvider(LowLevelAsyncIoProvider& lowLevel) {
} }
AsyncIoContext setupAsyncIo() { AsyncIoContext setupAsyncIo() {
WSADATA dontcare; _::initWinsockOnce();
int result = WSAStartup(MAKEWORD(2, 2), &dontcare);
if (result != 0) {
KJ_FAIL_WIN32("WSAStartup()", result);
}
auto lowLevel = heap<LowLevelAsyncIoProviderImpl>(); auto lowLevel = heap<LowLevelAsyncIoProviderImpl>();
auto ioProvider = kj::heap<AsyncIoProviderImpl>(*lowLevel); auto ioProvider = kj::heap<AsyncIoProviderImpl>(*lowLevel);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment