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

#include <qlocalsocket_p.h>

Inheritance diagram for QLocalSocketPrivate:
QIODevicePrivate QObjectPrivate QObjectData

Public Functions

void _q_canWrite ()
 
void _q_emitReadyRead ()
 
void _q_notified ()
 
void _q_pipeClosed ()
 
DWORD checkPipeState ()
 Returns the number of available bytes in the pipe. More...
 
void checkReadyRead ()
 
bool completeAsyncRead ()
 Sets the correct size of the read buffer after a read operation. More...
 
void destroyPipeHandles ()
 
void init ()
 
 QLocalSocketPrivate ()
 
void setErrorString (const QString &function)
 
void startAsyncRead ()
 
 ~QLocalSocketPrivate ()
 
- Public Functions inherited from QIODevicePrivate
bool isSequential () const
 
virtual qint64 peek (char *data, qint64 maxSize)
 
virtual QByteArray peek (qint64 maxSize)
 
virtual bool putCharHelper (char c)
 
 QIODevicePrivate ()
 
virtual ~QIODevicePrivate ()
 
- 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
 

Public Variables

int actualReadBufferSize
 
QWinEventNotifierdataReadNotifier
 
QLocalSocket::LocalSocketError error
 
QString fullServerName
 
HANDLE handle
 
OVERLAPPED overlapped
 
bool pendingReadyRead
 
bool pipeClosed
 
QWindowsPipeWriterpipeWriter
 
QRingBuffer readBuffer
 
qint64 readBufferMaxSize
 
bool readSequenceStarted
 
QString serverName
 
QLocalSocket::LocalSocketState state
 
- Public Variables inherited from QIODevicePrivate
AccessMode accessMode
 
bool baseReadLineDataCalled
 
QIODevicePrivateLinearBuffer buffer
 
qint64 devicePos
 
QString errorString
 
bool firstRead
 
QIODevice::OpenMode openMode
 
qint64pDevicePos
 
qint64 pos
 
qint64pPos
 
qint64 seqDumpPos
 
- 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
 

Static Public Variables

static const qint64 initialReadBufferSize = 4096
 

Additional Inherited Members

- Public Types inherited from QIODevicePrivate
enum  AccessMode { Unset, Sequential, RandomAccess }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- 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)
 

Detailed Description

Definition at line 114 of file qlocalsocket_p.h.

Constructors and Destructors

◆ QLocalSocketPrivate()

QLocalSocketPrivate::QLocalSocketPrivate ( )

Definition at line 52 of file qlocalsocket_tcp.cpp.

Referenced by setErrorString().

52  : QIODevicePrivate(),
53  tcpSocket(0),
54  ownsTcpSocket(true),
56 {
57 }
QLocalSocket::LocalSocketState state

◆ ~QLocalSocketPrivate()

QLocalSocketPrivate::~QLocalSocketPrivate ( )

Definition at line 117 of file qlocalsocket_win.cpp.

118 {
120  CloseHandle(overlapped.hEvent);
121 }

Functions

◆ _q_canWrite()

void QLocalSocketPrivate::_q_canWrite ( )

Definition at line 506 of file qlocalsocket_win.cpp.

Referenced by completeAsyncRead().

507 {
508  Q_Q(QLocalSocket);
510  q->close();
511 }
QLocalSocket::LocalSocketState state
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483

◆ _q_emitReadyRead()

void QLocalSocketPrivate::_q_emitReadyRead ( )

Definition at line 528 of file qlocalsocket_win.cpp.

Referenced by checkReadyRead().

529 {
530  if (pendingReadyRead) {
531  Q_Q(QLocalSocket);
532  pendingReadyRead = false;
533  emit q->readyRead();
534  }
535 }
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76

◆ _q_notified()

void QLocalSocketPrivate::_q_notified ( )

Definition at line 513 of file qlocalsocket_win.cpp.

514 {
515  Q_Q(QLocalSocket);
516  if (!completeAsyncRead()) {
517  pipeClosed = true;
518  emit q->readChannelFinished();
519  if (actualReadBufferSize == 0)
521  return;
522  }
523  startAsyncRead();
524  pendingReadyRead = false;
525  emit q->readyRead();
526 }
#define SLOT(a)
Definition: qobjectdefs.h:226
bool completeAsyncRead()
Sets the correct size of the read buffer after a read operation.
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59

◆ _q_pipeClosed()

void QLocalSocketPrivate::_q_pipeClosed ( )

Definition at line 392 of file qlocalsocket_win.cpp.

Referenced by _q_notified(), checkPipeState(), and destroyPipeHandles().

393 {
394  Q_Q(QLocalSocket);
395  q->close();
396 }
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483

◆ checkPipeState()

DWORD QLocalSocketPrivate::checkPipeState ( )

Returns the number of available bytes in the pipe.

Warning
This function is not part of the public interface.

Sets QLocalSocketPrivate::pipeClosed to true if the connection is broken.

Definition at line 375 of file qlocalsocket_win.cpp.

