本文整理汇总了C++中QLocalSocket::socketDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::socketDescriptor方法的具体用法?C++ QLocalSocket::socketDescriptor怎么用?C++ QLocalSocket::socketDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::socketDescriptor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clientConnected
AuthorizationRecord QJsonUIDAuthority::clientConnected(QJsonStream *stream)
{
AuthorizationRecord authRecord;
authRecord.state = QJsonAuthority::StateNotAuthorized;
if (!stream)
return authRecord;
QLocalSocket *socket = qobject_cast<QLocalSocket*>(stream->device());
if (!socket)
return authRecord;
if (socket->socketDescriptor() == (qintptr)-1) {
qWarning() << Q_FUNC_INFO << "no socket descriptor available for connection" << socket;
return authRecord;
}
uid_t euid;
#if defined(Q_OS_MAC)
gid_t egid;
if (::getpeereid(socket->socketDescriptor(), &euid, &egid) != 0) {
qWarning() << "getpeereid failed with errcode" << errno << socket->socketDescriptor();
return authRecord;
}
#else
// Check the UID table and return Authorized if appropriate.
struct ucred cr;
socklen_t len = sizeof(struct ucred);
if (::getsockopt(socket->socketDescriptor(), SOL_SOCKET, SO_PEERCRED, &cr, &len) != 0) {
qWarning() << "getsockopt failed with errcode" << errno << socket->socketDescriptor();
return authRecord;
}
euid = cr.uid;
#endif
if (m_nameForUid.contains(euid)) {
authRecord.identifier = m_nameForUid.value(euid);
authRecord.state = StateAuthorized;
}
return authRecord;
}
示例2: qt_waitforinput
int qt_waitforinput(void)
{
#ifdef USE_MOUSE
fd_set read_fds;
int stdin_fd = fileno(stdin);
int socket_fd = qt_socket.socketDescriptor();
if (!qt_initialized || (socket_fd < 0) || (qt_socket.state() != QLocalSocket::ConnectedState))
return getchar();
// Gnuplot event loop
do
{
// Watch file descriptors
FD_ZERO(&read_fds);
FD_SET(socket_fd, &read_fds);
if (!paused_for_mouse)
FD_SET(stdin_fd, &read_fds);
// Wait for input
if (select(socket_fd+1, &read_fds, NULL, NULL, NULL) < 0)
{
fprintf(stderr, "Qt terminal communication error: select() error\n");
break;
}
// Terminal event coming
if (FD_ISSET(socket_fd, &read_fds))
{
qt_socket.waitForReadyRead(-1);
while (qt_socket.bytesAvailable() >= sizeof(gp_event_t))
{
struct gp_event_t event;
qt_socket.read((char*) &event, sizeof(gp_event_t));
/// @todo don't process mouse move events if others are in the queue
if (qt_processTermEvent(&event))
return '\0'; // exit from paused_for_mouse
}
}
} while (paused_for_mouse || (!paused_for_mouse && !FD_ISSET(stdin_fd, &read_fds)));
#endif
return getchar();
}
示例3: readSocket
void QServer::readSocket()
{
//Pointer to the signal sender
QLocalSocket * socket = (QLocalSocket*)sender();
//Read all data on the socket & store it on a QByteArray
QByteArray block = socket->readAll();
//Data stream to easy read all data
QDataStream in(&block, QIODevice::ReadOnly);
in.setVersion(QDataStream::Qt_5_4);
while (!in.atEnd()) //loop needed cause some messages can come on a single packet
{
QString receiveString;
in >> receiveString;
receiveString.prepend(QString("%1 :: ").arg(socket->socketDescriptor()));
emit sms(receiveString);
}
}
示例4: qt_waitforinput
int qt_waitforinput(void)
{
#ifdef USE_MOUSE
fd_set read_fds;
int stdin_fd = fileno(stdin);
int socket_fd = qt_socket.socketDescriptor();
if (!qt_initialized || (socket_fd < 0) || (qt_socket.state() != QLocalSocket::ConnectedState))
return getchar();
// Gnuplot event loop
do
{
// Watch file descriptors
FD_ZERO(&read_fds);
FD_SET(socket_fd, &read_fds);
if (!paused_for_mouse)
FD_SET(stdin_fd, &read_fds);
// Wait for input
if (select(socket_fd+1, &read_fds, NULL, NULL, NULL) < 0)
{
// Display the error message except when Ctrl + C is pressed
if (errno != 4)
fprintf(stderr, "Qt terminal communication error: select() error %i %s\n", errno, strerror(errno));
break;
}
// Terminal event coming
if (FD_ISSET(socket_fd, &read_fds))
{
if (!(qt_socket.waitForReadyRead(-1))) {
// Must be a socket error; we need to restart qt_gnuplot
qDebug() << "Error: gnuplot_qt socket not responding";
qt_gnuplot_qtStarted = false;
return '\0';
}
// Temporary event for mouse move events. If several consecutive
// move events are received, only transmit the last one.
gp_event_t tempEvent;
tempEvent.type = -1;
if (qt_socket.bytesAvailable() < sizeof(gp_event_t)) {
qDebug() << "Error: short read from gnuplot_qt socket";
return '\0';
}
while (qt_socket.bytesAvailable() >= sizeof(gp_event_t))
{
struct gp_event_t event;
qt_socket.read((char*) &event, sizeof(gp_event_t));
// Delay move events
if (event.type == GE_motion)
tempEvent = event;
// Other events. Replay the last move event if present
else
{
if (tempEvent.type == GE_motion)
{
qt_processTermEvent(&tempEvent);
tempEvent.type = -1;
}
if (qt_processTermEvent(&event))
return '\0'; // exit from paused_for_mouse
}
}
// Replay move event
if (tempEvent.type == GE_motion)
qt_processTermEvent(&tempEvent);
}
} while (paused_for_mouse || (!paused_for_mouse && !FD_ISSET(stdin_fd, &read_fds)));
#endif
return getchar();
}