Unverified Commit 5822b19c authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #604 from capnproto/fix-connect

Fix multiple problems with connect() on non-glibc-Linux:
parents 3b834806 bd05ffe8
......@@ -1084,6 +1084,10 @@ public:
}
Promise<Own<AsyncIoStream>> wrapConnectingSocketFd(
int fd, const struct sockaddr* addr, uint addrlen, uint flags = 0) override {
// It's important that we construct the AsyncStreamFd first, so that `flags` are honored,
// especially setting nonblocking mode and taking ownership.
auto result = heap<AsyncStreamFd>(eventPort, fd, flags);
// Unfortunately connect() doesn't fit the mold of KJ_NONBLOCKING_SYSCALL, since it indicates
// non-blocking using EINPROGRESS.
for (;;) {
......@@ -1102,8 +1106,6 @@ public:
}
}
auto result = heap<AsyncStreamFd>(eventPort, fd, flags);
auto connected = result->waitConnected();
return connected.then(kj::mvCapture(result, [fd](Own<AsyncIoStream>&& stream) {
int err;
......@@ -1223,12 +1225,11 @@ private:
ArrayPtr<SocketAddress> addrs) {
KJ_ASSERT(addrs.size() > 0);
int fd = addrs[0].socket(SOCK_STREAM);
return kj::evalNow([&]() -> Promise<Own<AsyncIoStream>> {
if (!addrs[0].allowedBy(filter)) {
return KJ_EXCEPTION(FAILED, "connect() blocked by restrictPeers()");
} else {
int fd = addrs[0].socket(SOCK_STREAM);
return lowLevel.wrapConnectingSocketFd(
fd, addrs[0].getRaw(), addrs[0].getRawSize(), NEW_FD_FLAGS);
}
......
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