Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Public Variables | List of all members
QUnixSocketPrivate Class Reference
Inheritance diagram for QUnixSocketPrivate:
QObject

Public Types

enum  { CausedAbort = 0x70000000 }
 

Public Slots

void readActivated ()
 
qint64 writeActivated ()
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void bytesWritten (qint64)
 
void readyRead ()
 
- 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...
 

Public Functions

unsigned int ancillaryBufferCapacity ()
 
void flushAncillary ()
 
 QUnixSocketPrivate (QUnixSocket *_me)
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
 ~QUnixSocketPrivate ()
 
- 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...
 

Public Variables

QByteArray address
 
char * ancillaryBuffer
 
unsigned int ancillaryBufferCount
 
int closingTimer
 
char * dataBuffer
 
unsigned int dataBufferCapacity
 
unsigned int dataBufferLength
 
QUnixSocket::SocketError error
 
int fd
 
QUnixSocketme
 
::msghdr message
 
bool messageValid
 
QSocketNotifierreadNotifier
 
QUnixSocket::SocketState state
 
QSocketNotifierwriteNotifier
 
QQueue< QUnixSocketMessagewriteQueue
 
unsigned int writeQueueBytes
 

Additional Inherited Members

- 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 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
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 801 of file qunixsocket.cpp.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
CausedAbort 

Definition at line 822 of file qunixsocket.cpp.

Constructors and Destructors

◆ QUnixSocketPrivate()

QUnixSocketPrivate::QUnixSocketPrivate ( QUnixSocket _me)
inline

Definition at line 804 of file qunixsocket.cpp.

805  : me(_me), fd(-1), readNotifier(0), writeNotifier(0),
807  writeQueueBytes(0), messageValid(false), dataBuffer(0),
813  }
unsigned int ancillaryBufferCount
QSocketNotifier * readNotifier
QUnixSocket::SocketError error
QUnixSocket * me
unsigned int dataBufferLength
QUnixSocket::SocketState state
#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
void bytesWritten(qint64)
__int64 qint64
Definition: qglobal.h:942
unsigned int writeQueueBytes
unsigned int dataBufferCapacity
QSocketNotifier * writeNotifier

◆ ~QUnixSocketPrivate()

QUnixSocketPrivate::~QUnixSocketPrivate ( )
inline

Definition at line 814 of file qunixsocket.cpp.

815  {
816  if(dataBuffer)
817  delete [] dataBuffer;
818  if(ancillaryBuffer)
819  delete [] ancillaryBuffer;
820  }

Functions

◆ ancillaryBufferCapacity()

unsigned int QUnixSocketPrivate::ancillaryBufferCapacity ( )
inline

Definition at line 865 of file qunixsocket.cpp.

866  {
867  return CMSG_SPACE(sizeof(::ucred)) + CMSG_SPACE(sizeof(int) * ancillaryBufferCount);
868  }
unsigned int ancillaryBufferCount

◆ bytesWritten

void QUnixSocketPrivate::bytesWritten ( qint64  )
signal

◆ flushAncillary()

void QUnixSocketPrivate::flushAncillary ( )
inline

Definition at line 839 of file qunixsocket.cpp.

Referenced by QUnixSocket::abort(), and QUnixSocket::readData().

840  {
841  if(!messageValid) return;
842  ::cmsghdr * h = (::cmsghdr *)CMSG_FIRSTHDR(&(message));
843  while(h) {
844 
845  if(SCM_RIGHTS == h->cmsg_type) {
846  int * fds = (int *)CMSG_DATA(h);
847  int numFds = (h->cmsg_len - CMSG_LEN(0)) / sizeof(int);
848 
849  for(int ii = 0; ii < numFds; ++ii)
850  QT_CLOSE(fds[ii]);
851  }
852 
853  h = (::cmsghdr *)CMSG_NXTHDR(&(message), h);
854  }
855 
856  messageValid = false;
857  }
#define QT_CLOSE
Definition: qcore_unix_p.h:304

