Qt 4.8
Public Functions | List of all members
QSocks5SocketEngine Class Reference

#include <qsocks5socketengine_p.h>

Inheritance diagram for QSocks5SocketEngine:
QAbstractSocketEngine QObject

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
 
 QSocks5SocketEngine (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)
 
 ~QSocks5SocketEngine ()
 
- 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...
 

Additional Inherited Members

- Public Types inherited from QAbstractSocketEngine
enum  SocketOption {
  NonBlockingSocketOption, BroadcastSocketOption, ReceiveBufferSocketOption, SendBufferSocketOption,
  AddressReusable, BindExclusively, ReceiveOutOfBandData, LowDelayOption,
  KeepAliveOption, MulticastTtlOption, MulticastLoopbackOption
}
 
- 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...
 
- 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 65 of file qsocks5socketengine_p.h.

Constructors and Destructors

◆ QSocks5SocketEngine()

QSocks5SocketEngine::QSocks5SocketEngine ( QObject parent = 0)

◆ ~QSocks5SocketEngine()

QSocks5SocketEngine::~QSocks5SocketEngine ( )

Definition at line 991 of file qsocks5socketengine.cpp.

992 {
994 
995  if (d->data) {
996  delete d->data->authenticator;
997  delete d->data->controlSocket;
998  }
999  if (d->connectData)
1000  delete d->connectData;
1001 #ifndef QT_NO_UDPSOCKET
1002  if (d->udpData) {
1003  delete d->udpData->udpSocket;
1004  delete d->udpData;
1005  }
1006 #endif
1007  if (d->bindData)
1008  delete d->bindData;
1009 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

Functions

◆ accept()

int QSocks5SocketEngine::accept ( )
virtual

Implements QAbstractSocketEngine.

Definition at line 1436 of file qsocks5socketengine.cpp.

1437 {
1439  // check we are listing ---
1440 
1441  QSOCKS5_Q_DEBUG << "accept()";
1442 
1443  if (d->socks5State == QSocks5SocketEnginePrivate::BindSuccess) {
1444  QSOCKS5_Q_DEBUG << "BindSuccess adding" << d->socketDescriptor << "to the bind store";
1445  d->data->controlSocket->disconnect();
1446  d->data->controlSocket->setParent(0);
1447  d->bindData->localAddress = d->localAddress;
1448  d->bindData->localPort = d->localPort;
1449  int sd = d->socketDescriptor;
1450  socks5BindStore()->add(sd, d->bindData);
1451  d->data = 0;
1452  d->bindData = 0;
1453  d->socketDescriptor = 0;
1454  //### do something about this socket layer ... set it closed and an error about why ...
1455  // reset state and local port/address
1456  d->socks5State = QSocks5SocketEnginePrivate::Uninitialized; // ..??
1457  d->socketState = QAbstractSocket::UnconnectedState;
1458  return sd;
1459  }
1460  return -1;
1461 }
double d
Definition: qnumeric_p.h:62
#define QSOCKS5_Q_DEBUG
#define Q_D(Class)
Definition: qglobal.h:2482

◆ bind()

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

delete d->udpSocket;

d->udpSocket = 0;

Implements QAbstractSocketEngine.

Definition at line 1328 of file qsocks5socketengine.cpp.

Referenced by connectInternal(), and writeDatagram().

1329 {
1331 
1332  // when bind wee will block until the bind is finished as the info from the proxy server is needed
1333 
1334  if (!d->data) {
1337 #ifndef QT_NO_UDPSOCKET
1338  } else if (socketType() == QAbstractSocket::UdpSocket) {
1340 #endif
1341  } else {
1342  //### something invalid
1343  return false;
1344  }
1345  }
1346 
1347 #ifndef QT_NO_UDPSOCKET
1349  if (!d->udpData->udpSocket->bind(address, port)) {
1350  QSOCKS5_Q_DEBUG << "local udp bind failed";
1351  setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
1352  return false;
1353  }
1354  d->localAddress = d->udpData->udpSocket->localAddress();
1355  d->localPort = d->udpData->udpSocket->localPort();
1356  } else
1357 #endif
1358  if (d->mode == QSocks5SocketEnginePrivate::BindMode) {
1359  d->localAddress = address;
1360  d->localPort = port;
1361  } else {
1362  //### something invalid
1363  return false;
1364  }
1365 
1366  int msecs = SOCKS5_BLOCKING_BIND_TIMEOUT;
1367  QElapsedTimer stopWatch;
1368  stopWatch.start();
1369  d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port());
1370  if (!d->waitForConnected(msecs, 0) ||
1371  d->data->controlSocket->state() == QAbstractSocket::UnconnectedState) {
1372  // waitForConnected sets the error state and closes the socket
1373  QSOCKS5_Q_DEBUG << "waitForConnected to proxy server" << d->data->controlSocket->errorString();
1374  return false;
1375  }
1376  if (d->socks5State == QSocks5SocketEnginePrivate::BindSuccess) {
1378  return true;
1379 #ifndef QT_NO_UDPSOCKET
1380  } else if (d->socks5State == QSocks5SocketEnginePrivate::UdpAssociateSuccess) {
1382  d->udpData->associateAddress = d->localAddress;
1383  d->localAddress = QHostAddress();
1384  d->udpData->associatePort = d->localPort;
1385  d->localPort = 0;
1386  QUdpSocket dummy;
1387 #ifndef QT_NO_BEARERMANAGEMENT
1388  dummy.setProperty("_q_networksession", property("_q_networksession"));
1389 #endif
1391  if (!dummy.bind()
1392  || writeDatagram(0,0, d->data->controlSocket->localAddress(), dummy.localPort()) != 0
1393  || !dummy.waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))
1394  || dummy.readDatagram(0,0, &d->localAddress, &d->localPort) != 0) {
1395  QSOCKS5_DEBUG << "udp actual address and port lookup failed";
1397  setError(dummy.error(), dummy.errorString());
1398  d->data->controlSocket->close();
1399  //### reset and error
1400  return false;
1401  }
1402  QSOCKS5_DEBUG << "udp actual address and port" << d->localAddress << ':' << d->localPort;
1403  return true;
1404 #endif // QT_NO_UDPSOCKET
1405  }
1406 
1407  // binding timed out
1409  QLatin1String(QT_TRANSLATE_NOOP("QSocks5SocketEngine", "Network operation timed out")));
1410 
1413  return false;
1414 }
double d
Definition: qnumeric_p.h:62
The QUdpSocket class provides a UDP socket.
Definition: qudpsocket.h:59
bool waitForReadyRead(int msecs=30000)
This function blocks until new data is available for reading and the QIODevice::readyRead() signal ha...
#define QSOCKS5_Q_DEBUG
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(QAbstractSocket::SocketState state)
#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.
bool bind(const QHostAddress &address, quint16 port)
Binds this socket to the address address and the port port.
Definition: qudpsocket.cpp:255
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, quint16 port)
void setProxy(const QNetworkProxy &networkProxy)
Sets the explicit network proxy for this socket to networkProxy.
static int qt_timeout_value(int msecs, int elapsed)
quint16 localPort() const
Returns the host port number (in native byte order) of the local socket if available; otherwise retur...
#define SOCKS5_BLOCKING_BIND_TIMEOUT
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
SocketError error() const
Returns the type of error that last occurred.
QAbstractSocket::SocketType socketType() const
void start()
Starts this timer.
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *host=0, quint16 *port=0)
Receives a datagram no larger than maxSize bytes and stores it in data.
Definition: qudpsocket.cpp:583
#define QSOCKS5_DEBUG

