Qt 4.8
Public Types | Public Slots | Public Functions | Private Slots | Private Functions | List of all members
QHttpSocketEngine Class Reference

#include <qhttpsocketengine_p.h>

Inheritance diagram for QHttpSocketEngine:
QAbstractSocketEngine QObject

Public Types

enum  HttpState {
  None, ConnectSent, Connected, SendAuthentication,
  ReadResponseContent
}
 
- Public Types inherited from QAbstractSocketEngine
enum  SocketOption {
  NonBlockingSocketOption, BroadcastSocketOption, ReceiveBufferSocketOption, SendBufferSocketOption,
  AddressReusable, BindExclusively, ReceiveOutOfBandData, LowDelayOption,
  KeepAliveOption, MulticastTtlOption, MulticastLoopbackOption
}
 

Public Slots

void slotSocketBytesWritten ()
 
void slotSocketConnected ()
 
void slotSocketDisconnected ()
 
void slotSocketError (QAbstractSocket::SocketError error)
 
void slotSocketReadNotification ()
 
void slotSocketStateChanged (QAbstractSocket::SocketState state)
 
- Public Slots inherited from QAbstractSocketEngine
void connectionNotification ()
 
void exceptionNotification ()
 
void proxyAuthenticationRequired (const QNetworkProxy &proxy, QAuthenticator *authenticator)
 
void readNotification ()
 
void writeNotification ()
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

int accept ()
 
bool bind (const QHostAddress &address, quint16 port)
 
qint64 bytesAvailable () const
 
qint64 bytesToWrite () const
 
void close ()
 
bool connectInternal ()
 
bool connectToHost (const QHostAddress &address, quint16 port)
 
bool connectToHostByName (const QString &name, quint16 port)
 
bool hasPendingDatagrams () const
 
bool initialize (QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)
 
bool initialize (int socketDescriptor, QAbstractSocket::SocketState socketState=QAbstractSocket::ConnectedState)
 
bool isExceptionNotificationEnabled () const
 
bool isReadNotificationEnabled () const
 
bool isValid () const
 
bool isWriteNotificationEnabled () const
 
bool joinMulticastGroup (const QHostAddress &groupAddress, const QNetworkInterface &interface)
 
bool leaveMulticastGroup (const QHostAddress &groupAddress, const QNetworkInterface &interface)
 
bool listen ()
 
QNetworkInterface multicastInterface () const
 
int option (SocketOption option) const
 
qint64 pendingDatagramSize () const
 
 QHttpSocketEngine (QObject *parent=0)
 
qint64 read (char *data, qint64 maxlen)
 
qint64 readDatagram (char *data, qint64 maxlen, QHostAddress *addr=0, quint16 *port=0)
 
void setExceptionNotificationEnabled (bool enable)
 
bool setMulticastInterface (const QNetworkInterface &iface)
 
bool setOption (SocketOption option, int value)
 
void setProxy (const QNetworkProxy &networkProxy)
 
void setReadNotificationEnabled (bool enable)
 
void setWriteNotificationEnabled (bool enable)
 
int socketDescriptor () const
 
bool waitForRead (int msecs=30000, bool *timedOut=0)
 
bool waitForReadOrWrite (bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=0)
 
bool waitForWrite (int msecs=30000, bool *timedOut=0)
 
qint64 write (const char *data, qint64 len)
 
qint64 writeDatagram (const char *data, qint64 len, const QHostAddress &addr, quint16 port)
 
 ~QHttpSocketEngine ()
 
- Public Functions inherited from QAbstractSocketEngine
QAbstractSocket::SocketError error () const
 
QString errorString () const
 
QHostAddress localAddress () const
 
quint16 localPort () const
 
QHostAddress peerAddress () const
 
quint16 peerPort () const
 
QAbstractSocket::NetworkLayerProtocol protocol () const
 
 QAbstractSocketEngine (QObject *parent=0)
 
void setReceiver (QAbstractSocketEngineReceiver *receiver)
 
QAbstractSocket::SocketType socketType () const
 
QAbstractSocket::SocketState state () const
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Slots

void emitPendingConnectionNotification ()
 
void emitPendingReadNotification ()
 
void emitPendingWriteNotification ()
 

Private Functions

void emitConnectionNotification ()
 
void emitReadNotification ()
 
void emitWriteNotification ()
 

Additional Inherited Members

- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QAbstractSocketEngine
static QAbstractSocketEnginecreateSocketEngine (QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent)
 
