void AsyncPacketQueue::dispatch(IPacket& packet) { if (cancelled()) { WarnS(this) << "Dispatch late packet" << endl; assert(0); return; } PacketStreamAdapter::emit(packet); }
void SyncPacketQueue::process(IPacket& packet) { if (cancelled()) { WarnS(this) << "Process late packet" << endl; assert(0); return; } push(packet.clone()); }
void SyncPacketQueue::dispatch(IPacket& packet) { // Emit should never be called after closure. // Any late packets should have been dealt with // and dropped by the run() function. if (cancelled()) { WarnS(this) << "Dispatch late packet" << endl; assert(0); return; } PacketStreamAdapter::emit(packet); }
void ConnectionAdapter::onSocketRecv(const MutableBuffer& buf, const net::Address& /* peerAddr */) { TraceS(this) << "On socket recv: " << buf.size() << endl; // TraceS(this) << "On socket recv: " << buf.str() << endl; if (_parser.complete()) { // Buggy HTTP servers might send late data or multiple responses, // in which case the parser state might already be HPE_OK. // In this case we discard the late message and log the error here, // rather than complicate the app with this error handling logic. // This issue was noted using Webrick with Ruby 1.9. WarnS(this) << "Dropping late HTTP response: " << buf.str() << endl; return; } // Parse incoming HTTP messages _parser.parse(bufferCast<const char*>(buf), buf.size()); }
void PacketStream::process(IPacket& packet) { TraceS(this) << "Processing packet: " << state() << ": " << packet.className() << endl; // assert(Thread::currentID() == _runner->tid()); try { // Auto start the stream if required and currently inactive if (_autoStart && stateEquals(PacketStreamState::None)) start(); // Process the packet if the stream is active PacketProcessor* firstProc = nullptr; if (stateEquals(PacketStreamState::Active) && !packet.flags.has(PacketFlags::NoModify)) { { std::lock_guard<std::mutex> guard(_mutex); firstProc = !_processors.empty() ? reinterpret_cast<PacketProcessor*>( _processors[0]->ptr) : nullptr; } if (firstProc) { // Lock the processor mutex to synchronize multi source streams std::lock_guard<std::mutex> guard(_procMutex); // Sync queued states synchronizeStates(); // Send the packet to the first processor in the chain if (stateEquals(PacketStreamState::Active)) { // TraceS(this) << "Starting process chain: " // << firstProc << ": " << packet.className() << endl; // assert(stateEquals(PacketStreamState::Active)); if (firstProc->accepts(packet)) firstProc->process(packet); else firstProc->emit(packet); // TraceS(this) << "After process chain: " // << firstProc << ": " << packet.className() << endl; // If all went well the packet was processed and emitted... } // Proxy packets which are rejected by the first processor else { WarnS(this) << "Source packet rejected: " << firstProc << ": " << packet.className() << endl; firstProc = nullptr; } } } // Otherwise just proxy and emit the packet // TODO: Should we pass the packet to the PacketSyncQueue if // synchronizeOutput was used? if (!firstProc) { TraceS(this) << "Proxying packet: " << state() << ": " << packet.className() << endl; emit(packet); } // Stop the packet stream on the final packet if (stateEquals(PacketStreamState::Active) && packet.flags.has(PacketFlags::Final)) { this->stop(); } } // Catch any exceptions thrown within the processor catch (std::exception& exc) { handleException(exc); } // TraceS(this) << "End process chain: " // << state() << ": " << packet.className() << endl; }