void InBandStream::close() { int state = streamState(); if (state==IDataStreamSocket::Opened || state==IDataStreamSocket::Opening) { emit aboutToClose(); if (FStanzaProcessor) { Stanza closeRequest(STANZA_KIND_IQ); closeRequest.setType(STANZA_TYPE_SET).setTo(FContactJid.full()).setUniqueId(); closeRequest.addElement("close",NS_INBAND_BYTESTREAMS).setAttribute("sid",FStreamId); if (FStanzaProcessor->sendStanzaRequest(this,FStreamJid,closeRequest,CLOSE_TIMEOUT)) { LOG_STRM_INFO(FStreamJid,QString("Close stream request sent, sid=%1").arg(FStreamId)); FCloseRequestId = closeRequest.id(); setStreamState(IDataStreamSocket::Closing); } else { LOG_STRM_WARNING(FStreamJid,QString("Failed to send close stream request, sid=%1").arg(FStreamId)); setStreamState(IDataStreamSocket::Closed); } } else { setStreamState(IDataStreamSocket::Closed); } } }
void InBandStream::setDataStanzaType(int AType) { if (streamState() == IDataStreamSocket::Closed) { FStanzaType = AType; emit propertiesChanged(); } }
void InBandStream::setBlockSize(int ASize) { if (streamState()==IDataStreamSocket::Closed && ASize>=MINIMUM_BLOCK_SIZE && ASize<=maximumBlockSize()) { FBlockSize = ASize; emit propertiesChanged(); } }
void InBandStream::abort(const XmppError &AError) { if (streamState() != IDataStreamSocket::Closed) { LOG_STRM_WARNING(FStreamJid,QString("Aborting stream, sid=%1: %2").arg(FStreamId,AError.errorMessage())); setStreamError(AError); close(); setStreamState(IDataStreamSocket::Closed); } }
bool InBandStream::waitForReadyRead(int AMsecs) { if (streamState()!=IDataStreamSocket::Closed && bytesAvailable()==0) { FThreadLock.lockForWrite(); FReadyReadCondition.wait(&FThreadLock, AMsecs>=0 ? (unsigned long)AMsecs : ULONG_MAX); FThreadLock.unlock(); } return bytesAvailable()>0; }
bool InBandStream::waitForBytesWritten(int AMsecs) { bool isWritten = false; if (streamState() != IDataStreamSocket::Closed) { FThreadLock.lockForWrite(); isWritten = FBytesWrittenCondition.wait(&FThreadLock, AMsecs>=0 ? (unsigned long)AMsecs : ULONG_MAX); FThreadLock.unlock(); } return isWritten && isOpen(); }
void FormatState::cleanup (std::ios_base::event e, std::ios_base &io, int) { try { if (e == std::ios_base::erase_event) delete streamState (io); } catch (std::ios::failure &e) { // C++ Standard 27.4.2.6 states that ios_base callbacks must not throw. } }
bool InBandStream::open(QIODevice::OpenMode AMode) { if (FStanzaProcessor && streamState()==IDataStreamSocket::Closed) { setStreamError(XmppError::null); if (streamKind() == IDataStream::Initiator) { Stanza openRequest(STANZA_KIND_IQ); openRequest.setType(STANZA_TYPE_SET).setTo(FContactJid.full()).setUniqueId(); QDomElement elem = openRequest.addElement("open",NS_INBAND_BYTESTREAMS); elem.setAttribute("sid",FStreamId); elem.setAttribute("block-size",FBlockSize); elem.setAttribute("stanza",FStanzaType==StanzaMessage ? STANZA_KIND_MESSAGE : STANZA_KIND_IQ); if (FStanzaProcessor->sendStanzaRequest(this,FStreamJid,openRequest,OPEN_TIMEOUT)) { LOG_STRM_INFO(FStreamJid,QString("Open stream request sent, sid=%1").arg(FStreamId)); FOpenRequestId = openRequest.id(); setOpenMode(AMode); setStreamState(IDataStreamSocket::Opening); return true; } else { LOG_STRM_WARNING(FStreamJid,QString("Failed to send open stream request, sid=%1").arg(FStreamId)); } } else { FSHIOpen = insertStanzaHandle(SHC_INBAND_OPEN); if (FSHIOpen != -1) { LOG_STRM_INFO(FStreamJid,QString("Open stanza handler inserted, sid=%1").arg(FStreamId)); setOpenMode(AMode); setStreamState(IDataStreamSocket::Opening); return true; } else { LOG_STRM_WARNING(FStreamJid,QString("Failed to insert open stanza handler, sid=%1").arg(FStreamId)); } } } return false; }
void InBandStream::setStreamState(int AState) { if (streamState() != AState) { if (AState == IDataStreamSocket::Opened) { FSeqIn = 0; FSeqOut = 0; FDataIqRequestId.clear(); FThreadLock.lockForWrite(); QIODevice::open(openMode()); FThreadLock.unlock(); LOG_STRM_INFO(FStreamJid,QString("In-band stream opened, sid=%1, stanzaType=%2").arg(FStreamId).arg(FStanzaType)); } else if (AState == IDataStreamSocket::Closed) { removeStanzaHandle(FSHIOpen); removeStanzaHandle(FSHIClose); removeStanzaHandle(FSHIData); emit readChannelFinished(); FThreadLock.lockForWrite(); FStreamState = AState; QString saveError = QIODevice::errorString(); QIODevice::close(); QIODevice::setErrorString(saveError); FReadBuffer.clear(); FWriteBuffer.clear(); FThreadLock.unlock(); FReadyReadCondition.wakeAll(); FBytesWrittenCondition.wakeAll(); LOG_STRM_INFO(FStreamJid,QString("In-band stream closed, sid=%1").arg(FStreamId)); } FThreadLock.lockForWrite(); FStreamState = AState; FThreadLock.unlock(); emit stateChanged(AState); } }
void MP3HTTPSource::writeGetCmd(char const* hostName, unsigned portNum, char const* fileName) { streamState()->writeGetCmd(hostName, portNum, fileName); }