◆ readActivated

void QUnixSocketPrivate::readActivated ( )
slot

Definition at line 1773 of file qunixsocket.cpp.

Referenced by QUnixSocket::waitForReadyRead().

1774 {
1775 #ifdef QUNIXSOCKET_DEBUG
1776  qDebug() << "QUnixSocket: readActivated";
1777 #endif
1778  readNotifier->setEnabled(false);
1779 
1780  ::iovec vec;
1781  vec.iov_base = dataBuffer;
1782  vec.iov_len = dataBufferCapacity;
1783 
1784  bzero(&message, sizeof(::msghdr));
1785  message.msg_iov = &vec;
1786  message.msg_iovlen = 1;
1787  message.msg_controllen = ancillaryBufferCapacity();
1788  message.msg_control = ancillaryBuffer;
1789 
1790  int flags = 0;
1791 #ifdef MSG_CMSG_CLOEXEC
1792  flags = MSG_CMSG_CLOEXEC;
1793 #endif
1794 
1795  int recvrv = ::recvmsg(fd, &message, flags);
1796 #ifdef QUNIXSOCKET_DEBUG
1797  qDebug() << "QUnixSocket: Received message (" << recvrv << ')';
1798 #endif
1799  if(-1 == recvrv) {
1800 #ifdef QUNIXSOCKET_DEBUG
1801  qDebug() << "QUnixSocket: Unable to receive data ("
1802  << ::strerror(errno) << ')';
1803 #endif
1805  CausedAbort);
1806  me->abort();
1807  } else if(0 == recvrv) {
1808  me->abort();
1809  } else {
1810  Q_ASSERT(recvrv);
1811  Q_ASSERT((unsigned)recvrv <= dataBufferCapacity);
1812  dataBufferLength = recvrv;
1813  messageValid = true;
1814 
1815 #ifdef QUNIXSOCKET_DEBUG
1816  qDebug() << "QUnixSocket: readyRead() " << dataBufferLength;
1817 #endif
1818  emit readyRead();
1819  }
1820 }
void abort()
Abort the connection.
QSocketNotifier * readNotifier
QUnixSocket::SocketError error
QUnixSocket * me
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned int dataBufferLength
Q_CORE_EXPORT void qDebug(const char *,...)
#define emit
Definition: qobjectdefs.h:76
SocketError
The SocketError enumeration represents the various errors that can occur on a Unix domain socket...
unsigned int ancillaryBufferCapacity()
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
unsigned int dataBufferCapacity
int errno

◆ readyRead

void QUnixSocketPrivate::readyRead ( )
signal

◆ timerEvent()

virtual void QUnixSocketPrivate::timerEvent ( QTimerEvent event)
inlinevirtual

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.

See also
startTimer(), killTimer(), event()

Reimplemented from QObject.

Definition at line 875 of file qunixsocket.cpp.

876  {
877  me->abort();
879  closingTimer = 0;
880  }
void abort()
Abort the connection.
QUnixSocket * me
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ writeActivated

qint64 QUnixSocketPrivate::writeActivated ( )
slot

Definition at line 1648 of file qunixsocket.cpp.

Referenced by QUnixSocket::flush(), and QUnixSocket::waitForBytesWritten().