Referenced by startAsyncRead().

376 {
377  Q_Q(QLocalSocket);
378  DWORD bytes;
379  if (PeekNamedPipe(handle, NULL, 0, NULL, &bytes, NULL)) {
380  return bytes;
381  } else {
382  if (!pipeClosed) {
383  pipeClosed = true;
384  emit q->readChannelFinished();
385  if (actualReadBufferSize == 0)
387  }
388  }
389  return 0;
390 }
#define SLOT(a)
Definition: qobjectdefs.h:226
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59

◆ checkReadyRead()

void QLocalSocketPrivate::checkReadyRead ( )
Warning
This function is not part of the public interface. Schedules or cancels a readyRead() emission depending on actual data availability

Definition at line 239 of file qlocalsocket_win.cpp.

240 {
241  if (actualReadBufferSize > 0) {
242  if (!pendingReadyRead) {
243  Q_Q(QLocalSocket);
245  pendingReadyRead = true;
246  }
247  } else {
248  pendingReadyRead = false;
249  }
250 }
#define SLOT(a)
Definition: qobjectdefs.h:226
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59

◆ completeAsyncRead()

bool QLocalSocketPrivate::completeAsyncRead ( )

Sets the correct size of the read buffer after a read operation.

Warning
This function is not part of the public interface.

Returns false, if an error occurred or the connection dropped.

Definition at line 319 of file qlocalsocket_win.cpp.

Referenced by _q_notified(), and startAsyncRead().

320 {
321  ResetEvent(overlapped.hEvent);
322  readSequenceStarted = false;
323 
324  DWORD bytesRead;
325  if (!GetOverlappedResult(handle, &overlapped, &bytesRead, TRUE)) {
326  switch (GetLastError()) {
327  case ERROR_MORE_DATA:
328  // This is not an error. We're connected to a message mode
329  // pipe and the message didn't fit into the pipe's system
330  // buffer. We will read the remaining data in the next call.
331  break;
332  case ERROR_PIPE_NOT_CONNECTED:
333  return false;
334  default:
335  setErrorString(QLatin1String("QLocalSocketPrivate::completeAsyncRead"));
336  return false;
337  }
338  }
339 
340  actualReadBufferSize += bytesRead;
342  return true;
343 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define TRUE
Synonym for true.
Definition: qglobal.h:1018
void truncate(int pos)
QRingBuffer readBuffer
void setErrorString(const QString &function)

◆ destroyPipeHandles()

void QLocalSocketPrivate::destroyPipeHandles ( )

Definition at line 123 of file qlocalsocket_win.cpp.

Referenced by ~QLocalSocketPrivate().

124 {
125  if (handle != INVALID_HANDLE_VALUE) {
126  DisconnectNamedPipe(handle);
127  CloseHandle(handle);
128  }
129 }

◆ init()

void QLocalSocketPrivate::init ( )

Definition at line 59 of file qlocalsocket_tcp.cpp.

60 {
61  setSocket(new QLocalUnixSocket);
62 }

◆ setErrorString()

void QLocalSocketPrivate::setErrorString ( const QString function)

Definition at line 59 of file qlocalsocket_win.cpp.

Referenced by completeAsyncRead(), destroyPipeHandles(), and startAsyncRead().

60 {
62  BOOL windowsError = GetLastError();
64 
65  // If the connectToServer fails due to WaitNamedPipe() time-out, assume ConnectionError
66  if (state == QLocalSocket::ConnectingState && windowsError == ERROR_SEM_TIMEOUT)
67  windowsError = ERROR_NO_DATA;
68 
69  switch (windowsError) {
70  case ERROR_PIPE_NOT_CONNECTED:
71  case ERROR_BROKEN_PIPE:
72  case ERROR_NO_DATA:
74  errorString = QLocalSocket::tr("%1: Connection error").arg(function);
76  break;
77  case ERROR_FILE_NOT_FOUND:
79  errorString = QLocalSocket::tr("%1: Invalid name").arg(function);
81  break;
82  case ERROR_ACCESS_DENIED:
84  errorString = QLocalSocket::tr("%1: Access denied").arg(function);
86  break;
87  default:
89  errorString = QLocalSocket::tr("%1: Unknown error %2").arg(function).arg(windowsError);
90 #if defined QLOCALSOCKET_DEBUG
91  qWarning() << "QLocalSocket error not handled:" << errorString;
92 #endif
94  }
95 
96  if (currentState != state) {
97  q->emit stateChanged(state);
99  q->emit disconnected();
100  }
101  emit q->error(error);
102 }
LocalSocketState
This enum describes the different states in which a socket can be.
Definition: qlocalsocket.h:78
QLocalSocket::LocalSocketState state
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLocalSocket::LocalSocketError error
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
QString errorString
Definition: qiodevice_p.h:213
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186

◆ startAsyncRead()

void QLocalSocketPrivate::startAsyncRead ( )
Warning
This function is not part of the public interface. Reads data from the socket into the readbuffer

Definition at line 256 of file qlocalsocket_win.cpp.

Referenced by _q_notified().

257 {
258  do {
259  DWORD bytesToRead = checkPipeState();
260  if (pipeClosed)
261  return;
262 
263  if (bytesToRead == 0) {
264  // There are no bytes in the pipe but we need to
265  // start the overlapped read with some buffer size.
266  bytesToRead = initialReadBufferSize;
267  }
268 
269  if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - readBuffer.size())) {
270  bytesToRead = readBufferMaxSize - readBuffer.size();
271  if (bytesToRead == 0) {
272  // Buffer is full. User must read data from the buffer
273  // before we can read more from the pipe.
274  return;
275  }
276  }
277 
278  char *ptr = readBuffer.reserve(bytesToRead);
279 
280  readSequenceStarted = true;
281  if (ReadFile(handle, ptr, bytesToRead, NULL, &overlapped)) {
283  } else {
284  switch (GetLastError()) {
285  case ERROR_IO_PENDING:
286  // This is not an error. We're getting notified, when data arrives.
287  return;
288  case ERROR_MORE_DATA:
289  // This is not an error. The synchronous read succeeded.
290  // We're connected to a message mode pipe and the message
291  // didn't fit into the pipe's system buffer.
293  break;
294  case ERROR_PIPE_NOT_CONNECTED:
295  {
296  // It may happen, that the other side closes the connection directly
297  // after writing data. Then we must set the appropriate socket state.
298  pipeClosed = true;
299  Q_Q(QLocalSocket);
300  emit q->readChannelFinished();
301  return;
302  }
303  default:
304  setErrorString(QLatin1String("QLocalSocketPrivate::startAsyncRead"));
305  return;
306  }
307  }
308  } while (!readSequenceStarted);
309 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool completeAsyncRead()
Sets the correct size of the read buffer after a read operation.
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
#define Q_Q(Class)
Definition: qglobal.h:2483
char * reserve(int bytes)
#define emit
Definition: qobjectdefs.h:76
const T * ptr(const T &t)
DWORD checkPipeState()
Returns the number of available bytes in the pipe.
static const qint64 initialReadBufferSize
QRingBuffer readBuffer
void setErrorString(const QString &function)
int size() const

