This function blocks until some bytes show up from the client. Returns true if some bytes are available from client; Returns false upon reading EOF, in which case the connection will be closed by the caller. If idle_poll_period_ms_ is not 0, this function will block up to idle_poll_period_ms_ milliseconds before waking up to check if the sessions associated with the connection have all expired du
| 146 | // due to inactivity. If so, it will return false and the connection |
| 147 | // will be closed by the caller. |
| 148 | bool Peek(void* connectionContext, TServerEventHandler* eventHandler) { |
| 149 | // Set a timeout on input socket if idle_poll_period_ms_ is non-zero. |
| 150 | TSocket* socket = static_cast<TSocket*>(transport_.get()); |
| 151 | if (server_.idle_poll_period_ms_ > 0) { |
| 152 | socket->setRecvTimeout(server_.idle_poll_period_ms_); |
| 153 | } |
| 154 | |
| 155 | // Block until some bytes show up or EOF or timeout. |
| 156 | bool bytes_pending = true; |
| 157 | for (;;) { |
| 158 | try { |
| 159 | bytes_pending = input_->getTransport()->peek(); |
| 160 | break; |
| 161 | } catch (const TTransportException& ttx) { |
| 162 | // Implementation of the underlying transport's peek() may call either |
| 163 | // read() or peek() of the socket. |
| 164 | if (eventHandler != nullptr && server_.idle_poll_period_ms_ > 0 && |
| 165 | (IsReadTimeoutTException(ttx) || IsPeekTimeoutTException(ttx))) { |
| 166 | VLOG(2) << Substitute("Socket read or peek timeout encountered " |
| 167 | "(idle_poll_period_ms_=$0). $1", |
| 168 | server_.idle_poll_period_ms_, ttx.what()); |
| 169 | ThriftServer::ThriftServerEventProcessor* thriftServerHandler = |
| 170 | static_cast<ThriftServer::ThriftServerEventProcessor*>(eventHandler); |
| 171 | if (thriftServerHandler->IsIdleContext(connectionContext)) { |
| 172 | const string& client = socket->getSocketInfo(); |
| 173 | GlobalOutput.printf( |
| 174 | "TAcceptQueueServer closing connection to idle client %s", client.c_str()); |
| 175 | bytes_pending = false; |
| 176 | break; |
| 177 | } |
| 178 | } else { |
| 179 | // Rethrow the exception to be handled by callers. |
| 180 | throw; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | // Unset the socket timeout. |
| 185 | if (server_.idle_poll_period_ms_ > 0) socket->setRecvTimeout(0); |
| 186 | return bytes_pending; |
| 187 | } |
| 188 | |
| 189 | TAcceptQueueServer& server_; |
| 190 | friend class TAcceptQueueServer; |
nothing calls this directly
no test coverage detected