| 107 | } |
| 108 | |
| 109 | void TServerFramework::serve() { |
| 110 | shared_ptr<TTransport> client; |
| 111 | shared_ptr<TTransport> inputTransport; |
| 112 | shared_ptr<TTransport> outputTransport; |
| 113 | shared_ptr<TProtocol> inputProtocol; |
| 114 | shared_ptr<TProtocol> outputProtocol; |
| 115 | |
| 116 | // Start the server listening |
| 117 | serverTransport_->listen(); |
| 118 | |
| 119 | // Run the preServe event to indicate server is now listening |
| 120 | // and that it is safe to connect. |
| 121 | if (eventHandler_) { |
| 122 | eventHandler_->preServe(); |
| 123 | } |
| 124 | |
| 125 | // Fetch client from server |
| 126 | for (;;) { |
| 127 | try { |
| 128 | // Dereference any resources from any previous client creation |
| 129 | // such that a blocking accept does not hold them indefinitely. |
| 130 | outputProtocol.reset(); |
| 131 | inputProtocol.reset(); |
| 132 | outputTransport.reset(); |
| 133 | inputTransport.reset(); |
| 134 | client.reset(); |
| 135 | |
| 136 | // If we have reached the limit on the number of concurrent |
| 137 | // clients allowed, wait for one or more clients to drain before |
| 138 | // accepting another. |
| 139 | { |
| 140 | Synchronized sync(mon_); |
| 141 | while (clients_ >= limit_) { |
| 142 | mon_.wait(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | client = serverTransport_->accept(); |
| 147 | |
| 148 | inputTransport = inputTransportFactory_->getTransport(client); |
| 149 | outputTransport = outputTransportFactory_->getTransport(client); |
| 150 | if (!outputProtocolFactory_) { |
| 151 | inputProtocol = inputProtocolFactory_->getProtocol(inputTransport, outputTransport); |
| 152 | outputProtocol = inputProtocol; |
| 153 | } else { |
| 154 | inputProtocol = inputProtocolFactory_->getProtocol(inputTransport); |
| 155 | outputProtocol = outputProtocolFactory_->getProtocol(outputTransport); |
| 156 | } |
| 157 | |
| 158 | newlyConnectedClient(shared_ptr<TConnectedClient>( |
| 159 | new TConnectedClient(getProcessor(inputProtocol, outputProtocol, client), |
| 160 | inputProtocol, |
| 161 | outputProtocol, |
| 162 | eventHandler_, |
| 163 | client), |
| 164 | bind(&TServerFramework::disposeConnectedClient, this, std::placeholders::_1))); |
| 165 | |
| 166 | } catch (TTransportException& ttx) { |
nothing calls this directly
no test coverage detected