New KIO::Connection
Ralf Habacker
ralf.habacker at freenet.de
Wed Jul 11 09:30:40 BST 2007
Thiago Macieira schrieb:
> I'd like to apply a patch very similar to the one attached to kdelibs in a
> week's time (i.e., not tomorrow). I am still testing a couple of things
> and some bugs may show up.
>
To get this stuff initial running on win32 I added a an experimental tcp
backend (see appended patch) and got kio_file with kioslavetest and kate
running. It uses an url form of tcp://<host>:<port> to make the
Connection class able to select the correct backend.
It is quite easy to add additional QTcpSocket/QTcpServer based backends
to this new design. Great work ;-)
One problem i had with the code below (commented part), which raises
the Q_ASSERT(socket->bytesAvailable() == 1) all the time. Commenting
out let kio_file works
void TCPSocketConnectionBackend::socketReadyRead()
{
if (!socket)
// might happen if the invokeMethods were delivered after we
disconnected
return;
//kDebug() << k_funcinfo << "Got " << socket->bytesAvailable() << "
bytes" << endl;
if (len == -1) {
// We have to read the header
static char buffer[10];
if (socket->bytesAvailable() < sizeof buffer) {
/*
if (socket->readBufferSize() == 0) {
// we were suspended and there's still data in the buffer
// so we have to read it before QtNetwork decides to
send more data
Q_ASSERT(socket->bytesAvailable() == 1);
char c;
Q_ASSERT(socket->getChar(&c));
socket->ungetChar(c);
}
*/
return; // wait for more data
}
Another issue I had with connectToRemote(). In the method the connection
state is set unconditional, although there may be errors returning from
connectToHost. I had added a workaround, there may be better solutions
for this.
bool TCPSocketConnectionBackend::connectToRemote(const KUrl &url)
{
Q_ASSERT(state == Idle);
Q_ASSERT(!socket);
Q_ASSERT(!server);
socket = KSocketFactory::connectToHost(url,this);
qDebug() << k_funcinfo << socket->state();
if (!socket->waitForConnected(1000)) {
state = Idle;
qDebug() << k_funcinfo << "could not connect to " << url;
return false;
}
connect(socket, SIGNAL(readyRead()), SLOT(socketReadyRead()));
connect(socket, SIGNAL(disconnected()), SIGNAL(disconnected()));
state = Connected;
qDebug() << k_funcinfo << "connected to " << url;
return true;
}
Another point I recognized is in the method below where inited() was
used to detect slave connection state, I think isConnected() would be
better, but I may be wrong.
void SlaveBase::connectSlave(const QString &address)
{
appconn->connectToRemote(address);
//if (!appconn->inited())
if (!appconn->isConnected())
{
kDebug(7019) << "SlaveBase: failed to connect to " << address <<
endl
<< "Reason: " << appconn->errorString() << endl;
exit();
return;
}
setConnection(appconn);
}
Ralf
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: kio-new-connection-tcp.diff
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070711/1fed10d3/attachment.ksh>
More information about the kde-core-devel
mailing list