Ejemplo n.º 1
0
void LocalChannel::incoming (ByteArrayPtr data){
	if (mCollector) mCollector->addPendingData (data->size());
	mInputBuffer.append(*data);
	if (mChanged) {
		xcall (mChanged);
	}
}
Ejemplo n.º 2
0
Error LocalChannel::write (const ByteArrayPtr& data, const ResultCallback & callback) {
	if (!mOther) return error::NotInitialized; // no target
	mOther->incoming (data);
	if (callback) xcall (abind (callback, NoError));
	if (mCollector) mCollector->addTransferred (mHostId, mOther->hostId(), data->size(), mHops);
	return NoError;
}
Ejemplo n.º 3
0
ByteArrayPtr Datagram::encode () const {
	// simple encoding headerLength, contentLength, header, content
	// both with 4 bytes
	size_t headerLength  = mHeader ? mHeader->size() : 0;
	if (headerLength > 2147483647) {
		Log (LogError) << LOGID << "Header to long!" << std::endl;
		assert (false);
		return ByteArrayPtr();
	}
	size_t contentLength = mContent ? mContent->size() : 0;
	if (contentLength > 2147483647) {
		Log (LogError) << LOGID << "Content to long" << std::endl;
		assert (false);
		return ByteArrayPtr();
	}
	uint32_t hln = htonl ((uint32_t)headerLength);
	uint32_t cln = htonl ((uint32_t)contentLength);

	ByteArrayPtr dest = createByteArrayPtr ();
	dest->reserve(8 + headerLength + contentLength);
	dest->append((const char*) &hln, 4);
	dest->append((const char*) &cln, 4);
	if (mHeader)
		dest->append(*mHeader);
	if (mContent)
		dest->append(*mContent);
	assert (dest->size() == 8 + headerLength + contentLength);
	return dest;
}
Ejemplo n.º 4
0
void UDPEchoClient::onReadyRead () {
	{
		LockGuard guard (mMutex);
		if (mState != WAIT) return; // ignoring; timeout.
		// Check protocol
		String from;
		int fromPort;
		ByteArrayPtr data = mSocket.recvFrom(&from,&fromPort);
		if (!data) {
			Log (LogWarning) << LOGID << "Could not read any data tough readyRead() signal" << std::endl;
			return; // ?
		}
		String toParse (data->const_c_array(), data->size());
		ArgumentList list;
		sf::argSplit (toParse, &list);
		// Format: TOKEN IP-Address Port
		if (list.size() != 4 || list[0] != "condataReply") {
			Log (LogInfo) << LOGID << "Invalid protocol in answer " << *data << ", token=" << list.size() <<  std::endl;
			return;   // invalid protocol
		}
		if (list[1] != mToken){
			Log (LogInfo) << LOGID << "Token mismatch in answer " << *data << std::endl;
			return; // invalid token
		}
		mState = READY;
		mAddress = list[2];
		mPort = atoi (list[3].c_str());
		Log (LogInfo) << LOGID << "Successfully decoded echo answer: " << mAddress << ":" << mPort << " coming from " << from << ":" << fromPort << std::endl;
		sf::cancelTimer(mTimeoutHandle);
	}
	mResultDelegate (NoError);
}
Ejemplo n.º 5
0
void SocketMessage::setPayload(const ByteArrayPtr &msg)
{
	clear();
	payload_type=Variant::TYPE_BYTEARRAY;
	payload_size=msg.size();
	payload=malloc(payload_size);
	if (!payload) throw OutOfMemoryException();
	memcpy(payload,msg.ptr(),payload_size);
}
Ejemplo n.º 6
0
	sf::Error write (const ds::Range & range, const ByteArrayPtr & data) {
		LockGuard guard (mMutex);
		ds::Range realRange = ds::Range (range.from - mWritePosition, range.to - mWritePosition);
		if (realRange.from != 0) {
			// no seeking
			return error::NotSupported;
		}
		mWritePosition+=data->size();
		return mChannel->write (data);
	}
Ejemplo n.º 7
0
void XMPPStream::onChannelChange   () {
	ByteArrayPtr data = mChannel->read();
	if (data && data->size() > 0){
#ifndef NDEBUG
		Log (LogInfo) << LOGID << "recv " << *data << std::endl;
#endif
		mXmlStreamDecoder.onWrite(*data);
	}
	// mXmlStreamDecoder can remove the channel by its own callbacks!
	if (mChannel && mChannel->error()) {
		onChannelError (mChannel->error());
	}
}
Ejemplo n.º 8
0
/*!\brief Nutzdaten des Chunks setzen
 *
 * \desc
 * Mit dieser Funktion werden die Nutzdaten des Chunks angegeben. Die
 * Daten werden dabei in einen eigenen Speicherbereich kopiert.
 *
 * \param data Eine Referenz aif ein ByteArray oder ByteArrayPtr
 * \exception NullPointerException Wird geworfen, wenn \p ptr auf NULL zeigt
 * \exception OutOfMemoryException Nicht genug Speicher
 */
void PFPChunk::setData(const ByteArrayPtr &data)
{
	setData(data.ptr(),data.size());
}