Exemple #1
0
void QSocketPrivate::setSocketDevice( QSocket *q, QSocketDevice *device )
{
    delete socket;
    delete rsn;
    delete wsn;

    if ( device ) {
	socket = device;
    } else {
	socket = new QSocketDevice( QSocketDevice::Stream,
				    ( addr.isIPv4Address() ?
				      QSocketDevice::IPv4 :
				      QSocketDevice::IPv6 ), 0 );
	socket->setBlocking( FALSE );
	socket->setAddressReusable( TRUE );
    }

    rsn = new QSocketNotifier( socket->socket(),
			       QSocketNotifier::Read, q, "read" );
    wsn = new QSocketNotifier( socket->socket(),
			       QSocketNotifier::Write, q, "write" );

    QObject::connect( rsn, SIGNAL(activated(int)), q, SLOT(sn_read()) );
    rsn->setEnabled( FALSE );
    QObject::connect( wsn, SIGNAL(activated(int)), q, SLOT(sn_write()) );
    wsn->setEnabled( FALSE );
}
Exemple #2
0
void QSocket::setSocketIntern( int socket )
{
    if ( state() != Idle ) {
	clearPendingData();
        close();
    }
    Q_ULONG oldBufferSize = d ? d->readBufferSize : 0;
    delete d;

    d = new QSocketPrivate;
    if (oldBufferSize)
        d->readBufferSize = oldBufferSize;
    if ( socket >= 0 ) {
	QSocketDevice *sd = new QSocketDevice( socket, QSocketDevice::Stream );
	sd->setBlocking( FALSE );
	sd->setAddressReusable( TRUE );
	d->setSocketDevice( this, sd );
    }
    d->state = Idle;

    // Initialize the IO device flags
    setFlags( IO_Direct );
    resetStatus();
    open( IO_ReadWrite );

    // hm... this is not very nice.
    d->host = QString::null;
    d->port = 0;
#ifndef QT_NO_DNS
    delete d->dns4;
    d->dns4 = 0;
    delete d->dns6;
    d->dns6 = 0;
#endif
}