| 149 | } |
| 150 | |
| 151 | Status ServicePool::QueueInboundCall(unique_ptr<InboundCall> call) { |
| 152 | InboundCall* c = call.release(); |
| 153 | |
| 154 | vector<uint32_t> unsupported_features; |
| 155 | for (uint32_t feature : c->GetRequiredFeatures()) { |
| 156 | if (!service_->SupportsFeature(feature)) { |
| 157 | unsupported_features.push_back(feature); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if (!unsupported_features.empty()) { |
| 162 | c->RespondUnsupportedFeature(unsupported_features); |
| 163 | return Status::NotSupported("call requires unsupported application feature flags", |
| 164 | JoinMapped(unsupported_features, |
| 165 | [] (uint32_t flag) { return std::to_string(flag); }, |
| 166 | ", ")); |
| 167 | } |
| 168 | |
| 169 | TRACE_TO(c->trace(), "Inserting onto call queue"); |
| 170 | |
| 171 | // Queue message on service queue |
| 172 | std::optional<InboundCall*> evicted; |
| 173 | auto queue_status = service_queue_.Put(c, &evicted); |
| 174 | if (queue_status == QUEUE_FULL) { |
| 175 | RejectTooBusy(c); |
| 176 | return Status::OK(); |
| 177 | } |
| 178 | |
| 179 | if (PREDICT_TRUE(evicted)) { |
| 180 | RejectTooBusy(*evicted); |
| 181 | } |
| 182 | |
| 183 | if (PREDICT_TRUE(queue_status == QUEUE_SUCCESS)) { |
| 184 | // NB: do not do anything with 'c' after it is successfully queued -- |
| 185 | // a service thread may have already dequeued it, processed it, and |
| 186 | // responded by this point, in which case the pointer would be invalid. |
| 187 | return Status::OK(); |
| 188 | } |
| 189 | |
| 190 | Status status = Status::OK(); |
| 191 | if (queue_status == QUEUE_SHUTDOWN) { |
| 192 | status = Status::ServiceUnavailable("Service is shutting down"); |
| 193 | c->RespondFailure(ErrorStatusPB::FATAL_SERVER_SHUTTING_DOWN, status); |
| 194 | } else { |
| 195 | status = Status::RuntimeError(Substitute("Unknown error from BlockingQueue: $0", queue_status)); |
| 196 | c->RespondFailure(ErrorStatusPB::FATAL_UNKNOWN, status); |
| 197 | } |
| 198 | return status; |
| 199 | } |
| 200 | |
| 201 | void ServicePool::RunThread() { |
| 202 | while (true) { |
nothing calls this directly
no test coverage detected