Qt 4.8
|
The QUnixSocketRights class encapsulates QUnixSocket rights data. More...
#include <qunixsocket_p.h>
Public Functions | |
int | dupFd () const |
Return a duplicate of the file descriptor contained in this object. More... | |
bool | isValid () const |
Returns true if this QUnixSocketRights instance is managing a valid file descriptor. More... | |
QUnixSocketRights & | operator= (const QUnixSocketRights &) |
Create a copy of other. More... | |
int | peekFd () const |
Returns the file descriptor contained in this object. More... | |
QUnixSocketRights (int) | |
Create a new QUnixSocketRights instance containing the file descriptor fd. More... | |
QUnixSocketRights (const QUnixSocketRights &) | |
Create a copy of other. More... | |
~QUnixSocketRights () | |
Destroys the QUnixSocketRights instance. More... | |
Private Functions | |
QUnixSocketRights (int, int) | |
Construct a QUnixSocketRights instance on fd without dup(2)'ing the file descriptor. More... | |
Properties | |
QSharedDataPointer< QUnixSocketRightsPrivate > | d |
Friends | |
class | QUnixSocket |
The QUnixSocketRights class encapsulates QUnixSocket rights data.
QUnixSocket allows you to transfer Unix file descriptors between processes. A file descriptor is referred to as "rights data" as it allows one process to transfer its right to access a resource to another.
The Unix system verifies resource permissions only when the resource is first opened. For example, consider a file on disk readable only by the user "qt". A process running as user "qt" will be able to open this file for reading. If, while the process was still reading from the file, the ownership was changed from user "qt" to user "root", the process would be allowed to continue reading from the file, even though attempting to reopen the file would be denied. Permissions are associated with special descriptors called file descriptors which are returned to a process after it initially opens a resource.
File descriptors can be duplicated within a process through the dup(2) system call. File descriptors can be passed between processes using the QUnixSocket class in the same way. Even though the receiving process never opened the resource directly, it has the same permissions to access it as the process that did.
Definition at line 73 of file qunixsocket_p.h.
QUnixSocketRights::QUnixSocketRights | ( | int | fd | ) |
Create a new QUnixSocketRights instance containing the file descriptor fd.
fd will be dup(2)'d internally, so the application is free to close fd following this call.
If the dup(2) fails, or you pass an invalid fd, an QUnixSocketRights::isValid(){invalid } object will be constructed.
QUnixSocketRights instances are immutable and the internal file descriptor will be shared between any copies made of this object. The system will close(2) the file descriptor once it is no longer needed.
Definition at line 163 of file qunixsocket.cpp.
QUnixSocketRights::~QUnixSocketRights | ( | ) |
Destroys the QUnixSocketRights instance.
Definition at line 198 of file qunixsocket.cpp.
QUnixSocketRights::QUnixSocketRights | ( | const QUnixSocketRights & | other | ) |
|
private |
Construct a QUnixSocketRights instance on fd without dup(2)'ing the file descriptor.
Definition at line 188 of file qunixsocket.cpp.
int QUnixSocketRights::dupFd | ( | ) | const |
Return a duplicate of the file descriptor contained in this object.
If this is an QUnixSocketRights::isValid(){invalid } object, or the dup(2) call fails, an invalid file descriptor (-1) will be returned.
Definition at line 238 of file qunixsocket.cpp.
bool QUnixSocketRights::isValid | ( | ) | const |
Returns true if this QUnixSocketRights instance is managing a valid file descriptor.
This method is equivalent to (-1 != peekFd()).
Definition at line 226 of file qunixsocket.cpp.
Referenced by QUnixSocketPrivate::writeActivated().
QUnixSocketRights & QUnixSocketRights::operator= | ( | const QUnixSocketRights & | other | ) |
int QUnixSocketRights::peekFd | ( | ) | const |
Returns the file descriptor contained in this object.
If this is an QUnixSocketRights::isValid(){invalid } object an invalid file descriptor (-1) will be returned.
The lifetime of this file descriptor is tied to the lifetime of the QUnixSocketRights instance. The file descriptor returned by this method may be close(2)'d when the QUnixSocketRights instance is destroyed. If you want to continue to use the file descriptor use QUnixSocketRights::dupFd() instead.
Definition at line 266 of file qunixsocket.cpp.
Referenced by QUnixSocketPrivate::writeActivated().
|
friend |
Definition at line 87 of file qunixsocket_p.h.
|
private |
Definition at line 89 of file qunixsocket_p.h.
Referenced by dupFd(), isValid(), operator=(), and peekFd().