static QAbstractSocketEnginecreateSocketEngine (int socketDescripter, QObject *parent)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QAbstractSocketEngine
 QAbstractSocketEngine (QAbstractSocketEnginePrivate &dd, QObject *parent=0)
 
void setError (QAbstractSocket::SocketError error, const QString &errorString) const
 
void setLocalAddress (const QHostAddress &address)
 
void setLocalPort (quint16 port)
 
void setPeerAddress (const QHostAddress &address)
 
void setPeerPort (quint16 port)
 
void setProtocol (QAbstractSocket::NetworkLayerProtocol protocol)
 
void setSocketType (QAbstractSocket::SocketType socketType)
 
void setState (QAbstractSocket::SocketState state)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 68 of file qhttpsocketengine_p.h.

Enumerations

◆ HttpState

Constructors and Destructors

◆ QHttpSocketEngine()

QHttpSocketEngine::QHttpSocketEngine ( QObject parent = 0)

Definition at line 57 of file qhttpsocketengine.cpp.

◆ ~QHttpSocketEngine()

QHttpSocketEngine::~QHttpSocketEngine ( )

Definition at line 62 of file qhttpsocketengine.cpp.

63 {
64 }

Functions

◆ accept()

int QHttpSocketEngine::accept ( )
virtual

Implements QAbstractSocketEngine.

Definition at line 199 of file qhttpsocketengine.cpp.

200 {
201  return 0;
202 }

◆ bind()

