void QmlIODevice::setDevice(QIODevice *io) { if(m_device != io) { //! 如果 m_device 被删除了怎么办? if(m_device != Q_NULLPTR) { disconnect(m_device, 0, this, 0); } m_device = io; if(m_device != Q_NULLPTR) { connect( m_device,SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose()) ); connect( m_device, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64)) ); connect( m_device, SIGNAL(readChannelFinished()), this, SIGNAL(readChannelFinished()) ); connect( m_device, SIGNAL(readyRead()), this, SIGNAL(readyRead()) ); } emit deviceChanged(); emit hasDeviceChanged(this->hasDevice()); } }
bool IpsEngineClient::doConnect() { if(!socket) { socket = new QTcpSocket(this); connect(socket, SIGNAL(connected()),this, SLOT(connected())); connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected())); connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64))); connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); } opened=false; busy=true; qDebug() << "connecting..."; // this is not blocking call socket->connectToHost(QHostAddress::LocalHost, 58486); // we need to wait... if(!socket->waitForConnected(10000)) { qDebug() << "Error: " << socket->errorString(); busy=false; return false; } busy=false; return true; }
// Constructs an unconnected PeerWire client and starts the connect timer. PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent) : QTcpSocket(parent), pendingBlockSizes(0), pwState(ChokingPeer | ChokedByPeer), receivedHandShake(false), gotPeerId(false), sentHandShake(false), nextPacketLength(-1), pendingRequestTimer(0), invalidateTimeout(false), keepAliveTimer(0), torrentPeer(0) { memset(uploadSpeedData, 0, sizeof(uploadSpeedData)); memset(downloadSpeedData, 0, sizeof(downloadSpeedData)); transferSpeedTimer = startTimer(RateControlTimerDelay); timeoutTimer = startTimer(ConnectTimeout); peerIdString = peerId; connect(this, SIGNAL(readyRead()), this, SIGNAL(readyToTransfer())); connect(this, SIGNAL(connected()), this, SIGNAL(readyToTransfer())); connect(&socket, SIGNAL(connected()), this, SIGNAL(connected())); connect(&socket, SIGNAL(readyRead()), this, SIGNAL(readyRead())); connect(&socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError))); connect(&socket, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64))); connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState))); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), serverView(0), manager(0) { ui->setupUi(this); serverView = new ChannelDisplay(ui->tabList); ui->tabList->addTab(serverView, "Server"); ui->tabList->setCurrentIndex(0); manager = new IrcManager(ui, serverView, &sock); enableConnect(); connect(&sock, SIGNAL(connected()), this, SLOT(connected())); connect(&sock,SIGNAL(disconnected()), this, SLOT(disconnected())); connect(&sock,SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); connect(&sock,SIGNAL(readyRead()),this,SLOT(readyRead())); connect(ui->sendButton,SIGNAL(clicked(bool)),this,SLOT(issueQuery())); connect(ui->connectButton,SIGNAL(clicked(bool)),this,SLOT(connectToServer())); connect(&sock,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(error(QAbstractSocket::SocketError))); connect(ui->disconnectButton,SIGNAL(clicked(bool)),this,SLOT(disconnect())); connect(ui->queryEdit, SIGNAL(returnPressed()), this, SLOT(issueQuery())); connect(ui->joinButton, SIGNAL(clicked(bool)), this, SLOT(join())); }
void QThreadTCP::connect() { isconnected = false; socket = new QTcpSocket(); QThreadTCP::QObject::connect(socket, SIGNAL(connected()),this, SLOT(connected())); QThreadTCP::QObject::connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected())); QThreadTCP::QObject::connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64))); QThreadTCP::QObject::connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead())); processclient = new QProcess(); processclient->closeReadChannel(QProcess::StandardOutput); processclient->closeReadChannel(QProcess::StandardError); connection_loop = true; //boost::thread _thread_logic(&QThreadTCP::boost_run,this); timer = new QTimer(this); QThreadTCP::QObject:: connect(timer, SIGNAL(timeout()), this, SLOT(update())); //timer->start(10000); }
//Command argument contain wether command is upload or download //if download also provide filename and if upload porvide path of file void ServerCliant::test(QString Command,QString ClassFilepath) { DownloadStrted=0; downloadFilePath ="D:/dk work/Motarola/project/teacher/"; int pos = Command.indexOf(" "); CCommand = Command.mid(0,pos).trimmed(); fileNameOrPath = Command.mid(pos + 1).trimmed(); //full path of the class or if scecific student index ClassName =ClassFilepath; socket = new QTcpSocket(this); connect(socket,SIGNAL(connected()),this,SLOT(connected())); connect(socket,SIGNAL(disconnected()),this,SLOT(disconnected())); connect(socket,SIGNAL(bytesWritten(qint64 )),this,SLOT(bytesWritten(qint64 ))); connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead())); qDebug()<<"conneting..."; socket->connectToHost("127.0.0.1",1234); if(!socket->waitForConnected(5000)) { qDebug()<<"Error:"<<socket->errorString(); } }
void TcpClient::initFromSocket(void *socket) { mQTcpSocket = reinterpret_cast<QTcpSocket *>(socket); QObject::connect(mQTcpSocket, SIGNAL(readyRead()), this, SLOT(markAsReadable())); QObject::connect(mQTcpSocket, SIGNAL(disconnected()), this, SLOT(close())); QObject::connect(mQTcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); }
void CNetworkConnection::initializeSocket() { m_pSocket->disconnect(); connect(m_pSocket, SIGNAL(connected()), this, SIGNAL(connected())); connect(m_pSocket, SIGNAL(connected()), this, SIGNAL(readyToTransfer())); connect(m_pSocket, SIGNAL(readyRead()), this, SIGNAL(readyToTransfer())); connect(m_pSocket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(m_pSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError))); connect(m_pSocket, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64))); connect(m_pSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SIGNAL(stateChanged(QAbstractSocket::SocketState))); connect(m_pSocket, SIGNAL(aboutToClose()), this, SLOT(OnAboutToClose())); connect(this, SIGNAL(connected()), this, SLOT(OnConnect()), Qt::QueuedConnection); connect(this, SIGNAL(disconnected()), this, SLOT(OnDisconnect()), Qt::QueuedConnection); connect(this, SIGNAL(readyRead()), this, SLOT(OnRead()), Qt::QueuedConnection); connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(OnError(QAbstractSocket::SocketError)), Qt::QueuedConnection); connect(this, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(OnStateChange(QAbstractSocket::SocketState)), Qt::QueuedConnection); }
void Connection::doSetup() { qDebug() << Q_FUNC_INFO << thread(); /* New connections can be created from other thread contexts, such as when AudioEngine calls getIODevice.. - we need to ensure that connections and their associated sockets are running in the same thread as the servent. HINT: export QT_FATAL_WARNINGS=1 helps to catch these kind of errors. */ if( QThread::currentThread() != m_servent->thread() ) { // Connections should always be in the same thread as the servent. qDebug() << "Fixing thead affinity..."; moveToThread( m_servent->thread() ); qDebug() << Q_FUNC_INFO << thread(); } //stats timer calculates BW used by this connection m_statstimer = new QTimer; m_statstimer->moveToThread( this->thread() ); m_statstimer->setInterval( 1000 ); connect( m_statstimer, SIGNAL( timeout() ), SLOT( calcStats() ) ); m_statstimer->start(); m_statstimer_mark.start(); m_sock->moveToThread( thread() ); connect( m_sock.data(), SIGNAL( bytesWritten( qint64 ) ), SLOT( bytesWritten( qint64 ) ), Qt::QueuedConnection ); connect( m_sock.data(), SIGNAL( disconnected() ), SLOT( socketDisconnected() ), Qt::QueuedConnection ); connect( m_sock.data(), SIGNAL( error( QAbstractSocket::SocketError ) ), SLOT( socketDisconnectedError( QAbstractSocket::SocketError ) ), Qt::QueuedConnection ); connect( m_sock.data(), SIGNAL( readyRead() ), SLOT( readyRead() ), Qt::QueuedConnection ); // if connection not authed/setup fast enough, kill it: QTimer::singleShot( AUTH_TIMEOUT, this, SLOT( authCheckTimeout() ) ); if( outbound() ) { Q_ASSERT( !m_firstmsg.isNull() ); sendMsg( m_firstmsg ); } else { sendMsg( Msg::factory( PROTOVER, Msg::SETUP ) ); } // call readyRead incase we missed the signal in between the servent disconnecting and us // connecting to the signal - won't do anything if there are no bytesAvailable anyway. readyRead(); }
void MsgStream::init(void) { socket = new QTcpSocket(this); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); QHostAddress hostAddress(peerAddress); socket->connectToHost(hostAddress, port); }
qint64 QLocalSocket::writeData(const char *data, qint64 maxSize) { Q_D(QLocalSocket); if (!d->pipeWriter) { d->pipeWriter = new QWindowsPipeWriter(d->handle, this); connect(d->pipeWriter, SIGNAL(canWrite()), this, SLOT(_q_canWrite())); connect(d->pipeWriter, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64))); d->pipeWriter->start(); } return d->pipeWriter->write(data, maxSize); }
void TcpClient::connect(const std::string &addr, int port) { close(false); mQTcpSocket->connectToHost(QString(addr.c_str()), port); if (mQTcpSocket->waitForConnected(-1) == false) throw SocketException("fail QTcpSocket::connectToHost & QTcpSocket::waitForConnected"); QObject::connect(mQTcpSocket, SIGNAL(readyRead()), this, SLOT(markAsReadable())); QObject::connect(mQTcpSocket, SIGNAL(disconnected()), this, SLOT(close())); QObject::connect(mQTcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); }
childProcess_t::childProcess_t (process_t * parent) : QProcess(parent) { QObject::connect(this, SIGNAL(error (QProcess::ProcessError)), this, SLOT(error (QProcess::ProcessError))); QObject::connect(this, SIGNAL(finished (int, QProcess::ExitStatus)), this, SLOT(finished (int, QProcess::ExitStatus))); QObject::connect(this, SIGNAL(readyReadStandardError(void)), this, SLOT(readyReadStandardError(void))); QObject::connect(this, SIGNAL(readyReadStandardOutput(void)), this, SLOT(readyReadStandardOutput(void))); QObject::connect(this, SIGNAL(started (void)), this, SLOT(started (void))); QObject::connect(this, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(stateChanged(QProcess::ProcessState))); QObject::connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); }
void TCPClient::declareAndConnectSockets() { //Declare TCP and UDP sockets: if (tcpSocket) delete tcpSocket; if (udpSocket) delete udpSocket; tcpSocket = new QTcpSocket(); udpSocket = new QUdpSocket(); connect (tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()), Qt::QueuedConnection); connect (tcpSocket, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::QueuedConnection); connect (tcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)), Qt::QueuedConnection); }
IpsEngineClient::~IpsEngineClient() { if(socket) { disconnect(socket, SIGNAL(connected()),this, SLOT(connected())); disconnect(socket, SIGNAL(disconnected()),this, SLOT(disconnected())); disconnect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64))); disconnect(socket, SIGNAL(readyRead()),this, SLOT(readyRead())); disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); delete socket; } }
// the playScreen is the screen for the single player game. // it takes in the file path to the image the user wants to use // and cuts it up into tiles and displays them on the screen with various // menu buttons and statistics. It also handles tile clicks and tile swapping. PlayScreen::PlayScreen(QString imgPath, MainWindow *mainWindow, QWidget *parent) : QWidget(parent) { this->imgPath = imgPath; this->mainWindow = mainWindow; socket = new QTcpSocket(this); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); }
/*! \internal */ void QBluetoothHeadsetService::hookupSocket(QBluetoothRfcommSocket *socket) { m_data->m_client = socket; QObject::connect(m_data->m_client, SIGNAL(stateChanged(QBluetoothAbstractSocket::SocketState)), this, SLOT(stateChanged(QBluetoothAbstractSocket::SocketState))); QObject::connect(m_data->m_client, SIGNAL(error(QBluetoothAbstractSocket::SocketError)), this, SLOT(error(QBluetoothAbstractSocket::SocketError))); QObject::connect(m_data->m_client, SIGNAL(readyRead()), this, SLOT(readyRead())); QObject::connect(m_data->m_client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); }
void readyToRead() { bool gotPackets = false; while (true) { // Get size header (if not in progress) if (-1 == inProgressSize) { // We need a size header of sizeof(qint32) if (sizeof(qint32) > (uint)dev->bytesAvailable()) { if (gotPackets) emit readyRead(); return; // no more data available } // Read size header int read = dev->read((char *)&inProgressSize, sizeof(qint32)); Q_ASSERT(read == sizeof(qint32)); Q_UNUSED(read); // Check sizing constraints if (inProgressSize > maxPacketSize) { QObject::disconnect(dev, SIGNAL(readyRead()), this, SLOT(readyToRead())); QObject::disconnect(dev, SIGNAL(aboutToClose()), this, SLOT(aboutToClose())); QObject::disconnect(dev, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); dev = 0; emit invalidPacket(); return; } inProgressSize -= sizeof(qint32); } else { inProgress.append(dev->read(inProgressSize - inProgress.size())); if (inProgressSize == inProgress.size()) { // Packet has arrived! packets.append(inProgress); inProgressSize = -1; inProgress.clear(); waitingForPacket = false; gotPackets = true; } else { if (gotPackets) emit readyRead(); return; // packet in progress is not yet complete } } } }
/** Set the device used by the JsonStream. The stream does not take ownership of the device. */ void JsonStream::setDevice(QIODevice *device, bool queued) { if (mDevice) { disconnect(mDevice, SIGNAL(readyRead()), this, SLOT(deviceReadyRead())); disconnect(mDevice, SIGNAL(bytesWritten(qint64)), this, SLOT(deviceBytesWritten(qint64))); disconnect(mDevice, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose())); } mDevice = device; if (mDevice) { connect(mDevice, SIGNAL(readyRead()), this, SLOT(deviceReadyRead()), queued ? Qt::QueuedConnection : Qt::DirectConnection); connect(mDevice, SIGNAL(bytesWritten(qint64)), this, SLOT(deviceBytesWritten(qint64))); connect(mDevice, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose())); } }
// Send treatment plan void Server::sendPlan() { QHostAddress ipAddress("172.168.0.116"); m_tcpServer->connectToHost(ipAddress, 6666); QDataStream m_sendOut(&m_outBlock, QIODevice::WriteOnly); m_sendOut.setVersion(QDataStream::Qt_4_6); qDebug() << "Sending plan..."; QString sendInfo = writeSendInfo(); // Write data connect(m_tcpServer, SIGNAL(bytesWritten(qint64)), this, SLOT(writtenBytes(qint64))); // Check if the data has been all well written m_sendOut << qint64(0) << qint64(0) << m_plan.coordinate.spotNum << m_plan.coordinate.spotPosX << m_plan.coordinate.spotPosY << m_plan.coordinate.spotPosZ << m_plan.parameter.coolingTime << m_plan.parameter.dutyCycle << m_plan.parameter.sonicationPeriod << m_plan.parameter.sonicationTime << sendInfo; qDebug() << "sendInfo:" << sendInfo; m_totalBytes = m_outBlock.size(); qDebug() << "m_totalBytes:" << m_totalBytes; m_sendOut.device()->seek(0); m_sendOut << qint64(2) << m_totalBytes; // Find the head of array and write the haed information m_tcpServer->write(m_outBlock); m_sendTimeNum += 1; m_writtenBytes = 0; m_outBlock.resize(0); qDebug() << "Send finished"; // Read send-back data connect(m_tcpServer, SIGNAL(readyRead()), this, SLOT(readSendBack())); m_tcpServer->waitForReadyRead(3000); qDebug() << m_receivedInfo; // Check the consistency of the send-back data if(m_receivedInfo == sendInfo) { qDebug() << "Send-back checked."; m_receivedInfo = ""; } else { emit error_sendBackCheck(); qDebug() << "Check failed ! emit error signal..."; } }
QHttpConnection::QHttpConnection(QTcpSocket *socket, QObject *parent) : QObject(parent), m_socket(socket), m_parser(0), m_parserSettings(0), m_request(0), m_transmitLen(0), m_transmitPos(0) { m_parser = (http_parser *)malloc(sizeof(http_parser)); http_parser_init(m_parser, HTTP_REQUEST); m_parserSettings = new http_parser_settings(); m_parserSettings->on_message_begin = MessageBegin; m_parserSettings->on_url = Url; m_parserSettings->on_header_field = HeaderField; m_parserSettings->on_header_value = HeaderValue; m_parserSettings->on_headers_complete = HeadersComplete; m_parserSettings->on_body = Body; m_parserSettings->on_message_complete = MessageComplete; m_parser->data = this; connect(socket, SIGNAL(readyRead()), this, SLOT(parseRequest())); connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(updateWriteCount(qint64))); }
void Connection::shutdown( bool waitUntilSentAll ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << waitUntilSentAll << id(); if ( d_func()->do_shutdown ) { //qDebug() << id() << " already shutting down"; return; } d_func()->do_shutdown = true; if ( !waitUntilSentAll ) { // qDebug() << "Shutting down immediately " << id(); actualShutdown(); } else { tDebug( LOGVERBOSE ) << "Shutting down after transfer complete " << id() << "Actual/Desired" << d_func()->tx_bytes << d_func()->tx_bytes_requested; bytesWritten( 0 ); // trigger shutdown if we've already sent everything // otherwise the bytesWritten slot will call actualShutdown() // once all enqueued data has been properly written to the socket } }
AaServerWindowApp::AaServerWindowApp(QWidget *parent) : QMainWindow(parent), ui(new Ui::AaServerWindowApp) { localSize = 2048; totalBytesRecevice = 0; bytesRecevice = 0; bytesToWriteSend = 0; bytesWrittenSend = 0; fileNameSize = 0; ui->setupUi(this); ui->m_txtOutput->setReadOnly(true); setFocusPolicy(Qt::ClickFocus); ui->menuBar->hide(); ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Send")); ui->buttonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::ALT+Qt::Key_S); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Close")); setWindowTitle(tr("Server")); init(); //connect connect(m_pServerServer,SIGNAL(newConnection()),this,SLOT(acceptConnection())); connect(ui->buttonBox,SIGNAL(clicked(QAbstractButton*)),this,SLOT(slotBtnClicked(QAbstractButton*))); connect(ui->actionSend_File,SIGNAL(triggered()),this,SLOT(slotSendFile())); connect(m_pServerSocket,SIGNAL(bytesWritten(qint64)),this,SLOT(slotContinueSendFile(qint64))); }
bool QHttpSocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol) { Q_D(QHttpSocketEngine); if (type != QAbstractSocket::TcpSocket) return false; setProtocol(protocol); setSocketType(type); d->socket = new QTcpSocket(this); // Explicitly disable proxying on the proxy socket itself to avoid // unwanted recursion. QNetworkProxy proxy; proxy.setType(QNetworkProxy::NoProxy); d->socket->setProxy(proxy); // Intercept all the signals. connect(d->socket, SIGNAL(connected()), this, SLOT(slotSocketConnected())); connect(d->socket, SIGNAL(disconnected()), this, SLOT(slotSocketDisconnected())); connect(d->socket, SIGNAL(readyRead()), this, SLOT(slotSocketReadNotification())); connect(d->socket, SIGNAL(readyRead()), this, SLOT(slotSocketReadNotification())); connect(d->socket, SIGNAL(bytesWritten(qint64)), this, SLOT(slotSocketBytesWritten())); connect(d->socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError))); connect(d->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(slotSocketStateChanged(QAbstractSocket::SocketState))); return true; }
void FfmpegExporter::bytesWritten(qint64 bytes) { const qint64 bufsize = _writebuffer.size(); _written += bytes; _chunk -= bytes; Q_ASSERT(_written <= bufsize); Q_ASSERT(_chunk >= 0); //qDebug() << "wrote" << bytes << "bytes:" << _written << "of" << bufsize << QString("(%1%)").arg(_written/qreal(bufsize)*100, 0, 'f', 1); if(_written == bufsize) { --_repeats; if(_repeats<=0) { _writebuffer.clear(); emit exporterReady(); } else { _written = 0; _chunk = 0; bytesWritten(0); } } else if(_written < bufsize && _chunk==0) { _chunk = qMin(bufsize - _written, qint64(1024 * 1024)); _encoder->write(_writebuffer.constData() + _written, _chunk); } }
void ConnectorInterface::SendExistingPackets() { behaviac::LinkedObjectPool<Packet>::Iterator it = this->m_packetPool->Begin(); int packetsCount = 0; while (!it.Empty()) { Packet* p = (*it); const size_t bytesToSend = p->PrepareToSend(); size_t bytesWritten(0); behaviac::Socket::Write(m_writeSocket, p, bytesToSend, bytesWritten); packetsCount++; //this->m_packetPool->Free(p); ++it; } //wait for the finish behaviac::Thread::Sleep(1000); int packetsCount2 = 0; it = this->m_packetPool->Begin(); while (!it.Empty()) { Packet* p = (*it); ++it; packetsCount2++; this->m_packetPool->Free(p); } //this->m_packetPool->Destroy(true); }
StarterSocketWrapper::StarterSocketWrapper(TransferStarter& parent) : m_parent(parent) { connect(&m_socket, SIGNAL(connected()), this, SLOT(new_transfer_connection())); connect(&m_socket, SIGNAL(bytesWritten(qint64)), SLOT(transfer_bytes_written(qint64))); connect(&m_socket, SIGNAL(readyRead()), SLOT(transfer_ready_read())); connect(&m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socket_error(QAbstractSocket::SocketError))); if (parent.m_request.m_size == -1) m_unpack_after_transfer = true; else m_unpack_after_transfer = false; m_chunker = std::make_unique<Chunker>(RECEIVER, m_unpack_after_transfer ? parent.m_request.m_packed_size : parent.m_request.m_size); if (!m_chunker || !m_chunker->open(parent.m_local_file)) { qDebug() << "[StarterSocketWrapper] Could not open '" << parent.m_local_file << "' aborting"; m_parent.exit(1); return; } connect(this, SIGNAL(update_percentage(int)), &m_parent, SLOT(update_percentage_slot(int))); connect(this, SIGNAL(file_received()), &m_parent, SLOT(file_received_slot())); m_socket.connectToHost(parent.m_request.m_sender_address, parent.m_request.m_sender_transfer_port); }
bool InBandStream::sendNextPaket(bool AFlush) { bool sent = false; if (isOpen() && FDataIqRequestId.isEmpty() && (bytesToWrite()>=FBlockSize || AFlush)) { FThreadLock.lockForWrite(); QByteArray data = FWriteBuffer.read(FBlockSize); FThreadLock.unlock(); if (!data.isEmpty()) { if (FStanzaProcessor) { Stanza paket(FStanzaType==StanzaMessage ? STANZA_KIND_MESSAGE : STANZA_KIND_IQ); paket.setTo(FContactJid.full()).setUniqueId(); QDomElement dataElem = paket.addElement("data",NS_INBAND_BYTESTREAMS); dataElem.setAttribute("sid",FStreamId); dataElem.setAttribute("seq",FSeqOut); dataElem.appendChild(paket.createTextNode(QString::fromUtf8(data.toBase64()))); if (FStanzaType == StanzaMessage) { QDomElement ampElem = paket.addElement("amp","http://jabber.org/protocol/amp"); QDomElement ruleElem = ampElem.appendChild(paket.createElement("rule")).toElement(); ruleElem.setAttribute("condition","deliver"); ruleElem.setAttribute("value","stored"); ruleElem.setAttribute("action","error"); ruleElem = ampElem.appendChild(paket.createElement("rule")).toElement(); ruleElem.setAttribute("condition","match-resource"); ruleElem.setAttribute("value","exact"); ruleElem.setAttribute("action","error"); DataEvent *dataEvent = new DataEvent(AFlush); QCoreApplication::postEvent(this, dataEvent); sent = FStanzaProcessor->sendStanzaOut(FStreamJid,paket); } else { paket.setType(STANZA_TYPE_SET); FDataIqRequestId = paket.id(); sent = FStanzaProcessor->sendStanzaRequest(this,FStreamJid,paket,DATA_TIMEOUT); } } if (sent) { FSeqOut = FSeqOut<USHRT_MAX ? FSeqOut+1 : 0; emit bytesWritten(data.size()); FBytesWrittenCondition.wakeAll(); } else { abort(XmppError(IERR_INBAND_STREAM_DATA_NOT_SENT)); } } } return sent; }
int myclianttest::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: readyRead(); break; case 1: bytesWritten((*reinterpret_cast< qint64(*)>(_a[1]))); break; case 2: disconnected(); break; case 3: list((*reinterpret_cast< QString(*)>(_a[1]))); break; case 4: connected(); break; case 5: test(); break; case 6: mycomputer((*reinterpret_cast< QString(*)>(_a[1]))); break; case 7: doubleClicked((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; case 8: doubleClickedServer((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; case 9: setpath((*reinterpret_cast< QString(*)>(_a[1]))); break; case 10: getpath(); break; case 11: servercomputer((*reinterpret_cast< QByteArray(*)>(_a[1]))); break; case 12: serverfiledown((*reinterpret_cast< QByteArray(*)>(_a[1]))); break; case 13: getserverpath(); break; case 14: download(); break; case 15: Serverclicked((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; case 16: gotomotherpath(); break; case 17: gotoservermotherpath(); break; default: ; } _id -= 18; } return _id; }
void ConnectorInterface::SendAllPackets() { for (int i = 0; i < m_maxTracedThreads; ++i) { if (m_packetBuffers[i] && !m_packetBuffers[i]->m_free) { #if USING_BEHAVIAC_SEQUENTIAL if (!m_packetBuffers[i]->CollectPackets(*m_packetCollection)) { break; } #else m_packetBuffers[i].SendPackets(m_writeSocket); #endif } } #if USING_BEHAVIAC_SEQUENTIAL // TODO: Deal with Socket::Write failures. // (right now packet is lost). m_packetCollection->Sort(); for (Packet* p = m_packetCollection->Begin(); p != m_packetCollection->End() && this->m_writeSocket; ++p) { const size_t bytesToSend = p->PrepareToSend(); size_t bytesWritten(0); behaviac::Socket::Write(m_writeSocket, p, bytesToSend, bytesWritten); } m_packetCollection->Reset(); #endif this->m_packetsCount = 0; }