1649 {
1650  writeNotifier->setEnabled(false);
1651 
1653  const QList<QUnixSocketRights> & a = m.rights();
1654 
1655  //
1656  // Construct the message
1657  //
1658  ::iovec vec;
1659  if ( !m.d->vec ) // message does not already have an iovec
1660  {
1661  vec.iov_base = (void *)m.bytes().constData();
1662  vec.iov_len = m.bytes().size();
1663  }
1664 
1665  // Allocate the control buffer
1666  ::msghdr sendmessage;
1667  ::bzero(&sendmessage, sizeof(::msghdr));
1668  if ( m.d->vec )
1669  {
1670  sendmessage.msg_iov = m.d->vec;
1671  sendmessage.msg_iovlen = m.d->iovecLen;
1672  }
1673  else
1674  {
1675  sendmessage.msg_iov = &vec;
1676  sendmessage.msg_iovlen = 1;
1677  }
1678  unsigned int required = CMSG_SPACE(sizeof(::ucred)) +
1679  a.size() * CMSG_SPACE(sizeof(int));
1680  sendmessage.msg_control = new char[required];
1681  ::bzero(sendmessage.msg_control, required);
1682  sendmessage.msg_controllen = required;
1683 
1684  // Create ancillary buffer
1685  ::cmsghdr * h = CMSG_FIRSTHDR(&sendmessage);
1686 
1688  h->cmsg_len = CMSG_LEN(sizeof(::ucred));
1689  h->cmsg_level = SOL_SOCKET;
1690  h->cmsg_type = SCM_CREDENTIALS;
1691  ((::ucred *)CMSG_DATA(h))->pid = m.d->pid;
1692  ((::ucred *)CMSG_DATA(h))->gid = m.d->gid;
1693  ((::ucred *)CMSG_DATA(h))->uid = m.d->uid;
1694  h = CMSG_NXTHDR(&sendmessage, h);
1695  } else {
1696  sendmessage.msg_controllen -= CMSG_SPACE(sizeof(::ucred));
1697  }
1698 
1699  for(int ii = 0; ii < a.count(); ++ii) {
1700  const QUnixSocketRights & r = a.at(ii);
1701 
1702  if(r.isValid()) {
1703  h->cmsg_len = CMSG_LEN(sizeof(int));
1704  h->cmsg_level = SOL_SOCKET;
1705  h->cmsg_type = SCM_RIGHTS;
1706  *((int *)CMSG_DATA(h)) = r.peekFd();
1707  h = CMSG_NXTHDR(&sendmessage, h);
1708  } else {
1709  sendmessage.msg_controllen -= CMSG_SPACE(sizeof(int));
1710  }
1711  }
1712 
1713 #ifdef QUNIXSOCKET_DEBUG
1714  qDebug() << "QUnixSocket: Transmitting message (length" << m.d->size() << ')';
1715 #endif
1716  ::ssize_t s = ::sendmsg(fd, &sendmessage, MSG_DONTWAIT | MSG_NOSIGNAL);
1717 #ifdef QUNIXSOCKET_DEBUG
1718  qDebug() << "QUnixSocket: Transmitted message (" << s << ')';
1719 #endif
1720 
1721  if(-1 == s) {
1722  if(EAGAIN == errno || EWOULDBLOCK == errno || EINTR == errno) {
1723  writeNotifier->setEnabled(true);
1724  } else if(EPIPE == errno) {
1725 #ifdef QUNIXSOCKET_DEBUG
1726  qDebug() << "QUnixSocket: Remote side disconnected during transmit "
1727  "(" << ::strerror(errno) << ')';
1728 #endif
1729  me->abort();
1730  } else {
1731 #ifdef QUNIXSOCKET_DEBUG
1732  qDebug() << "QUnixSocket: Unable to transmit data ("
1733  << ::strerror(errno) << ')';
1734 #endif
1736  CausedAbort);
1737  me->abort();
1738  }
1739  } else if(s != m.d->size()) {
1740 
1741  // A partial transmission
1742  writeNotifier->setEnabled(true);
1743  delete [] (char *)sendmessage.msg_control;
1745  m.d->removeBytes( s );
1746  writeQueueBytes -= s;
1747  emit bytesWritten(s);
1748  return s;
1749 
1750  } else {
1751 
1752  // Success!
1753  writeQueue.dequeue();
1754  Q_ASSERT(writeQueueBytes >= (unsigned)s);
1755  writeQueueBytes -= s;
1756  emit bytesWritten(s);
1757 
1758  }
1759 
1760  delete [] (char *)sendmessage.msg_control;
1761  if(-1 != s && !writeQueue.isEmpty())
1762  return writeActivated();
1764  me->abort();
1765 
1766  if((-1 == s) && (EAGAIN == errno || EWOULDBLOCK == errno || EINTR == errno))
1767  // Return zero bytes written to indicate retry may be required
1768  return 0;
1769  else
1770  return s;
1771 }
void abort()
Abort the connection.
AncillaryDataState state
QUnixSocket::SocketError error
QUnixSocket * me
void removeBytes(unsigned int)
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool isValid() const
Returns true if this QUnixSocketRights instance is managing a valid file descriptor.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QUnixSocketRights class encapsulates QUnixSocket rights data.
Definition: qunixsocket_p.h:73
QQueue< QUnixSocketMessage > writeQueue
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qDebug(const char *,...)
const QList< QUnixSocketRights > & rights() const
Return the rights portion of the message.
QList< QUnixSocketRights > rights
void bytesWritten(qint64)
SocketState state() const
Returns the connection state of this instance.
int peekFd() const
Returns the file descriptor contained in this object.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
T & head()
Returns a reference to the queue&#39;s head item.
Definition: qqueue.h:62
SocketError
The SocketError enumeration represents the various errors that can occur on a Unix domain socket...
unsigned int writeQueueBytes
QSharedDataPointer< QUnixSocketMessagePrivate > d
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 items in the list.
Definition: qlist.h:137
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
const QByteArray & bytes() const
Return the data portion of the message.
T dequeue()
Removes the head item in the queue and returns it.
Definition: qqueue.h:61
QSocketNotifier * writeNotifier
The QUnixSocketMessage class encapsulates a message sent or received through the QUnixSocket class...
Definition: qunixsocket_p.h:92
int errno

