Qt 4.8
Classes | Public Functions | Static Public Functions | Public Variables | List of all members
QLocalServerPrivate Class Reference

#include <qlocalserver_p.h>

Inheritance diagram for QLocalServerPrivate:
QObjectPrivate QObjectData

Classes

struct  Listener
 

Public Functions

void _q_onNewConnection ()
 We have received a notification that we can read on the listen socket. More...
 
bool addListener ()
 
void closeServer ()
 
void init ()
 
bool listen (const QString &name)
 
 QLocalServerPrivate ()
 
void setError (const QString &function)
 
void waitForNewConnection (int msec, bool *timedOut)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static bool removeServer (const QString &name)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QWinEventNotifierconnectionEventNotifier
 
QAbstractSocket::SocketError error
 
QString errorString
 
HANDLE eventHandle
 
QString fullServerName
 
QList< Listenerlisteners
 
int maxPendingConnections
 
QQueue< QLocalSocket * > pendingConnections
 
QString serverName
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 74 of file qlocalserver_p.h.

Constructors and Destructors

◆ QLocalServerPrivate()

QLocalServerPrivate::QLocalServerPrivate ( )
inline

Definition at line 79 of file qlocalserver_p.h.

79  :
80 #if !defined(QT_LOCALSOCKET_TCP) && !defined(Q_OS_WIN)
81  listenSocket(-1), socketNotifier(0),
82 #endif
84  {
85  }
QAbstractSocket::SocketError error

Functions

◆ _q_onNewConnection()

void QLocalServerPrivate::_q_onNewConnection ( )

We have received a notification that we can read on the listen socket.

Warning
This function is not part of the public interface.

Accept the new socket.

Definition at line 99 of file qlocalserver_tcp.cpp.

Referenced by addListener(), init(), and QLocalServerPrivate().

100 {
101  Q_Q(QLocalServer);
102  QTcpSocket* tcpSocket = tcpServer.nextPendingConnection();
103  if (!tcpSocket) {
104  qWarning("QLocalServer: no pending connection");
105  return;
106  }
107 
108  tcpSocket->setParent(q);
109  const quintptr socketDescriptor = tcpSocket->socketDescriptor();
110  q->incomingConnection(socketDescriptor);
111 }
int socketDescriptor() const
Returns the native socket descriptor of the QAbstractSocket object if this is available; otherwise re...
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qWarning(const char *,...)
The QLocalServer class provides a local socket based server.
Definition: qlocalserver.h:58
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56

◆ addListener()

bool QLocalServerPrivate::addListener ( )

Definition at line 58 of file qlocalserver_win.cpp.

59 {
60  // The object must not change its address once the
61  // contained OVERLAPPED struct is passed to Windows.
62  listeners << Listener();
63  Listener &listener = listeners.last();
64 
65  listener.handle = CreateNamedPipe(
66  (const wchar_t *)fullServerName.utf16(), // pipe name
67  PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, // read/write access
68  PIPE_TYPE_BYTE | // byte type pipe
69  PIPE_READMODE_BYTE | // byte-read mode
70  PIPE_WAIT, // blocking mode
71  PIPE_UNLIMITED_INSTANCES, // max. instances
72  BUFSIZE, // output buffer size
73  BUFSIZE, // input buffer size
74  3000, // client time-out
75  NULL);
76 
77  if (listener.handle == INVALID_HANDLE_VALUE) {
78  setError(QLatin1String("QLocalServerPrivate::addListener"));
79  listeners.removeLast();
80  return false;
81  }
82 
83  memset(&listener.overlapped, 0, sizeof(listener.overlapped));
84  listener.overlapped.hEvent = eventHandle;
85  if (!ConnectNamedPipe(listener.handle, &listener.overlapped)) {
86  switch (GetLastError()) {
87  case ERROR_IO_PENDING:
88  listener.connected = false;
89  break;
90  case ERROR_PIPE_CONNECTED:
91  listener.connected = true;
92  SetEvent(eventHandle);
93  break;
94  default:
95  CloseHandle(listener.handle);
96  setError(QLatin1String("QLocalServerPrivate::addListener"));
97  listeners.removeLast();
98  return false;
99  }
100  } else {
101  Q_ASSERT_X(false, "QLocalServerPrivate::addListener", "The impossible happened");
102  SetEvent(eventHandle);
103  }
104  return true;
105 }
QList< Listener > listeners
#define BUFSIZE
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setError(const QString &function)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static QNSListener * listener
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ closeServer()

void QLocalServerPrivate::closeServer ( )
Warning
This function is not part of the public interface.
See also
QLocalServer::closeServer()

Definition at line 81 of file qlocalserver_tcp.cpp.

Referenced by addListener(), and QLocalServerPrivate().