◆ bytesAvailable()

qint64 QSocks5SocketEngine::bytesAvailable ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1485 of file qsocks5socketengine.cpp.

1486 {
1487  Q_D(const QSocks5SocketEngine);
1489  return d->connectData->readBuffer.size();
1490 #ifndef QT_NO_UDPSOCKET
1492  && !d->udpData->pendingDatagrams.isEmpty())
1493  return d->udpData->pendingDatagrams.first().data.size();
1494 #endif
1495  return 0;
1496 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ bytesToWrite()

qint64 QSocks5SocketEngine::bytesToWrite ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1678 of file qsocks5socketengine.cpp.

1679 {
1680  Q_D(const QSocks5SocketEngine);
1681  if (d->data && d->data->controlSocket) {
1682  return d->data->controlSocket->bytesToWrite();
1683  } else {
1684  return 0;
1685  }
1686 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ close()

void QSocks5SocketEngine::close ( )
virtual

Implements QAbstractSocketEngine.

Definition at line 1463 of file qsocks5socketengine.cpp.

Referenced by read().

1464 {
1465  QSOCKS5_Q_DEBUG << "close()";
1467  if (d->data && d->data->controlSocket) {
1468  if (d->data->controlSocket->state() == QAbstractSocket::ConnectedState) {
1469  int msecs = 100;
1470  QElapsedTimer stopWatch;
1471  stopWatch.start();
1472  while (!d->data->controlSocket->bytesToWrite()) {
1473  if (!d->data->controlSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed())))
1474  break;
1475  }
1476  }
1477  d->data->controlSocket->close();
1478  }
1479 #ifndef QT_NO_UDPSOCKET
1480  if (d->udpData && d->udpData->udpSocket)
1481  d->udpData->udpSocket->close();
1482 #endif
1483 }
double d
Definition: qnumeric_p.h:62
#define QSOCKS5_Q_DEBUG
#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.
static int qt_timeout_value(int msecs, int elapsed)
void start()
Starts this timer.

