46 #ifdef QUNIXSOCKETSERVER_DEBUG 50 #include <QtCore/qsocketnotifier.h> 53 #include <sys/types.h> 54 #include <sys/socket.h> 60 #define UNIX_PATH_MAX 108 // From unix(7) 174 #ifdef QUNIXSOCKET_DEBUG 178 #ifdef QUNIXSOCKET_DEBUG 180 qDebug() <<
"QUnixSocketServer: Unable to close socket (" 181 << strerror(
errno) <<
')';
218 return (-1 !=
d->
fd);
250 d->
fd = ::socket(PF_UNIX, SOCK_STREAM, 0);
252 #ifdef QUNIXSOCKETSERVER_DEBUG 253 qDebug() <<
"QUnixSocketServer: Unable to create socket (" 254 << strerror(
errno) <<
')';
262 struct ::sockaddr_un addr;
263 addr.sun_family = AF_UNIX;
264 ::memcpy(addr.sun_path, path.
data(), path.
size());
266 addr.sun_path[path.
size()] =
'\0';
269 if(-1 == ::bind(
d->
fd, (sockaddr *)&addr,
sizeof(sockaddr_un))) {
270 #ifdef QUNIXSOCKETSERVER_DEBUG 271 qDebug() <<
"QUnixSocketServer: Unable to bind socket (" 272 << strerror(
errno) <<
')';
281 #ifdef QUNIXSOCKETSERVER_DEBUG 282 qDebug() <<
"QUnixSocketServer: Unable to listen socket (" 283 << strerror(
errno) <<
')';
295 d,
SLOT(acceptActivated()));
374 socklen_t len =
sizeof(sockaddr_un);
375 int connsock = ::accept(fd, (sockaddr *)&r, &len);
376 #ifdef QUNIXSOCKETSERVER_DEBUG 377 qDebug() <<
"QUnixSocketServer: Accept connection " << connsock;
380 me->incomingConnection(connsock);
385 #include "qunixsocketserver.moc" QSocketNotifier * acceptNotifier
virtual ~QUnixSocketServer()
Stops listening for incoming connection and destroys the Unix socket server.
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
void close()
Stop listening for incoming connections and resets the Unix socket server's state.
The QByteArray class provides an array of bytes.
bool listen(const QByteArray &path)
Tells the server to listen for incoming connections on path.
The QObject class is the base class of all Qt objects.
QUnixSocketServerPrivate(QUnixSocketServer *parent)
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
ServerError serverError() const
Returns the last server error.
QUnixSocketServerPrivate * d
Q_CORE_EXPORT void qDebug(const char *,...)
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setMaxPendingConnections(int numConnections)
Sets the maximum length the queue of pending connections may grow to numConnections.
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...
bool isListening() const
Returns true if this server is listening for incoming connections, false otherwise.
QUnixSocketServer(QObject *parent=0)
Create a new Unix socket server with the given parent.
int maxPendingConnections() const
Returns the maximum length the queue of pending connections may grow to.
QObject * parent() const
Returns a pointer to the parent object.
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
QUnixSocketServer::ServerError error
int size() const
Returns the number of bytes in this byte array.
The QUnixSocketServer class provides a Unix domain socket based server.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
friend class QUnixSocketServerPrivate
ServerError
The ServerError enumeration represents the errors that can occur during server establishment.
QByteArray serverAddress() const
Returns the Unix path on which this server is listening.
int socketDescriptor() const