82 {
83  QSettings settings(QLatin1String("Trolltech"), QLatin1String("Qt"));
84  if (fullServerName == QLatin1String("QLocalServer"))
85  settings.setValue(fullServerName, QVariant());
86  else
87  settings.remove(fullServerName);
88  tcpServer.close();
89 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ init()

void QLocalServerPrivate::init ( )

Definition at line 53 of file qlocalserver_tcp.cpp.

Referenced by addListener(), and QLocalServerPrivate().

54 {
56  q->connect(&tcpServer, SIGNAL(newConnection()), SLOT(_q_onNewConnection()));
57 }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_Q(Class)
Definition: qglobal.h:2483
void _q_onNewConnection()
We have received a notification that we can read on the listen socket.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QLocalServer class provides a local socket based server.
Definition: qlocalserver.h:58

◆ listen()

bool QLocalServerPrivate::listen ( const QString name)

Definition at line 59 of file qlocalserver_tcp.cpp.

Referenced by addListener(), and QLocalServerPrivate().

60 {
61  if (!tcpServer.listen(QHostAddress::LocalHost))
62  return false;
63 
64  const QLatin1String prefix("QLocalServer/");
65  if (requestedServerName.startsWith(prefix))
66  fullServerName = requestedServerName;
67  else
68  fullServerName = prefix + requestedServerName;
69 
70  QSettings settings(QLatin1String("Trolltech"), QLatin1String("Qt"));
71  if (settings.contains(fullServerName)) {
72  qWarning("QLocalServer::listen: server name is already in use.");
73  tcpServer.close();
74  return false;
75  }
76 
77  settings.setValue(fullServerName, tcpServer.serverPort());
78  return true;
79 }
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654

◆ removeServer()

bool QLocalServerPrivate::removeServer ( const QString name)
static

Definition at line 113 of file qlocalserver_tcp.cpp.

Referenced by addListener(), QLocalServerPrivate(), and QLocalServer::removeServer().

114 {
115  const QLatin1String prefix("QLocalServer/");
117  if (name.startsWith(prefix))
118  serverName = name;
119  else
120  serverName = prefix + name;
121 
122  QSettings settings(QLatin1String("Trolltech"), QLatin1String("Qt"));
123  if (settings.contains(serverName))
124  settings.remove(serverName);
125 
126  return true;
127 }
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * name
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654

◆ setError()

void QLocalServerPrivate::setError ( const QString function)

Definition at line 234 of file qlocalserver_unix.cpp.

Referenced by addListener().

235 {
236  if (EAGAIN == errno)
237  return;
238 
239  switch (errno) {
240  case EACCES:
241  errorString = QLocalServer::tr("%1: Permission denied").arg(function);
243  break;
244  case ELOOP:
245  case ENOENT:
246  case ENAMETOOLONG:
247  case EROFS:
248  case ENOTDIR:
249  errorString = QLocalServer::tr("%1: Name error").arg(function);
251  break;
252  case EADDRINUSE:
253  errorString = QLocalServer::tr("%1: Address in use").arg(function);
255  break;
256 
257  default:
258  errorString = QLocalServer::tr("%1: Unknown error %2")
259  .arg(function).arg(errno);
261 #if defined QLOCALSERVER_DEBUG
262  qWarning() << errorString << "fullServerName:" << fullServerName;
263 #endif
264  }
265 }
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
Q_CORE_EXPORT void qWarning(const char *,...)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QAbstractSocket::SocketError error
int errno

◆ waitForNewConnection()

void QLocalServerPrivate::waitForNewConnection ( int  msec,
bool *  timedOut 
)

Definition at line 91 of file qlocalserver_tcp.cpp.

Referenced by addListener(), and QLocalServerPrivate().

92 {
94  tcpServer.waitForNewConnection(msec, timedOut);
95  else if (timedOut)
96  *timedOut = false;
97 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QQueue< QLocalSocket * > pendingConnections

Properties

◆ connectionEventNotifier

QWinEventNotifier* QLocalServerPrivate::connectionEventNotifier

Definition at line 110 of file qlocalserver_p.h.

Referenced by addListener().

◆ error

QAbstractSocket::SocketError QLocalServerPrivate::error

Definition at line 123 of file qlocalserver_p.h.

Referenced by addListener(), and setError().

◆ errorString

QString QLocalServerPrivate::errorString

Definition at line 122 of file qlocalserver_p.h.

Referenced by addListener(), and setError().

◆ eventHandle

HANDLE QLocalServerPrivate::eventHandle

Definition at line 109 of file qlocalserver_p.h.

Referenced by addListener().

◆ fullServerName

QString QLocalServerPrivate::fullServerName

Definition at line 119 of file qlocalserver_p.h.

Referenced by addListener(), closeServer(), listen(), and setError().

◆ listeners

QList<Listener> QLocalServerPrivate::listeners

Definition at line 108 of file qlocalserver_p.h.

Referenced by addListener().

◆ maxPendingConnections

int QLocalServerPrivate::maxPendingConnections

Definition at line 120 of file qlocalserver_p.h.

Referenced by addListener().

◆ pendingConnections

QQueue<QLocalSocket*> QLocalServerPrivate::pendingConnections

Definition at line 121 of file qlocalserver_p.h.

Referenced by addListener(), and waitForNewConnection().

◆ serverName

QString QLocalServerPrivate::serverName

Definition at line 118 of file qlocalserver_p.h.

Referenced by removeServer().


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