27 #include <tqsocketnotifier.h>
28 #include <tqdatetime.h>
30 #include <tqguardedptr.h>
32 #include "ksocketaddress.h"
33 #include "kresolver.h"
34 #include "ksocketdevice.h"
35 #include "kstreamsocket.h"
37 using namespace KNetwork;
39 class KNetwork::KStreamSocketPrivate
42 KResolverResults::ConstIterator local, peer;
48 inline KStreamSocketPrivate()
54 TQObject* parent,
const char *name)
80 if (
state() != Connecting)
85 return timeout() - d->startTime.elapsed();
92 if (
state() == Connecting)
93 d->timer.changeInterval(msecs);
103 if (!service.isNull())
110 if (
state() == Connected)
113 if (
state() > Connected)
118 if (!service.isNull())
123 setError(IO_ConnectError, InProgress);
128 if (
state() < HostFound)
148 if (!
blocking() && !d->timer.isActive())
149 d->timer.start(
timeout(),
true);
162 if (
state() < Connecting)
164 if (
state() == Connected)
189 return error() == NoError;
197 void KStreamSocket::hostFoundSlot()
201 d->timer.start(
timeout(),
true);
202 TQTimer::singleShot(0,
this, TQT_SLOT(connectionEvent()));
205 void KStreamSocket::connectionEvent()
207 if (
state() != HostFound &&
state() != Connecting)
211 if (
state() == HostFound)
213 d->startTime.start();
217 d->peer = peer.begin();
221 while (d->peer != peer.end())
232 connectionSucceeded(r);
247 if (!bindLocallyFor(r))
271 this, TQT_SLOT(connectionEvent()));
276 this, TQT_SLOT(connectionEvent()));
283 connectionSucceeded(r);
302 void KStreamSocket::timeoutSlot()
304 if (
state() != Connecting)
314 TQGuardedPtr<KStreamSocket> that =
this;
328 bool foundone =
false;
330 for (d->local = local.begin(); d->local != local.end(); ++d->local)
331 if ((*d->local).family() == peer.
family())
343 setError(IO_BindError, NotSupported);
351 void KStreamSocket::connectionSucceeded(
const KResolverEntry& peer)
357 setFlags(IO_Sequential | IO_Raw | IO_ReadWrite | IO_Open | IO_Async);
364 emit
bound(*d->local);
368 #include "kstreamsocket.moc"