◆ connectInternal()

bool QSocks5SocketEngine::connectInternal ( )

Definition at line 1103 of file qsocks5socketengine.cpp.

Referenced by connectToHost(), and connectToHostByName().

1104 {
1106 
1107  if (!d->data) {
1110 #ifndef QT_NO_UDPSOCKET
1111  } else if (socketType() == QAbstractSocket::UdpSocket) {
1113  // all udp needs to be bound
1114  if (!bind(QHostAddress(QLatin1String("0.0.0.0")), 0))
1115  return false;
1116 
1118  return true;
1119 #endif
1120  } else {
1121  qFatal("QSocks5SocketEngine::connectToHost: in QTcpServer mode");
1122  return false;
1123  }
1124  }
1125 
1126  if (d->socks5State == QSocks5SocketEnginePrivate::Uninitialized
1127  && d->socketState != QAbstractSocket::ConnectingState) {
1129  //limit buffer in internal socket, data is buffered in the external socket under application control
1130  d->data->controlSocket->setReadBufferSize(65536);
1131  d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port());
1132  return false;
1133  }
1134  return false;
1135 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(QAbstractSocket::SocketState state)
bool bind(const QHostAddress &address, quint16 port)
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qFatal(const char *,...)
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
QAbstractSocket::SocketType socketType() const

◆ connectToHost()

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

Implements QAbstractSocketEngine.

Definition at line 1137 of file qsocks5socketengine.cpp.

1138 {
1140  QSOCKS5_DEBUG << "connectToHost" << address << ':' << port;
1141 
1142  setPeerAddress(address);
1143  setPeerPort(port);
1144  d->peerName.clear();
1145 
1146  return connectInternal();
1147 }
double d
Definition: qnumeric_p.h:62
void setPeerAddress(const QHostAddress &address)
#define Q_D(Class)
Definition: qglobal.h:2482
void setPeerPort(quint16 port)
#define QSOCKS5_DEBUG

◆ connectToHostByName()

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

Implements QAbstractSocketEngine.

Definition at line 1149 of file qsocks5socketengine.cpp.

1150 {
1152 
1154  setPeerPort(port);
1155  d->peerName = hostname;
1156 
1157  return connectInternal();
1158 }
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

◆ hasPendingDatagrams()

bool QSocks5SocketEngine::hasPendingDatagrams ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1656 of file qsocks5socketengine.cpp.

