| 197 | } |
| 198 | |
| 199 | void |
| 200 | IPCSocketServer::run() |
| 201 | { |
| 202 | _running.store(true); |
| 203 | |
| 204 | while (_running) { |
| 205 | // poll till socket it's ready. |
| 206 | if (!this->poll_for_new_client()) { |
| 207 | if (_running.load()) { |
| 208 | Warning("ups, we've got an issue."); |
| 209 | } |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | std::error_code ec; |
| 214 | if (int fd = this->accept(ec); !ec) { |
| 215 | Client client{fd, _conf.incomingRequestMaxBufferSize}; |
| 216 | Buffer bw; |
| 217 | |
| 218 | if (auto [ok, errStr] = client.read_all(bw); ok) { |
| 219 | const std::string &json = bw.str(); |
| 220 | rpc::Context ctx; |
| 221 | // we want to make sure the peer's credentials are ok. |
| 222 | ctx.get_auth().add_checker( |
| 223 | [&](TSRPCHandlerOptions const &opt, swoc::Errata &errata) -> void { late_check_peer_credentials(fd, opt, errata); }); |
| 224 | |
| 225 | if (auto response = rpc::JsonRPCManager::instance().handle_call(ctx, json); response) { |
| 226 | // seems a valid response. |
| 227 | if (client.write(*response, ec); ec) { |
| 228 | Dbg(dbg_ctl, "Error sending the response: %s", ec.message().c_str()); |
| 229 | } |
| 230 | } // it was a notification. |
| 231 | } else { |
| 232 | Dbg(dbg_ctl, "Error detected while reading: %s", errStr.c_str()); |
| 233 | } |
| 234 | } else { |
| 235 | Dbg(dbg_ctl, "Error while accepting a new connection on the socket: %s", ec.message().c_str()); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | this->close(); |
| 240 | } |
| 241 | |
| 242 | bool |
| 243 | IPCSocketServer::stop() |
no test coverage detected