/****************************************************************************
**
** Copyright (C) 1992-2004 Trolltech AS. All rights reserved.
**
** This file is part of the compatibility classes of the Qt Toolkit.
**
** Licensees holding valid Qt Preview licenses may use this file in
** accordance with the Qt Preview License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef QSOCKETDEVICE_P_H
#define QSOCKETDEVICE_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists for the convenience
// of QSocketDevice. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
//

#include "qglobal.h"
#include "qstring.h"
#include "qobjectdefs.h"
#include "private/qiodevice_p.h"

class QSocketDevicePrivate : public QIODevicePrivate
{
    Q_DECLARE_PUBLIC(QSocketDevice)

protected:
    friend class QSocketDeviceEngine;
    QSocketDevicePrivate()
        : fd(-1), t(QSocketDevice::Stream), p(0), pp(0), e(QSocketDevice::NoError),
          protocol(QSocketDevice::IPv4), socketEngine(0) {}
    ~QSocketDevicePrivate();

private:
    enum Option {
#if 0
        // not used anywhere
        Broadcast,
#endif
        ReceiveBuffer,
        ReuseAddress,
        SendBuffer
    };

    int option(Option) const;
    void setOption(Option, int);
    void fetchConnectionParameters() const;
#if defined(Q_OS_WIN32)
    void fetchPeerConnectionParameters() const;
#endif

    int createNewSocket();
    QSocketDevice::Protocol getProtocol() const;

    // the mutable variables are computed lazily
    int fd;
    QSocketDevice::Type t;
    mutable Q_UINT16 p;
    mutable QHostAddress a;
    mutable Q_UINT16 pp;
    mutable QHostAddress pa;
    mutable QSocketDevice::Error e;
    mutable QSocketDevice::Protocol protocol;

    static void init();

    mutable QSocketDeviceEngine *socketEngine;
};

#if !defined(Q_OS_WIN32)
inline void QSocketDevicePrivate::init() {}
#endif

#endif