1657 {
1658  Q_D(const QSocks5SocketEngine);
1659  Q_INIT_CHECK(false);
1660 
1661  d->checkForDatagrams();
1662 
1663  return !d->udpData->pendingDatagrams.isEmpty();
1664 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define Q_INIT_CHECK(returnValue)

◆ initialize() [1/2]

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

Implements QAbstractSocketEngine.

Definition at line 1013 of file qsocks5socketengine.cpp.

1014 {
1016 
1017  d->socketDescriptor = descriptorCounter.fetchAndAddRelaxed(1);
1018 
1019  d->socketType = type;
1020  d->socketProtocol = protocol;
1021 
1022  return true;
1023 }
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractSocket::NetworkLayerProtocol protocol() const
int fetchAndAddRelaxed(int valueToAdd)
static QBasicAtomicInt descriptorCounter

◆ initialize() [2/2]

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

Implements QAbstractSocketEngine.

Definition at line 1025 of file qsocks5socketengine.cpp.

1026 {
1028 
1029  QSOCKS5_Q_DEBUG << "initialize" << socketDescriptor;
1030 
1031  // this is only valid for the other side of a bind, nothing else is supported
1032 
1033  if (socketState != QAbstractSocket::ConnectedState) {
1034  //### must be connected state ???
1035  return false;
1036  }
1037 
1038  QSocks5BindData *bindData = socks5BindStore()->retrieve(socketDescriptor);
1039  if (bindData) {
1040 
1041  d->socketState = QAbstractSocket::ConnectedState;
1042  d->socketType = QAbstractSocket::TcpSocket;
1043  d->connectData = new QSocks5ConnectData;
1044  d->data = d->connectData;
1046  d->data->controlSocket = bindData->controlSocket;
1047  bindData->controlSocket = 0;
1048  d->data->controlSocket->setParent(this);
1049  d->socketProtocol = d->data->controlSocket->localAddress().protocol();
1050  d->data->authenticator = bindData->authenticator;
1051  bindData->authenticator = 0;
1052  d->localPort = bindData->localPort;
1053  d->localAddress = bindData->localAddress;
1054  d->peerPort = bindData->peerPort;
1055  d->peerAddress = bindData->peerAddress;
1056  delete bindData;
1057 
1058  QObject::connect(d->data->controlSocket, SIGNAL(connected()), this, SLOT(_q_controlSocketConnected()),
1060  QObject::connect(d->data->controlSocket, SIGNAL(readyRead()), this, SLOT(_q_controlSocketReadNotification()),
1062  QObject::connect(d->data->controlSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(_q_controlSocketBytesWritten()),
1064  QObject::connect(d->data->controlSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(_q_controlSocketError(QAbstractSocket::SocketError)),
1066  QObject::connect(d->data->controlSocket, SIGNAL(disconnected()), this, SLOT(_q_controlSocketDisconnected()),
1068  QObject::connect(d->data->controlSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
1069  this, SLOT(_q_controlSocketStateChanged(QAbstractSocket::SocketState)),
1071 
1073 
1074  if (d->data->controlSocket->bytesAvailable() != 0)
1075  d->_q_controlSocketReadNotification();
1076  return true;
1077  }
1078  return false;
1079 }
double d
Definition: qnumeric_p.h:62
QTcpSocket * controlSocket
#define QSOCKS5_Q_DEBUG
#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.
QSocks5Authenticator * authenticator
__int64 qint64
Definition: qglobal.h:942
QAbstractSocket::SocketError error() const

◆ isExceptionNotificationEnabled()

bool QSocks5SocketEngine::isExceptionNotificationEnabled ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1890 of file qsocks5socketengine.cpp.

1891 {
1892  Q_D(const QSocks5SocketEngine);
1893  return d->exceptNotificationEnabled;
1894 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isReadNotificationEnabled()

bool QSocks5SocketEngine::isReadNotificationEnabled ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1839 of file qsocks5socketengine.cpp.

1840 {
1841  Q_D(const QSocks5SocketEngine);
1842  return d->readNotificationEnabled;
1843 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isValid()

bool QSocks5SocketEngine::isValid ( ) const
virtual

◆ isWriteNotificationEnabled()

bool QSocks5SocketEngine::isWriteNotificationEnabled ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1872 of file qsocks5socketengine.cpp.

1873 {
1874  Q_D(const QSocks5SocketEngine);
1875  return d->writeNotificationEnabled;
1876 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ joinMulticastGroup()

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

Implements QAbstractSocketEngine.

Definition at line 1565 of file qsocks5socketengine.cpp.

1567 {
1569  QLatin1String("Operation on socket is not supported"));
1570  return false;
1571 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setError(QAbstractSocket::SocketError error, const QString &errorString) const

◆ leaveMulticastGroup()

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

Implements QAbstractSocketEngine.

Definition at line 1573 of file qsocks5socketengine.cpp.

1575 {
1577  QLatin1String("Operation on socket is not supported"));
1578  return false;
1579 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setError(QAbstractSocket::SocketError error, const QString &errorString) const

◆ listen()

bool QSocks5SocketEngine::listen ( )
virtual

Implements QAbstractSocketEngine.

Definition at line 1417 of file qsocks5socketengine.cpp.

1418 {
1420 
1421  QSOCKS5_Q_DEBUG << "listen()";
1422 
1423  // check that we are in bound and then go to listening.
1424  if (d->socketState == QAbstractSocket::BoundState) {
1425  d->socketState = QAbstractSocket::ListeningState;
1426 
1427  // check if we already have a connection
1428  if (d->socks5State == QSocks5SocketEnginePrivate::BindSuccess)
1429  d->emitReadNotification();
1430 
1431  return true;
1432  }
1433  return false;
1434 }
double d
Definition: qnumeric_p.h:62
#define QSOCKS5_Q_DEBUG
#define Q_D(Class)
Definition: qglobal.h:2482

◆ multicastInterface()

QNetworkInterface QSocks5SocketEngine::multicastInterface ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1582 of file qsocks5socketengine.cpp.

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

◆ option()

int QSocks5SocketEngine::option ( SocketOption  option) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1688 of file qsocks5socketengine.cpp.

1689 {
1690  Q_D(const QSocks5SocketEngine);
1691  if (d->data && d->data->controlSocket) {
1692  // convert the enum and call the real socket
1694  return d->data->controlSocket->socketOption(QAbstractSocket::LowDelayOption).toInt();
1696  return d->data->controlSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
1697  }
1698  return -1;
1699 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int option(SocketOption option) const

◆ pendingDatagramSize()

qint64 QSocks5SocketEngine::pendingDatagramSize ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1666 of file qsocks5socketengine.cpp.

1667 {
1668  Q_D(const QSocks5SocketEngine);
1669 
1670  d->checkForDatagrams();
1671 
1672  if (!d->udpData->pendingDatagrams.isEmpty())
1673  return d->udpData->pendingDatagrams.head().data.size();
1674  return 0;
1675 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ read()

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

Implements QAbstractSocketEngine.

Definition at line 1498 of file qsocks5socketengine.cpp.

1499 {
1501  QSOCKS5_Q_DEBUG << "read( , maxlen = " << maxlen << ')';
1503  if (d->connectData->readBuffer.size() == 0) {
1504  if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState) {
1505  //imitate remote closed
1506  close();
1508  QLatin1String("Remote host closed connection###"));
1510  return -1;
1511  } else {
1512  return 0; // nothing to be read
1513  }
1514  }
1515  qint64 copy = qMin<qint64>(d->connectData->readBuffer.size(), maxlen);
1516  memcpy(data, d->connectData->readBuffer.constData(), copy);
1517  d->connectData->readBuffer.remove(0, copy);
1518  QSOCKS5_DEBUG << "read" << dump(QByteArray(data, copy));
1519  return copy;
1520 #ifndef QT_NO_UDPSOCKET
1521  } else if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode) {
1522  return readDatagram(data, maxlen);
1523 #endif
1524  }
1525  return 0;
1526 }
double d
Definition: qnumeric_p.h:62
#define QSOCKS5_Q_DEBUG
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
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
static QString dump(const QByteArray &)
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr=0, quint16 *port=0)
#define QSOCKS5_DEBUG

◆ readDatagram()

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

Implements QAbstractSocketEngine.

Definition at line 1595 of file qsocks5socketengine.cpp.

Referenced by read().

1597 {
1599 
1600  d->checkForDatagrams();
1601 
1602  if (d->udpData->pendingDatagrams.isEmpty())
1603  return 0;
1604 
1605  QSocks5RevivedDatagram datagram = d->udpData->pendingDatagrams.dequeue();
1606  int copyLen = qMin<int>(maxlen, datagram.data.size());
1607  memcpy(data, datagram.data.constData(), copyLen);
1608  if (addr)
1609  *addr = datagram.address;
1610  if (port)
1611  *port = datagram.port;
1612  return copyLen;
1613 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static const char * data(const QByteArray &arr)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ setExceptionNotificationEnabled()

void QSocks5SocketEngine::setExceptionNotificationEnabled ( bool  enable)
virtual

Implements QAbstractSocketEngine.

Definition at line 1896 of file qsocks5socketengine.cpp.

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

◆ setMulticastInterface()

bool QSocks5SocketEngine::setMulticastInterface ( const QNetworkInterface iface)
virtual

Implements QAbstractSocketEngine.

Definition at line 1587 of file qsocks5socketengine.cpp.

1588 {
1590  QLatin1String("Operation on socket is not supported"));
1591  return false;
1592 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setError(QAbstractSocket::SocketError error, const QString &errorString) const

◆ setOption()

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

Implements QAbstractSocketEngine.

Definition at line 1701 of file qsocks5socketengine.cpp.

1702 {
1704  if (d->data && d->data->controlSocket) {
1705  // convert the enum and call the real socket
1707  d->data->controlSocket->setSocketOption(QAbstractSocket::LowDelayOption, value);
1709  d->data->controlSocket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
1710  return true;
1711  }
1712  return false;
1713 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int option(SocketOption option) const

◆ setProxy()

void QSocks5SocketEngine::setProxy ( const QNetworkProxy networkProxy)

Definition at line 1081 of file qsocks5socketengine.cpp.

Referenced by QSocks5SocketEngineHandler::createSocketEngine().

1082 {
1084  d->proxyInfo = networkProxy;
1085 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setReadNotificationEnabled()

void QSocks5SocketEngine::setReadNotificationEnabled ( bool  enable)
virtual

Implements QAbstractSocketEngine.

Definition at line 1845 of file qsocks5socketengine.cpp.

1846 {
1848 
1849  QSOCKS5_Q_DEBUG << "setReadNotificationEnabled(" << enable << ')';
1850 
1851  bool emitSignal = false;
1852  if (!d->readNotificationEnabled
1853  && enable) {
1855  emitSignal = !d->connectData->readBuffer.isEmpty();
1856 #ifndef QT_NO_UDPSOCKET
1858  emitSignal = !d->udpData->pendingDatagrams.isEmpty();
1859 #endif
1860  else if (d->mode == QSocks5SocketEnginePrivate::BindMode
1861  && d->socketState == QAbstractSocket::ListeningState
1862  && d->socks5State == QSocks5SocketEnginePrivate::BindSuccess)
1863  emitSignal = true;
1864  }
1865 
1866  d->readNotificationEnabled = enable;
1867 
1868  if (emitSignal)
1869  d->emitReadNotification();
1870 }
double d
Definition: qnumeric_p.h:62
#define QSOCKS5_Q_DEBUG
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setWriteNotificationEnabled()

void QSocks5SocketEngine::setWriteNotificationEnabled ( bool  enable)
virtual

Implements QAbstractSocketEngine.

Definition at line 1878 of file qsocks5socketengine.cpp.

1879 {
1881  d->writeNotificationEnabled = enable;
1882  if (enable && d->socketState == QAbstractSocket::ConnectedState) {
1883  if (d->mode == QSocks5SocketEnginePrivate::ConnectMode && d->data->controlSocket->bytesToWrite())
1884  return; // will be emitted as a result of bytes written
1885  d->emitWriteNotification();
1886  d->writeNotificationActivated = false;
1887  }
1888 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ socketDescriptor()

int QSocks5SocketEngine::socketDescriptor ( ) const
virtual

Implements QAbstractSocketEngine.

Definition at line 1087 of file qsocks5socketengine.cpp.

Referenced by QSocks5SocketEngineHandler::createSocketEngine(), and initialize().

1088 {
1089  Q_D(const QSocks5SocketEngine);
1090  return d->socketDescriptor;
1091 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ waitForRead()

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

Implements QAbstractSocketEngine.

Definition at line 1743 of file qsocks5socketengine.cpp.

Referenced by waitForReadOrWrite().

1744 {
1746  QSOCKS5_DEBUG << "waitForRead" << msecs;
1747 
1748  d->readNotificationActivated = false;
1749 
1750  QElapsedTimer stopWatch;
1751  stopWatch.start();
1752 
1753  // are we connected yet?
1754  if (!d->waitForConnected(msecs, timedOut))
1755  return false;
1756  if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState)
1757  return true;
1758 
1759  // we're connected
1762  while (!d->readNotificationActivated) {
1763  if (!d->data->controlSocket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
1764  if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState)
1765  return true;
1766 
1767  setError(d->data->controlSocket->error(), d->data->controlSocket->errorString());
1768  if (timedOut && d->data->controlSocket->error() == QAbstractSocket::SocketTimeoutError)
1769  *timedOut = true;
1770  return false;
1771  }
1772  }
1773 #ifndef QT_NO_UDPSOCKET
1774  } else {
1775  while (!d->readNotificationActivated) {
1776  if (!d->udpData->udpSocket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
1777  setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
1778  if (timedOut && d->udpData->udpSocket->error() == QAbstractSocket::SocketTimeoutError)
1779  *timedOut = true;
1780  return false;
1781  }
1782  }
1783 #endif // QT_NO_UDPSOCKET
1784  }
1785 
1786 
1787  bool ret = d->readNotificationActivated;
1788  d->readNotificationActivated = false;
1789 
1790  QSOCKS5_DEBUG << "waitForRead returned" << ret;
1791  return ret;
1792 }
double d
Definition: qnumeric_p.h:62
#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
static int qt_timeout_value(int msecs, int elapsed)
void start()
Starts this timer.
#define QSOCKS5_DEBUG

◆ waitForReadOrWrite()

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

Implements QAbstractSocketEngine.

Definition at line 1821 of file qsocks5socketengine.cpp.

1824 {
1825  Q_UNUSED(checkRead);
1826  if (!checkWrite) {
1827  bool canRead = waitForRead(msecs, timedOut);
1828  if (readyToRead)
1829  *readyToRead = canRead;
1830  return canRead;
1831  }
1832 
1833  bool canWrite = waitForWrite(msecs, timedOut);
1834  if (readyToWrite)
1835  *readyToWrite = canWrite;
1836  return canWrite;
1837 }
bool waitForRead(int msecs=30000, bool *timedOut=0)
bool waitForWrite(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 QSocks5SocketEngine::waitForWrite ( int  msecs = 30000,
bool *  timedOut = 0 
)
virtual

Implements QAbstractSocketEngine.

Definition at line 1795 of file qsocks5socketengine.cpp.

Referenced by waitForReadOrWrite().

1796 {
1798  QSOCKS5_DEBUG << "waitForWrite" << msecs;
1799 
1800  QElapsedTimer stopWatch;
1801  stopWatch.start();
1802 
1803  // are we connected yet?
1804  if (!d->waitForConnected(msecs, timedOut))
1805  return false;
1806  if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState)
1807  return true;
1808 
1809  // we're connected
1810 
1811  // flush any bytes we may still have buffered in the time that we have left
1812  if (d->data->controlSocket->bytesToWrite())
1813  d->data->controlSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed()));
1814  while ((msecs == -1 || stopWatch.elapsed() < msecs)
1815  && d->data->controlSocket->state() == QAbstractSocket::ConnectedState
1816  && d->data->controlSocket->bytesToWrite() >= MaxWriteBufferSize)
1817  d->data->controlSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed()));
1818  return d->data->controlSocket->bytesToWrite() < MaxWriteBufferSize;
1819 }
double d
Definition: qnumeric_p.h:62
static const int MaxWriteBufferSize
#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.
static int qt_timeout_value(int msecs, int elapsed)
void start()
Starts this timer.
#define QSOCKS5_DEBUG

◆ write()

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

Implements QAbstractSocketEngine.

Definition at line 1528 of file qsocks5socketengine.cpp.

1529 {
1531  QSOCKS5_Q_DEBUG << "write" << dump(QByteArray(data, len));
1532 
1534  // clamp down the amount of bytes to transfer at once
1535  len = qMin<qint64>(len, MaxWriteBufferSize) - d->data->controlSocket->bytesToWrite();
1536  if (len <= 0)
1537  return 0;
1538 
1540  QByteArray sealedBuf;
1541  if (!d->data->authenticator->seal(buf, &sealedBuf)) {
1542  // ### Handle this error.
1543  }
1544 
1545  qint64 written = d->data->controlSocket->write(sealedBuf);
1546  if (written <= 0) {
1547  QSOCKS5_Q_DEBUG << "native write returned" << written;
1548  return written;
1549  }
1550  d->data->controlSocket->waitForBytesWritten(0);
1551  //NB: returning len rather than written for the OK case, because the "sealing" may increase the length
1552  return len;
1553 #ifndef QT_NO_UDPSOCKET
1554  } else if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode) {
1555  // send to connected address
1556  return writeDatagram(data, len, d->peerAddress, d->peerPort);
1557 #endif
1558  }
1559  //### set an error ???
1560  return -1;
1561 }
double d
Definition: qnumeric_p.h:62
#define QSOCKS5_Q_DEBUG
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static const int MaxWriteBufferSize
#define Q_D(Class)
Definition: qglobal.h:2482
qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, quint16 port)
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
static QString dump(const QByteArray &)

◆ writeDatagram()

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

Implements QAbstractSocketEngine.

Definition at line 1615 of file qsocks5socketengine.cpp.

Referenced by bind(), and write().

1617 {
1619 
1620  // it is possible to send with out first binding with udp, but socks5 requires a bind.
1621  if (!d->data) {
1623  // all udp needs to be bound
1624  if (!bind(QHostAddress(QLatin1String("0.0.0.0")), 0)) {
1625  //### set error
1626  return -1;
1627  }
1628  }
1629 
1630  QByteArray outBuf;
1631  outBuf.reserve(270 + len);
1632  outBuf[0] = 0x00;
1633  outBuf[1] = 0x00;
1634  outBuf[2] = 0x00;
1635  if (!qt_socks5_set_host_address_and_port(address, port, &outBuf)) {
1636  }
1637  outBuf += QByteArray(data, len);
1638  QSOCKS5_DEBUG << "sending" << dump(outBuf);
1639  QByteArray sealedBuf;
1640  if (!d->data->authenticator->seal(outBuf, &sealedBuf)) {
1641  QSOCKS5_DEBUG << "sealing data failed";
1642  setError(QAbstractSocket::SocketAccessError, d->data->authenticator->errorString());
1643  return -1;
1644  }
1645  if (d->udpData->udpSocket->writeDatagram(sealedBuf, d->udpData->associateAddress, d->udpData->associatePort) != sealedBuf.size()) {
1646  //### try frgamenting
1647  if (d->udpData->udpSocket->error() == QAbstractSocket::DatagramTooLargeError)
1648  setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
1649  //### else maybe more serious error
1650  return -1;
1651  }
1652 
1653  return len;
1654 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool bind(const QHostAddress &address, quint16 port)
#define Q_D(Class)
Definition: qglobal.h:2482
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
static const char * data(const QByteArray &arr)
static bool qt_socks5_set_host_address_and_port(const QHostAddress &address, quint16 port, QByteArray *pBuf)
static QString dump(const QByteArray &)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
#define QSOCKS5_DEBUG

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