Qt 4.8
Signals | Public Functions | Private Slots | List of all members
QWSSocket Class Reference

#include <qwssocket_qws.h>

Inheritance diagram for QWSSocket:

Signals

void connected ()
 
void disconnected ()
 
void error (QAbstractSocket::SocketError)
 

Public Functions

bool connectToLocalFile (const QString &file)
 
QString errorString ()
 
 QWSSocket (QObject *parent=0)
 
 ~QWSSocket ()
 

Private Slots

void forwardStateChange (SocketState)
 

Detailed Description

Definition at line 66 of file qwssocket_qws.h.

Constructors and Destructors

◆ QWSSocket()

QWSSocket::QWSSocket ( QObject parent = 0)
explicit

Definition at line 88 of file qwssocket_qws.cpp.

Referenced by QWSServerSocket::nextPendingConnection().

89  : QWS_SOCK_BASE(parent)
90 {
91 #ifndef QT_NO_SXE
92  QObject::connect( this, SIGNAL(stateChanged(SocketState)),
93  this, SLOT(forwardStateChange(SocketState)));
94 #endif
95 }
void forwardStateChange(SocketState)
#define SLOT(a)
Definition: qobjectdefs.h:226
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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
#define QWS_SOCK_BASE
Definition: qwsutils_qws.h:54

◆ ~QWSSocket()

QWSSocket::~QWSSocket ( )

Definition at line 97 of file qwssocket_qws.cpp.

98 {
99 }

Functions

◆ connected

void QWSSocket::connected ( )
signal

Referenced by forwardStateChange().

◆ connectToLocalFile()

bool QWSSocket::connectToLocalFile ( const QString file)

Definition at line 136 of file qwssocket_qws.cpp.

137 {
138 #ifndef QT_NO_SXE
139  bool result = QUnixSocket::connect( file.toLocal8Bit() );
140  if ( !result )
141  {
142  perror( "QWSSocketAuth::connectToLocalFile could not connect:" );
144  return false;
145  }
146  return true;
147 #else
148  // create socket
149  int s = ::socket(PF_LOCAL, SOCK_STREAM, 0);
150 
151  // connect to socket
152  struct sockaddr_un a;
153  memset(&a, 0, sizeof(a));
154  a.sun_family = PF_LOCAL;
155  strncpy(a.sun_path, file.toLocal8Bit().constData(), sizeof(a.sun_path) - 1);
156  int r = ::connect(s, (struct sockaddr*)&a, SUN_LEN(&a));
157  if (r == 0) {
158  setSocketDescriptor(s);
159  } else {
160  perror("QWSSocket::connectToLocalFile could not connect:");
161  ::close(s);
162  emit error(ConnectionRefusedError);
163  return false;
164  }
165 #endif
166  return true;
167 }
long ASN1_INTEGER_get ASN1_INTEGER * a
void error(QAbstractSocket::SocketError)
#define emit
Definition: qobjectdefs.h:76
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool connect(const QByteArray &path)
Attempt to connect to path.

◆ disconnected

void QWSSocket::disconnected ( )
signal

Referenced by forwardStateChange().

◆ error

void QWSSocket::error ( QAbstractSocket::SocketError  )
signal

◆ errorString()

QString QWSSocket::errorString ( )

Definition at line 102 of file qwssocket_qws.cpp.

Referenced by QWSClient::errorHandler(), and QWSServerSocket::init().

103 {
104  switch (QUnixSocket::error()) {
105  case NoError:
106  return QString();
107  case InvalidPath:
108  case NonexistentPath:
109  return QLatin1String("Bad path"); // NO_TR
110  default:
111  return QLatin1String("Bad socket"); // NO TR
112  }
113 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
SocketError error() const
Returns the last error to have occurred on this object.

◆ forwardStateChange

void QWSSocket::forwardStateChange ( SocketState  )
privateslot

Definition at line 115 of file qwssocket_qws.cpp.

Referenced by QWSSocket().

116 {
117  switch ( st )
118  {
119  case ConnectedState:
120  emit connected();
121  break;
122  case ClosingState:
123  break;
124  case UnconnectedState:
125  emit disconnected();
126  break;
127  default:
128  // nothing
129  break;
130  }
131  if ( QUnixSocket::error() != NoError )
133 }
void error(QAbstractSocket::SocketError)
#define emit
Definition: qobjectdefs.h:76
SocketError
This enum describes the socket errors that can occur.
SocketError error() const
Returns the last error to have occurred on this object.
void disconnected()
#define st(var, type, card)
void connected()

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