Properties

◆ address

QByteArray QUnixSocketPrivate::address

◆ ancillaryBuffer

char* QUnixSocketPrivate::ancillaryBuffer

Definition at line 864 of file qunixsocket.cpp.

Referenced by QUnixSocket::setRightsBufferSize().

◆ ancillaryBufferCount

unsigned int QUnixSocketPrivate::ancillaryBufferCount

◆ closingTimer

int QUnixSocketPrivate::closingTimer

Definition at line 873 of file qunixsocket.cpp.

Referenced by QUnixSocket::abort(), and QUnixSocket::close().

◆ dataBuffer

char* QUnixSocketPrivate::dataBuffer

◆ dataBufferCapacity

unsigned int QUnixSocketPrivate::dataBufferCapacity

Definition at line 862 of file qunixsocket.cpp.

Referenced by QUnixSocket::readBufferSize(), and QUnixSocket::setReadBufferSize().

◆ dataBufferLength

unsigned int QUnixSocketPrivate::dataBufferLength

◆ error

QUnixSocket::SocketError QUnixSocketPrivate::error

◆ fd

int QUnixSocketPrivate::fd

◆ me

QUnixSocket* QUnixSocketPrivate::me

Definition at line 824 of file qunixsocket.cpp.

◆ message

::msghdr QUnixSocketPrivate::message

Definition at line 838 of file qunixsocket.cpp.

Referenced by QUnixSocket::read().

◆ messageValid

bool QUnixSocketPrivate::messageValid

Definition at line 837 of file qunixsocket.cpp.

Referenced by QUnixSocket::read(), and QUnixSocket::waitForReadyRead().

◆ readNotifier

QSocketNotifier* QUnixSocketPrivate::readNotifier

◆ state

QUnixSocket::SocketState QUnixSocketPrivate::state

◆ writeNotifier

QSocketNotifier* QUnixSocketPrivate::writeNotifier

◆ writeQueue

QQueue<QUnixSocketMessage> QUnixSocketPrivate::writeQueue

◆ writeQueueBytes

unsigned int QUnixSocketPrivate::writeQueueBytes

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