/* read the potential DOHUnit state as soon as possible, but don't use it
until we have confirmed that we own this state by updating usageIndicator */
- auto du = std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>(ids->du, DOHUnit::release);
+ auto du = DOHUnitUniquePtr(ids->du, DOHUnit::release);
/* setting age to 0 to prevent the maintainer thread from
cleaning this IDS while we process the response.
*/
unsigned int idOffset = (ss->idOffset++) % ss->idStates.size();
IDState* ids = &ss->idStates[idOffset];
ids->age = 0;
- std::unique_ptr<DOHUnit, void(*)(DOHUnit*)> du(nullptr, DOHUnit::release);
+ DOHUnitUniquePtr du(nullptr, DOHUnit::release);
/* that means that the state was in use, possibly with an allocated
DOHUnit that we will need to handle, but we can't touch it before
confirming that we now own this state */
if (ids->isInUse()) {
- du = std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>(ids->du, DOHUnit::release);
+ du = DOHUnitUniquePtr(ids->du, DOHUnit::release);
}
/* we atomically replace the value, we now own this state */
continue;
}
ids.du = nullptr;
- handleDOHTimeout(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>(oldDU, DOHUnit::release));
+ handleDOHTimeout(DOHUnitUniquePtr(oldDU, DOHUnit::release));
oldDU = nullptr;
ids.age = 0;
dss->reuseds++;
/* This internal function sends back the object to the main thread to send a reply.
The caller should NOT release or touch the unit after calling this function */
-static void sendDoHUnitToTheMainThread(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& du, const char* description)
+static void sendDoHUnitToTheMainThread(DOHUnitUniquePtr&& du, const char* description)
{
auto ptr = du.release();
ptr->get();
/* This function is called from other threads than the main DoH one,
instructing it to send a 502 error to the client.
It takes ownership of the unit. */
-void handleDOHTimeout(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& oldDU)
+void handleDOHTimeout(DOHUnitUniquePtr&& oldDU)
{
if (oldDU == nullptr) {
return;
class DoHTCPCrossQuerySender : public TCPQuerySender
{
public:
- DoHTCPCrossQuerySender(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& du_): du(std::move(du_))
+ DoHTCPCrossQuerySender(DOHUnitUniquePtr&& du_): du(std::move(du_))
{
}
}
private:
- std::unique_ptr<DOHUnit, void(*)(DOHUnit*)> du;
+ DOHUnitUniquePtr du;
};
class DoHCrossProtocolQuery : public CrossProtocolQuery
{
public:
- DoHCrossProtocolQuery(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& du_): du(std::move(du_))
+ DoHCrossProtocolQuery(DOHUnitUniquePtr&& du_): du(std::move(du_))
{
query = InternalQuery(std::move(du->query), std::move(du->ids));
/* we _could_ remove it from the query buffer and put in query's d_proxyProtocolPayload,
}
private:
- std::unique_ptr<DOHUnit, void(*)(DOHUnit*)> du;
+ DOHUnitUniquePtr du;
};
/*
We are not in the main DoH thread but in the DoH 'client' thread.
*/
-static void processDOHQuery(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& du)
+static void processDOHQuery(DOHUnitUniquePtr&& du)
{
uint16_t queryId = 0;
ComboAddress remote;
to handle it because it's about to be overwritten. */
++du->downstream->reuseds;
++g_stats.downstreamTimeouts;
- handleDOHTimeout(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>(oldDU, DOHUnit::release));
+ handleDOHTimeout(DOHUnitUniquePtr(oldDU, DOHUnit::release));
}
ids->origFD = 0;
continue;
}
- std::unique_ptr<DOHUnit, void(*)(DOHUnit*)> du(ptr, DOHUnit::release);
+ DOHUnitUniquePtr du(ptr, DOHUnit::release);
/* we are not in the main DoH thread anymore, so there is a real risk of
a race condition where h2o kills the query while we are processing it,
so we can't touch the content of du->req until we are back into the
return;
}
- std::unique_ptr<DOHUnit, void(*)(DOHUnit*)> du(ptr, DOHUnit::release);
+ DOHUnitUniquePtr du(ptr, DOHUnit::release);
if (!du->req) { // it got killed in flight
du->self = nullptr;
continue;
}
}
-void handleUDPResponseForDoH(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& du, PacketBuffer&& udpResponse, IDState&& state)
+void handleUDPResponseForDoH(DOHUnitUniquePtr&& du, PacketBuffer&& udpResponse, IDState&& state)
{
du->response = std::move(udpResponse);
du->ids = std::move(state);