/** * @brief * * @param writeable * @param frame * * @return */ bool HttpImageStream::sendFrame( Select::CommsList &writeable, FramePtr frame ) { const ByteBuffer &packet = frame->buffer(); std::string txHeaders = "--imgboundary\r\n"; txHeaders += "Content-Type: image/jpeg\r\n"; txHeaders += stringtf( "Content-Length: %zd\r\n\r\n", packet.size() ); ByteBuffer txBuffer; txBuffer.reserve( packet.size()+128 ); txBuffer.append( txHeaders.c_str(), txHeaders.size() ); txBuffer.append( packet.data(), packet.size() ); txBuffer.append( "\r\n", 2 ); for ( Select::CommsList::iterator iter = writeable.begin(); iter != writeable.end(); iter++ ) { if ( TcpInetSocket *socket = dynamic_cast<TcpInetSocket *>(*iter) ) { if ( socket == mConnection->socket() ) { int nBytes = socket->write( txBuffer.data(), txBuffer.size() ); const FeedFrame *sourceFrame = frame->sourceFrame(); Debug( 4, "Wrote %d bytes on sd %d, frame %ju<-%ju", nBytes, socket->getWriteDesc(), frame->id(), sourceFrame->id() ); if ( nBytes != txBuffer.size() ) { Error( "Incomplete write, %d bytes instead of %zd", nBytes, packet.size() ); mStop = true; return( false ); } } } } return( true ); }
/** * @brief * * @param writeable * @param frame * * @return */ bool HttpDataStream::sendFrame( Select::CommsList &writeable, FramePtr frame ) { const ByteBuffer &packet = frame->buffer(); for ( Select::CommsList::iterator iter = writeable.begin(); iter != writeable.end(); iter++ ) { if ( TcpInetSocket *socket = dynamic_cast<TcpInetSocket *>(*iter) ) { if ( socket == mConnection->socket() ) { int nBytes = socket->write( packet.data(), packet.size() ); const FeedFrame *sourceFrame = frame->sourceFrame(); Debug( 4, "Wrote %d bytes on sd %d, frame %ju<-%ju", nBytes, socket->getWriteDesc(), frame->id(), sourceFrame->id() ); if ( nBytes != packet.size() ) { Error( "Incomplete write, %d bytes instead of %zd", nBytes, packet.size() ); mStop = true; return( false ); } } } } return( true ); }