Exemplo n.º 1
0
bool TcpSocket::send(DataToSend* data)
{
	if (!isValid()) return false;

	if (data == NULL) return true;

	switch (data->getType())
	{
	case DataToSend::DS_NONE:
		return true;

	case DataToSend::DS_BUF:
		// Copy into send buf and then flush
		_sendBuf->copyFrom(data->getBuffer(), data->getOffset(), _sendBuf->getSize(), data->getSize());
		return flushSendBuffer();

	case DataToSend::DS_READER:
		// Copy into send buf and then flush
		if (data->getOffset())
			data->getReader()->skip(data->getOffset());
		_sendBuf->load(data->getReader(), _sendBuf->getSize(), data->getSize());
		return flushSendBuffer();

	case DataToSend::DS_BYTES:
		return send(((const char*)data->getBytes()) + data->getOffset(), data->getSize());

	default:
		NIT_THROW(EX_NOT_SUPPORTED);
	}
}
Exemplo n.º 2
0
bool TcpSocket::updateSend()
{
	// Notify listener that it's time to send.
	if (_listener && !_listener->onSend(this))
		return false;

	return flushSendBuffer();
}
Exemplo n.º 3
0
void AbstractSshChannel::sendData(const QByteArray &data)
{
    try {
        m_sendBuffer += data;
        flushSendBuffer();
    }  catch (Botan::Exception &e) {
        qDebug("Botan error: %s", e.what());
        closeChannel();
    }
}
Exemplo n.º 4
0
void AbstractSshChannel::sendData(const QByteArray &data)
{
    try {
        m_sendBuffer += data;
        flushSendBuffer();
    }  catch (const std::exception &e) {
        qCWarning(sshLog, "Botan error: %s", e.what());
        closeChannel();
    }
}
Exemplo n.º 5
0
void AbstractSshChannel::handleWindowAdjust(quint32 bytesToAdd)
{
    checkChannelActive();

    const quint64 newValue = m_remoteWindowSize + bytesToAdd;
    if (newValue > 0xffffffffu) {
        throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
            "Illegal window size requested.");
    }

    m_remoteWindowSize = newValue;
    flushSendBuffer();
}
Exemplo n.º 6
0
bool TcpSocket::send(const void* data, size_t size)
{
	const char* buf = (const char*)data;

	if (isConnecting() || !_sendBuf->isEmpty())
	{
		// If buffering, just add tail to send buf then flush
		_sendBuf->pushBack(buf, size);
		return flushSendBuffer();
	}

	if (isConnected())
	{
		// If not buffering, try to send at once
		int sent = ::send(_handle, buf, size, 0);

		if (sent == size)
			return true;

		if (sent == SOCKET_ERROR)
		{
			int err = getLastError();
			if (err == ERR_WOULD_BLOCK)
				sent = 0;
			else
				return error("Send", err);
		}
		else if (sent == 0)
		{
			return error("Disconnected", ERR_CONN_RESET);
		}

		assert(size_t(sent) < size);

		// We have some remainder - save into sendbuf the remaing bytes
		buf += sent;
		size -= sent;
		_sendBuf->pushBack(buf, size);
		return true;
	}

	// Connecting in progress or not connected
	return false;
}