MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ProcessBuffer

Method ProcessBuffer

src/torcontrol.cpp:179–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177}
178
179bool TorControlConnection::ProcessBuffer()
180{
181 util::LineReader reader(m_recv_buffer, MAX_LINE_LENGTH);
182 auto start = reader.it;
183
184 while (auto line = reader.ReadLine()) {
185 if (m_message.lines.size() == MAX_LINE_COUNT) {
186 throw std::runtime_error(strprintf("Control port reply exceeded %d lines, disconnecting", MAX_LINE_COUNT));
187 }
188 // Skip short lines
189 if (line->size() < 4) continue;
190
191 // Parse: <code><separator><data>
192 // <status>(-|+| )<data>
193 m_message.code = ToIntegral<int>(line->substr(0, 3)).value_or(0);
194 m_message.lines.emplace_back(line->substr(4));
195 char separator = (*line)[3]; // '-', '+', or ' '
196
197 if (separator == ' ') {
198 if (m_message.code >= 600) {
199 // Async notifications are currently unused
200 // Synchronous and asynchronous messages are never interleaved
201 LogDebug(BCLog::TOR, "Received async notification %i", m_message.code);
202 } else if (!m_reply_handlers.empty()) {
203 // Invoke reply handler with message
204 m_reply_handlers.front()(*this, m_message);
205 m_reply_handlers.pop_front();
206 } else {
207 LogDebug(BCLog::TOR, "Received unexpected sync reply %i", m_message.code);
208 }
209 m_message.Clear();
210 }
211 }
212
213 m_recv_buffer.erase(m_recv_buffer.begin(), m_recv_buffer.begin() + std::distance(start, reader.it));
214 return true;
215}
216
217bool TorControlConnection::Command(const std::string &cmd, const ReplyHandlerCB& reply_handler)
218{

Callers

nothing calls this directly

Calls 10

ReadLineMethod · 0.80
sizeMethod · 0.45
value_orMethod · 0.45
emplace_backMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45
pop_frontMethod · 0.45
ClearMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected