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); } }
bool TcpSocket::updateSend() { // Notify listener that it's time to send. if (_listener && !_listener->onSend(this)) return false; return flushSendBuffer(); }
void AbstractSshChannel::sendData(const QByteArray &data) { try { m_sendBuffer += data; flushSendBuffer(); } catch (Botan::Exception &e) { qDebug("Botan error: %s", e.what()); closeChannel(); } }
void AbstractSshChannel::sendData(const QByteArray &data) { try { m_sendBuffer += data; flushSendBuffer(); } catch (const std::exception &e) { qCWarning(sshLog, "Botan error: %s", e.what()); closeChannel(); } }
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(); }
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; }