Properties

◆ actualReadBufferSize

int QLocalSocketPrivate::actualReadBufferSize

◆ dataReadNotifier

QWinEventNotifier* QLocalSocketPrivate::dataReadNotifier

Definition at line 148 of file qlocalsocket_p.h.

◆ error

QLocalSocket::LocalSocketError QLocalSocketPrivate::error

Definition at line 149 of file qlocalsocket_p.h.

Referenced by destroyPipeHandles(), init(), and setErrorString().

◆ fullServerName

QString QLocalSocketPrivate::fullServerName

Definition at line 171 of file qlocalsocket_p.h.

Referenced by init().

◆ handle

HANDLE QLocalSocketPrivate::handle

◆ initialReadBufferSize

const qint64 QLocalSocketPrivate::initialReadBufferSize = 4096
static

Definition at line 153 of file qlocalsocket_p.h.

Referenced by startAsyncRead().

◆ overlapped

OVERLAPPED QLocalSocketPrivate::overlapped

Definition at line 143 of file qlocalsocket_p.h.

Referenced by completeAsyncRead(), startAsyncRead(), and ~QLocalSocketPrivate().

◆ pendingReadyRead

bool QLocalSocketPrivate::pendingReadyRead

Definition at line 151 of file qlocalsocket_p.h.

Referenced by _q_emitReadyRead(), _q_notified(), checkReadyRead(), and setErrorString().

◆ pipeClosed

bool QLocalSocketPrivate::pipeClosed

Definition at line 152 of file qlocalsocket_p.h.

Referenced by _q_notified(), checkPipeState(), setErrorString(), and startAsyncRead().

◆ pipeWriter

QWindowsPipeWriter* QLocalSocketPrivate::pipeWriter

Definition at line 144 of file qlocalsocket_p.h.

Referenced by setErrorString().

◆ readBuffer

QRingBuffer QLocalSocketPrivate::readBuffer

Definition at line 146 of file qlocalsocket_p.h.

Referenced by completeAsyncRead(), and startAsyncRead().

◆ readBufferMaxSize

qint64 QLocalSocketPrivate::readBufferMaxSize

Definition at line 145 of file qlocalsocket_p.h.

Referenced by setErrorString(), and startAsyncRead().

◆ readSequenceStarted

bool QLocalSocketPrivate::readSequenceStarted

Definition at line 150 of file qlocalsocket_p.h.

Referenced by completeAsyncRead(), setErrorString(), and startAsyncRead().

◆ serverName

QString QLocalSocketPrivate::serverName

Definition at line 170 of file qlocalsocket_p.h.

Referenced by init().

◆ state

QLocalSocket::LocalSocketState QLocalSocketPrivate::state

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