bool QHttpSocketEngine::bind ( const QHostAddress address,
quint16  port 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 189 of file qhttpsocketengine.cpp.

190 {
191  return false;
192 }

◆ bytesAvailable()

qint64 QHttpSocketEngine::bytesAvailable ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 214 of file qhttpsocketengine.cpp.

Referenced by connectInternal(), and setReadNotificationEnabled().

215 {
216  Q_D(const QHttpSocketEngine);
217  return d->readBuffer.size() + (d->socket ? d->socket->bytesAvailable() : 0);
218 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ bytesToWrite()

qint64 QHttpSocketEngine::bytesToWrite ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 303 of file qhttpsocketengine.cpp.

304 {
305  Q_D(const QHttpSocketEngine);
306  if (d->socket) {
307  return d->socket->bytesToWrite();
308  } else {
309  return 0;
310  }
311 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ close()

void QHttpSocketEngine::close ( )
virtual

Implements QAbstractSocketEngine.

Definition at line 204 of file qhttpsocketengine.cpp.

Referenced by read().

205 {
207  if (d->socket) {
208  d->socket->close();
209  delete d->socket;
210  d->socket = 0;
211  }
212 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ connectInternal()

bool QHttpSocketEngine::connectInternal ( )

Definition at line 135 of file qhttpsocketengine.cpp.

Referenced by connectToHost(), and connectToHostByName().

136 {
138 
139  d->credentialsSent = false;
140 
141  // If the handshake is done, enter ConnectedState state and return true.
142  if (d->state == Connected) {
143  qWarning("QHttpSocketEngine::connectToHost: called when already connected");
145  return true;
146  }
147 
148  if (d->state == ConnectSent && d->socketState != QAbstractSocket::ConnectedState)
150 
151  // Handshake isn't done. If unconnected, start connecting.
152  if (d->state == None && d->socket->state() == QAbstractSocket::UnconnectedState) {
154  //limit buffer in internal socket, data is buffered in the external socket under application control
155  d->socket->setReadBufferSize(65536);
156  d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
157  }
158 
159  // If connected (might happen right away, at least for localhost services
160  // on some BSD systems), there might already be bytes available.
161  if (bytesAvailable())
163 
164  return d->socketState == QAbstractSocket::ConnectedState;
165 }
double d
Definition: qnumeric_p.h:62
void setState(QAbstractSocket::SocketState state)
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
qint64 bytesAvailable() const

◆ connectToHost()

bool QHttpSocketEngine::connectToHost ( const QHostAddress address,
quint16  port 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 167 of file qhttpsocketengine.cpp.

168 {
170 
171  setPeerAddress(address);
172  setPeerPort(port);
173  d->peerName.clear();
174 
175  return connectInternal();
176 }
double d
Definition: qnumeric_p.h:62
void setPeerAddress(const QHostAddress &address)
#define Q_D(Class)
Definition: qglobal.h:2482
void setPeerPort(quint16 port)

◆ connectToHostByName()

bool QHttpSocketEngine::connectToHostByName ( const QString name,
quint16  port 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 178 of file qhttpsocketengine.cpp.

179 {
181 
183  setPeerPort(port);
184  d->peerName = hostname;
185 
186  return connectInternal();
187 }
double d
Definition: qnumeric_p.h:62
void setPeerAddress(const QHostAddress &address)
#define Q_D(Class)
Definition: qglobal.h:2482
void setPeerPort(quint16 port)
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70

◆ emitConnectionNotification()

void QHttpSocketEngine::emitConnectionNotification ( )
private

Definition at line 795 of file qhttpsocketengine.cpp.

Referenced by slotSocketError(), and slotSocketReadNotification().

796 {
798  if (!d->connectionNotificationPending) {
799  d->connectionNotificationPending = true;
800  QMetaObject::invokeMethod(this, "emitPendingConnectionNotification", Qt::QueuedConnection);
801  }
802 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ emitPendingConnectionNotification

void QHttpSocketEngine::emitPendingConnectionNotification ( )
privateslot

Definition at line 765 of file qhttpsocketengine.cpp.

766 {
768  d->connectionNotificationPending = false;
770 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76

◆ emitPendingReadNotification

void QHttpSocketEngine::emitPendingReadNotification ( )
privateslot

Definition at line 749 of file qhttpsocketengine.cpp.

750 {
752  d->readNotificationPending = false;
753  if (d->readNotificationEnabled)
755 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76

◆ emitPendingWriteNotification

void QHttpSocketEngine::emitPendingWriteNotification ( )
privateslot

Definition at line 757 of file qhttpsocketengine.cpp.

758 {
760  d->writeNotificationPending = false;
761  if (d->writeNotificationEnabled)
763 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76

◆ emitReadNotification()

void QHttpSocketEngine::emitReadNotification ( )
private

Definition at line 772 of file qhttpsocketengine.cpp.

Referenced by read(), slotSocketError(), and slotSocketReadNotification().

773 {
775  d->readNotificationActivated = true;
776  // if there is a connection notification pending we have to emit the readNotification
777  // incase there is connection error. This is only needed for Windows, but it does not
778  // hurt in other cases.
779  if ((d->readNotificationEnabled && !d->readNotificationPending) || d->connectionNotificationPending) {
780  d->readNotificationPending = true;
781  QMetaObject::invokeMethod(this, "emitPendingReadNotification", Qt::QueuedConnection);
782  }
783 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ emitWriteNotification()

void QHttpSocketEngine::emitWriteNotification ( )
private

Definition at line 785 of file qhttpsocketengine.cpp.

Referenced by slotSocketBytesWritten(), and slotSocketReadNotification().

786 {
788  d->writeNotificationActivated = true;
789  if (d->writeNotificationEnabled && !d->writeNotificationPending) {
790  d->writeNotificationPending = true;
791  QMetaObject::invokeMethod(this, "emitPendingWriteNotification", Qt::QueuedConnection);
792  }
793 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ hasPendingDatagrams()

bool QHttpSocketEngine::hasPendingDatagrams ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 292 of file qhttpsocketengine.cpp.

293 {
294  return false;
295 }

◆ initialize() [1/2]

bool QHttpSocketEngine::initialize ( QAbstractSocket::SocketType  type,
QAbstractSocket::NetworkLayerProtocol  protocol = QAbstractSocket::IPv4Protocol 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 66 of file qhttpsocketengine.cpp.

67 {
70  return false;
71 
74  d->socket = new QTcpSocket(this);
75 #ifndef QT_NO_BEARERMANAGEMENT
76  d->socket->setProperty("_q_networkSession", property("_q_networkSession"));
77 #endif
78 
79  // Explicitly disable proxying on the proxy socket itself to avoid
80  // unwanted recursion.
81  d->socket->setProxy(QNetworkProxy::NoProxy);
82 
83  // Intercept all the signals.
84  connect(d->socket, SIGNAL(connected()),
85  this, SLOT(slotSocketConnected()),
87  connect(d->socket, SIGNAL(disconnected()),
90  connect(d->socket, SIGNAL(readyRead()),
93  connect(d->socket, SIGNAL(bytesWritten(qint64)),
99  connect(d->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
102 
103  return true;
104 }
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol)
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
SocketState
This enum describes the different states in which a socket can be.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QIntfbScreen * connected
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
SocketError
This enum describes the socket errors that can occur.
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
void slotSocketError(QAbstractSocket::SocketError error)
QAbstractSocket::SocketError error() const
QAbstractSocket::NetworkLayerProtocol protocol() const
void slotSocketStateChanged(QAbstractSocket::SocketState state)
void setSocketType(QAbstractSocket::SocketType socketType)
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807

◆ initialize() [2/2]

bool QHttpSocketEngine::initialize ( int  socketDescriptor,
QAbstractSocket::SocketState  socketState = QAbstractSocket::ConnectedState 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 106 of file qhttpsocketengine.cpp.

107 {
108  return false;
109 }

◆ isExceptionNotificationEnabled()

bool QHttpSocketEngine::isExceptionNotificationEnabled ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 482 of file qhttpsocketengine.cpp.

483 {
484  Q_D(const QHttpSocketEngine);
485  return d->exceptNotificationEnabled;
486 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isReadNotificationEnabled()

bool QHttpSocketEngine::isReadNotificationEnabled ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 448 of file qhttpsocketengine.cpp.

449 {
450  Q_D(const QHttpSocketEngine);
451  return d->readNotificationEnabled;
452 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isValid()

bool QHttpSocketEngine::isValid ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 129 of file qhttpsocketengine.cpp.

130 {
131  Q_D(const QHttpSocketEngine);
132  return d->socket;
133 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isWriteNotificationEnabled()

bool QHttpSocketEngine::isWriteNotificationEnabled ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 468 of file qhttpsocketengine.cpp.

469 {
470  Q_D(const QHttpSocketEngine);
471  return d->writeNotificationEnabled;
472 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ joinMulticastGroup()

bool QHttpSocketEngine::joinMulticastGroup ( const QHostAddress groupAddress,
const QNetworkInterface interface 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 251 of file qhttpsocketengine.cpp.

253 {
255  QLatin1String("Operation on socket is not supported"));
256  return false;
257 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setError(QAbstractSocket::SocketError error, const QString &errorString) const

◆ leaveMulticastGroup()

bool QHttpSocketEngine::leaveMulticastGroup ( const QHostAddress groupAddress,
const QNetworkInterface interface 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 259 of file qhttpsocketengine.cpp.

261 {
263  QLatin1String("Operation on socket is not supported"));
264  return false;
265 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setError(QAbstractSocket::SocketError error, const QString &errorString) const

◆ listen()

bool QHttpSocketEngine::listen ( )
virtual

Implements QAbstractSocketEngine.

Definition at line 194 of file qhttpsocketengine.cpp.

195 {
196  return false;
197 }

◆ multicastInterface()

QNetworkInterface QHttpSocketEngine::multicastInterface ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 267 of file qhttpsocketengine.cpp.

268 {
269  return QNetworkInterface();
270 }
The QNetworkInterface class provides a listing of the host&#39;s IP addresses and network interfaces...

◆ option()

int QHttpSocketEngine::option ( SocketOption  option) const
virtual

Implements QAbstractSocketEngine.

Definition at line 313 of file qhttpsocketengine.cpp.

314 {
315  Q_D(const QHttpSocketEngine);
316  if (d->socket) {
317  // convert the enum and call the real socket
319  return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt();
321  return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
322  }
323  return -1;
324 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int option(SocketOption option) const

◆ pendingDatagramSize()

qint64 QHttpSocketEngine::pendingDatagramSize ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 297 of file qhttpsocketengine.cpp.

298 {
299  return 0;
300 }

◆ read()

qint64 QHttpSocketEngine::read ( char *  data,
qint64  maxlen 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 220 of file qhttpsocketengine.cpp.

Referenced by slotSocketReadNotification().

221 {
223  qint64 bytesRead = d->socket->read(data, maxlen);
224 
225  if (d->socket->state() == QAbstractSocket::UnconnectedState
226  && d->socket->bytesAvailable() == 0) {
228  }
229 
230  if (bytesRead == -1) {
231  // If nothing has been read so far, and the direct socket read
232  // failed, return the socket's error. Otherwise, fall through and
233  // return as much as we read so far.
234  close();
236  QLatin1String("Remote host closed"));
238  return -1;
239  }
240  return bytesRead;
241 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(QAbstractSocket::SocketState state)
#define Q_D(Class)
Definition: qglobal.h:2482
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942

◆ readDatagram()

qint64 QHttpSocketEngine::readDatagram ( char *  data,
qint64  maxlen,
QHostAddress addr = 0,
quint16 port = 0 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 280 of file qhttpsocketengine.cpp.

282 {
283  return 0;
284 }

◆ setExceptionNotificationEnabled()

void QHttpSocketEngine::setExceptionNotificationEnabled ( bool  enable)
virtual

Implements QAbstractSocketEngine.

Definition at line 488 of file qhttpsocketengine.cpp.

489 {
491  d->exceptNotificationEnabled = enable;
492 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setMulticastInterface()

bool QHttpSocketEngine::setMulticastInterface ( const QNetworkInterface iface)
virtual

Implements QAbstractSocketEngine.

Definition at line 272 of file qhttpsocketengine.cpp.

273 {
275  QLatin1String("Operation on socket is not supported"));
276  return false;
277 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setError(QAbstractSocket::SocketError error, const QString &errorString) const

◆ setOption()

bool QHttpSocketEngine::setOption ( SocketOption  option,
int  value 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 326 of file qhttpsocketengine.cpp.

327 {
329  if (d->socket) {
330  // convert the enum and call the real socket
332  d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value);
334  d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
335  return true;
336  }
337  return false;
338 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int option(SocketOption option) const

◆ setProxy()

void QHttpSocketEngine::setProxy ( const QNetworkProxy networkProxy)

Definition at line 111 of file qhttpsocketengine.cpp.

Referenced by QHttpSocketEngineHandler::createSocketEngine().

112 {
114  d->proxy = proxy;
115  QString user = proxy.user();
116  if (!user.isEmpty())
117  d->authenticator.setUser(user);
118  QString password = proxy.password();
119  if (!password.isEmpty())
120  d->authenticator.setPassword(password);
121 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704

◆ setReadNotificationEnabled()

void QHttpSocketEngine::setReadNotificationEnabled ( bool  enable)
virtual

Implements QAbstractSocketEngine.

Definition at line 454 of file qhttpsocketengine.cpp.

455 {
457  if (d->readNotificationEnabled == enable)
458  return;
459 
460  d->readNotificationEnabled = enable;
461  if (enable) {
462  // Enabling read notification can trigger a notification.
463  if (bytesAvailable())
465  }
466 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
qint64 bytesAvailable() const

◆ setWriteNotificationEnabled()

void QHttpSocketEngine::setWriteNotificationEnabled ( bool  enable)
virtual

Implements QAbstractSocketEngine.

Definition at line 474 of file qhttpsocketengine.cpp.

475 {
477  d->writeNotificationEnabled = enable;
478  if (enable && d->state == Connected && d->socket->state() == QAbstractSocket::ConnectedState)
479  QMetaObject::invokeMethod(this, "writeNotification", Qt::QueuedConnection);
480 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ slotSocketBytesWritten

void QHttpSocketEngine::slotSocketBytesWritten ( )
slot

Definition at line 704 of file qhttpsocketengine.cpp.

Referenced by initialize().

705 {
707  if (d->state == Connected && d->writeNotificationEnabled)
709 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ slotSocketConnected

void QHttpSocketEngine::slotSocketConnected ( )
slot

Definition at line 494 of file qhttpsocketengine.cpp.

Referenced by initialize(), and slotSocketReadNotification().

495 {
497 
498  // Send the greeting.
499  const char method[] = "CONNECT";
500  QByteArray peerAddress = d->peerName.isEmpty() ?
501  d->peerAddress.toString().toLatin1() :
502  QUrl::toAce(d->peerName);
503  QByteArray path = peerAddress + ':' + QByteArray::number(d->peerPort);
504  QByteArray data = method;
505  data += " ";
506  data += path;
507  data += " HTTP/1.1\r\n";
508  data += "Proxy-Connection: keep-alive\r\n"
509  "User-Agent: ";
510  QVariant v = property("_q_user-agent");
511  if (v.isValid())
512  data += v.toByteArray();
513  else
514  data += "Mozilla/5.0";
515  data += "\r\n"
516  "Host: " + peerAddress + "\r\n";
518  //qDebug() << "slotSocketConnected: priv=" << priv << (priv ? (int)priv->method : -1);
519  if (priv && priv->method != QAuthenticatorPrivate::None) {
520  d->credentialsSent = true;
521  data += "Proxy-Authorization: " + priv->calculateResponse(method, path);
522  data += "\r\n";
523  }
524  data += "\r\n";
525 // qDebug() << ">>>>>>>> sending request" << this;
526 // qDebug() << data;
527 // qDebug() << ">>>>>>>";
528  d->socket->write(data);
529  d->state = ConnectSent;
530 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_D(Class)
Definition: qglobal.h:2482
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
Definition: qurl.cpp:6158
QHostAddress peerAddress() const
static const char * data(const QByteArray &arr)
static const QMetaObjectPrivate * priv(const uint *data)
QByteArray calculateResponse(const QByteArray &method, const QByteArray &path)
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...

◆ slotSocketDisconnected

void QHttpSocketEngine::slotSocketDisconnected ( )
slot

Definition at line 532 of file qhttpsocketengine.cpp.

Referenced by initialize().

533 {
534 }

◆ slotSocketError

void QHttpSocketEngine::slotSocketError ( QAbstractSocket::SocketError  error)
slot

Definition at line 711 of file qhttpsocketengine.cpp.

Referenced by initialize().

712 {
714  d->readBuffer.clear();
715 
716  if (d->state != Connected) {
717  // we are in proxy handshaking stages
719  setError(QAbstractSocket::ProxyNotFoundError, tr("Proxy server not found"));
721  setError(QAbstractSocket::ProxyConnectionRefusedError, tr("Proxy connection refused"));
723  setError(QAbstractSocket::ProxyConnectionTimeoutError, tr("Proxy server connection timed out"));
725  setError(QAbstractSocket::ProxyConnectionClosedError, tr("Proxy connection closed prematurely"));
726  else
727  setError(error, d->socket->errorString());
729  return;
730  }
731 
732  // We're connected
734  return; // ignore this error
735 
736  d->state = None;
737  setError(error, d->socket->errorString());
739  qDebug() << "QHttpSocketEngine::slotSocketError: got weird error =" << error;
740  //read notification needs to always be emitted, otherwise the higher layer doesn't get the disconnected signal
742 }
double d
Definition: qnumeric_p.h:62
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
QAbstractSocket::SocketError error() const

◆ slotSocketReadNotification

void QHttpSocketEngine::slotSocketReadNotification ( )
slot

Definition at line 536 of file qhttpsocketengine.cpp.

Referenced by connectInternal(), initialize(), and setReadNotificationEnabled().

537 {
539  if (d->state != Connected && d->socket->bytesAvailable() == 0)
540  return;
541 
542  if (d->state == Connected) {
543  // Forward as a read notification.
544  if (d->readNotificationEnabled)
546  return;
547  }
548 
549  readResponseContent:
550  if (d->state == ReadResponseContent) {
551  char dummybuffer[4096];
552  while (d->pendingResponseData) {
553  int read = d->socket->read(dummybuffer, qMin(sizeof(dummybuffer), (size_t)d->pendingResponseData));
554  if (read >= 0)
555  dummybuffer[read] = 0;
556 
557  if (read == 0)
558  return;
559  if (read == -1) {
560  d->socket->disconnectFromHost();
562  return;
563  }
564  d->pendingResponseData -= read;
565  }
566  if (d->pendingResponseData > 0)
567  return;
568  d->state = SendAuthentication;
570  return;
571  }
572 
573  // Still in handshake mode. Wait until we've got a full response.
574  bool done = false;
575  do {
576  d->readBuffer += d->socket->readLine();
577  } while (!(done = d->readBuffer.endsWith("\r\n\r\n")) && d->socket->canReadLine());
578 
579  if (!done) {
580  // Wait for more.
581  return;
582  }
583 
584  if (!d->readBuffer.startsWith("HTTP/1.")) {
585  // protocol error, this isn't HTTP
586  d->readBuffer.clear();
587  d->socket->close();
589  setError(QAbstractSocket::ProxyProtocolError, tr("Did not receive HTTP response from proxy"));
591  return;
592  }
593 
594  QHttpResponseHeader responseHeader(QString::fromLatin1(d->readBuffer));
595  d->readBuffer.clear(); // we parsed the proxy protocol response. from now on direct socket reading will be done
596 
597  int statusCode = responseHeader.statusCode();
599  if (statusCode == 200) {
600  d->state = Connected;
601  setLocalAddress(d->socket->localAddress());
602  setLocalPort(d->socket->localPort());
604  d->authenticator.detach();
605  priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
606  priv->hasFailed = false;
607  } else if (statusCode == 407) {
608  if (d->credentialsSent) {
609  //407 response again means the provided username/password were invalid.
610  d->authenticator = QAuthenticator(); //this is needed otherwise parseHttpResponse won't set the state, and then signal isn't emitted.
611  d->authenticator.detach();
612  priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
613  priv->hasFailed = true;
614  }
615  else if (d->authenticator.isNull())
616  d->authenticator.detach();
617  priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
618 
619  priv->parseHttpResponse(responseHeader, true);
620 
621  if (priv->phase == QAuthenticatorPrivate::Invalid) {
622  // problem parsing the reply
623  d->socket->close();
625  setError(QAbstractSocket::ProxyProtocolError, tr("Error parsing authentication request from proxy"));
627  return;
628  }
629 
630  bool willClose;
631  QString proxyConnectionHeader = responseHeader.value(QLatin1String("Proxy-Connection"));
632  // Although most proxies use the unofficial Proxy-Connection header, the Connection header
633  // from http spec is also allowed.
634  if (proxyConnectionHeader.isEmpty())
635  proxyConnectionHeader = responseHeader.value(QLatin1String("Connection"));
636  proxyConnectionHeader = proxyConnectionHeader.toLower();
637  if (proxyConnectionHeader == QLatin1String("close")) {
638  willClose = true;
639  } else if (proxyConnectionHeader == QLatin1String("keep-alive")) {
640  willClose = false;
641  } else {
642  // no Proxy-Connection header, so use the default
643  // HTTP 1.1's default behaviour is to keep persistent connections
644  // HTTP 1.0 or earlier, so we expect the server to close
645  willClose = (responseHeader.majorVersion() * 0x100 + responseHeader.minorVersion()) <= 0x0100;
646  }
647 
648  if (willClose) {
649  // the server will disconnect, so let's avoid receiving an error
650  // especially since the signal below may trigger a new event loop
651  d->socket->disconnectFromHost();
652  d->socket->readAll();
653  }
654 
655  if (priv->phase == QAuthenticatorPrivate::Done)
656  emit proxyAuthenticationRequired(d->proxy, &d->authenticator);
657  // priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above.
658  if (priv->phase == QAuthenticatorPrivate::Done) {
660  d->socket->disconnectFromHost();
661  } else {
662  // close the connection if it isn't already and reconnect using the chosen authentication method
663  d->state = SendAuthentication;
664  if (willClose) {
665  d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
666  } else {
667  bool ok;
668  int contentLength = responseHeader.value(QLatin1String("Content-Length")).toInt(&ok);
669  if (ok && contentLength > 0) {
670  d->state = ReadResponseContent;
671  d->pendingResponseData = contentLength;
672  goto readResponseContent;
673  } else {
674  d->state = SendAuthentication;
676  }
677  }
678  return;
679  }
680  } else {
681  d->socket->close();
683  if (statusCode == 403 || statusCode == 405) {
684  // 403 Forbidden
685  // 405 Method Not Allowed
686  setError(QAbstractSocket::SocketAccessError, tr("Proxy denied connection"));
687  } else if (statusCode == 404) {
688  // 404 Not Found: host lookup error
690  } else if (statusCode == 503) {
691  // 503 Service Unavailable: Connection Refused
693  } else {
694  // Some other reply
695  //qWarning("UNEXPECTED RESPONSE: [%s]", responseHeader.toString().toLatin1().data());
696  setError(QAbstractSocket::ProxyProtocolError, tr("Error communicating with HTTP proxy"));
697  }
698  }
699 
700  // The handshake is done; notify that we're connected (or failed to connect)
702 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void parseHttpResponse(const QHttpResponseHeader &, bool isProxy)
qint64 read(char *data, qint64 maxlen)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(QAbstractSocket::SocketState state)
void setLocalPort(quint16 port)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setLocalAddress(const QHostAddress &address)
#define emit
Definition: qobjectdefs.h:76
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QAuthenticator class provides an authentication object.
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
static const QMetaObjectPrivate * priv(const uint *data)
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119

◆ slotSocketStateChanged

void QHttpSocketEngine::slotSocketStateChanged ( QAbstractSocket::SocketState  state)
slot

Definition at line 744 of file qhttpsocketengine.cpp.

Referenced by initialize().

745 {
746  Q_UNUSED(state);
747 }
QAbstractSocket::SocketState state() const
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ socketDescriptor()

int QHttpSocketEngine::socketDescriptor ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 123 of file qhttpsocketengine.cpp.

124 {
125  Q_D(const QHttpSocketEngine);
126  return d->socket ? d->socket->socketDescriptor() : 0;
127 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ waitForRead()

bool QHttpSocketEngine::waitForRead ( int  msecs = 30000,
bool *  timedOut = 0 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 353 of file qhttpsocketengine.cpp.

Referenced by waitForReadOrWrite().

354 {
355  Q_D(const QHttpSocketEngine);
356 
357  if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState)
358  return false;
359 
360  QElapsedTimer stopWatch;
361  stopWatch.start();
362 
363  // Wait for more data if nothing is available.
364  if (!d->socket->bytesAvailable()) {
365  if (!d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
366  if (d->socket->state() == QAbstractSocket::UnconnectedState)
367  return true;
368  setError(d->socket->error(), d->socket->errorString());
369  if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
370  *timedOut = true;
371  return false;
372  }
373  }
374 
375  // If we're not connected yet, wait until we are, or until an error
376  // occurs.
377  while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
378  // Loop while the protocol handshake is taking place.
379  }
380 
381  // Report any error that may occur.
382  if (d->state != Connected) {
383  setError(d->socket->error(), d->socket->errorString());
384  if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
385  *timedOut = true;
386  return false;
387  }
388  return true;
389 }
double d
Definition: qnumeric_p.h:62
static int qt_timeout_value(int msecs, int elapsed)
#define Q_D(Class)
Definition: qglobal.h:2482
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
void start()
Starts this timer.

◆ waitForReadOrWrite()

bool QHttpSocketEngine::waitForReadOrWrite ( bool *  readyToRead,
bool *  readyToWrite,
bool  checkRead,
bool  checkWrite,
int  msecs = 30000,
bool *  timedOut = 0 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 427 of file qhttpsocketengine.cpp.

430 {
431  Q_UNUSED(checkRead);
432 
433  if (!checkWrite) {
434  // Not interested in writing? Then we wait for read notifications.
435  bool canRead = waitForRead(msecs, timedOut);
436  if (readyToRead)
437  *readyToRead = canRead;
438  return canRead;
439  }
440 
441  // Interested in writing? Then we wait for write notifications.
442  bool canWrite = waitForWrite(msecs, timedOut);
443  if (readyToWrite)
444  *readyToWrite = canWrite;
445  return canWrite;
446 }
bool waitForWrite(int msecs=30000, bool *timedOut=0)
bool waitForRead(int msecs=30000, bool *timedOut=0)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ waitForWrite()

bool QHttpSocketEngine::waitForWrite ( int  msecs = 30000,
bool *  timedOut = 0 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 391 of file qhttpsocketengine.cpp.

Referenced by waitForReadOrWrite().

392 {
393  Q_D(const QHttpSocketEngine);
394 
395  // If we're connected, just forward the call.
396  if (d->state == Connected) {
397  if (d->socket->bytesToWrite()) {
398  if (!d->socket->waitForBytesWritten(msecs)) {
399  if (d->socket->error() == QAbstractSocket::SocketTimeoutError && timedOut)
400  *timedOut = true;
401  return false;
402  }
403  }
404  return true;
405  }
406 
407  QElapsedTimer stopWatch;
408  stopWatch.start();
409 
410  // If we're not connected yet, wait until we are, and until bytes have
411  // been received (i.e., the socket has connected, we have sent the
412  // greeting, and then received the response).
413  while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
414  // Loop while the protocol handshake is taking place.
415  }
416 
417  // Report any error that may occur.
418  if (d->state != Connected) {
419 // setError(d->socket->error(), d->socket->errorString());
420  if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
421  *timedOut = true;
422  }
423 
424  return true;
425 }
double d
Definition: qnumeric_p.h:62
static int qt_timeout_value(int msecs, int elapsed)
#define Q_D(Class)
Definition: qglobal.h:2482
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
void start()
Starts this timer.

◆ write()

qint64 QHttpSocketEngine::write ( const char *  data,
qint64  len 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 243 of file qhttpsocketengine.cpp.

244 {
246  return d->socket->write(data, len);
247 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static const char * data(const QByteArray &arr)

◆ writeDatagram()

qint64 QHttpSocketEngine::writeDatagram ( const char *  data,
qint64  len,
const QHostAddress addr,
quint16  port 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 286 of file qhttpsocketengine.cpp.

288 {
289  return 0;
290 }

The documentation for this class was generated from the following files: