aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/http/http_proxy_acceptor.cpp
diff options
context:
space:
mode:
authorAlexey Efimov <xeno@prnwatch.com>2022-05-18 19:23:33 +0300
committerAlexey Efimov <xeno@prnwatch.com>2022-05-18 19:23:33 +0300
commit90e99413865b0990ff8a5e35251074288bde15d9 (patch)
treeb5c17609b32840b95a50f755cdfbe0ab25fc55cb /library/cpp/actors/http/http_proxy_acceptor.cpp
parente1b4a8a09912622730eea7b2d3ca1267ef9dc135 (diff)
downloadydb-90e99413865b0990ff8a5e35251074288bde15d9.tar.gz
add support for mixed and ipv4-only environment KIKIMR-14869
ref:ec57c92c9ef01b8aad21861c915e620ec8823586
Diffstat (limited to 'library/cpp/actors/http/http_proxy_acceptor.cpp')
-rw-r--r--library/cpp/actors/http/http_proxy_acceptor.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/library/cpp/actors/http/http_proxy_acceptor.cpp b/library/cpp/actors/http/http_proxy_acceptor.cpp
index d74ef0abac..f73c239780 100644
--- a/library/cpp/actors/http/http_proxy_acceptor.cpp
+++ b/library/cpp/actors/http/http_proxy_acceptor.cpp
@@ -22,9 +22,9 @@ public:
, Socket(new TSocketDescriptor())
{
// for unit tests :(
- CheckedSetSockOpt(Socket->Socket, SOL_SOCKET, SO_REUSEADDR, (int)true, "reuse address");
+ SetSockOpt(Socket->Socket, SOL_SOCKET, SO_REUSEADDR, (int)true);
#ifdef SO_REUSEPORT
- CheckedSetSockOpt(Socket->Socket, SOL_SOCKET, SO_REUSEPORT, (int)true, "reuse port");
+ SetSockOpt(Socket->Socket, SOL_SOCKET, SO_REUSEPORT, (int)true);
#endif
}
@@ -45,7 +45,7 @@ protected:
}
void HandleInit(TEvHttpProxy::TEvAddListeningPort::TPtr event, const NActors::TActorContext& ctx) {
- SocketAddressType bindAddress(event->Get()->Address ? event->Get()->Address.data() : "::", event->Get()->Port);
+ SocketAddressType bindAddress(Socket->Socket.MakeAddress(event->Get()->Address,event->Get()->Port));
Endpoint = std::make_shared<TPrivateEndpointInfo>(event->Get()->CompressContentTypes);
Endpoint->Owner = ctx.SelfID;
Endpoint->Proxy = Owner;
@@ -64,12 +64,12 @@ protected:
}
}
if (err == 0) {
- err = Socket->Socket.Bind(&bindAddress);
+ err = Socket->Socket.Bind(bindAddress.get());
}
if (err == 0) {
err = Socket->Socket.Listen(LISTEN_QUEUE);
if (err == 0) {
- LOG_INFO_S(ctx, HttpLog, "Listening on " << bindAddress.ToString());
+ LOG_INFO_S(ctx, HttpLog, "Listening on " << bindAddress->ToString());
SetNonBlock(Socket->Socket);
ctx.Send(Poller, new NActors::TEvPollerRegister(Socket, SelfId(), SelfId()));
TBase::Become(&TAcceptorActor::StateListening);
@@ -77,7 +77,7 @@ protected:
return;
}
}
- LOG_WARN_S(ctx, HttpLog, "Failed to listen on " << bindAddress.ToString() << " - retrying...");
+ LOG_WARN_S(ctx, HttpLog, "Failed to listen on " << bindAddress->ToString() << " - retrying...");
ctx.ExecutorThread.Schedule(TDuration::Seconds(1), event.Release());
}
@@ -94,10 +94,13 @@ protected:
}
void Handle(NActors::TEvPollerReady::TPtr, const NActors::TActorContext& ctx) {
- TIntrusivePtr<TSocketDescriptor> socket = new TSocketDescriptor();
- SocketAddressType addr;
- int err;
- while ((err = Socket->Socket.Accept(&socket->Socket, &addr)) == 0) {
+ for (;;) {
+ SocketAddressType addr;
+ std::optional<SocketType> s = Socket->Socket.Accept(addr);
+ if (!s) {
+ break;
+ }
+ TIntrusivePtr<TSocketDescriptor> socket = new TSocketDescriptor(std::move(s).value());
NActors::IActor* connectionSocket = nullptr;
if (RecycledRequests.empty()) {
connectionSocket = CreateIncomingConnectionActor(Endpoint, socket, addr);
@@ -108,9 +111,9 @@ protected:
NActors::TActorId connectionId = ctx.Register(connectionSocket);
ctx.Send(Poller, new NActors::TEvPollerRegister(socket, connectionId, connectionId));
Connections.emplace(connectionId);
- socket = new TSocketDescriptor();
}
- if (err == -EAGAIN || err == -EWOULDBLOCK) { // request poller for further connection polling
+ int err = errno;
+ if (err == EAGAIN || err == EWOULDBLOCK) { // request poller for further connection polling
Y_VERIFY(PollerToken);
PollerToken->Request(true, false);
}