summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qlocalsocket_unix.cpp
diff options
context:
space:
mode:
authorCorentin Jabot <corentinjabot@gmail.com>2012-11-25 17:30:15 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-05 18:39:35 +0100
commit953255abab0f99afe7559da93ba18a876805d78d (patch)
tree953da560e670c135f2cd2e772c7f83ca2e9627d4 /src/network/socket/qlocalsocket_unix.cpp
parent866a5d0c28f458d50ab9e4f011fc7a94822ce6eb (diff)
Make QLocalSocket connectable with open()
Add getter and setter for handling the server QLocalSocket connects to. Move the connectServer() implementation to QLocalSocket::open so the local socket can be handled transparently as a QIODevice Add a convenient connectToServer(OpenMode) method Change-Id: Ibc8dc33f79903f92daf2d1ca2e64ead2ce39f33e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket/qlocalsocket_unix.cpp')
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index e846e43e73..67182e57b0 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -221,14 +221,14 @@ void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, co
q->emit stateChanged(state);
}
-void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
+bool QLocalSocket::open(OpenMode openMode)
{
Q_D(QLocalSocket);
if (state() == ConnectedState || state() == ConnectingState) {
QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
setErrorString(errorString);
emit error(QLocalSocket::OperationError);
- return;
+ return false;
}
d->errorString.clear();
@@ -236,17 +236,17 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
d->state = ConnectingState;
emit stateChanged(d->state);
- if (name.isEmpty()) {
+ if (d->serverName.isEmpty()) {
d->errorOccurred(ServerNotFoundError,
QLatin1String("QLocalSocket::connectToServer"));
- return;
+ return false;
}
// create the socket
if (-1 == (d->connectingSocket = qt_safe_socket(PF_UNIX, SOCK_STREAM, 0))) {
d->errorOccurred(UnsupportedSocketOperationError,
QLatin1String("QLocalSocket::connectToServer"));
- return;
+ return false;
}
// set non blocking so we can try to connect and it won't wait
int flags = fcntl(d->connectingSocket, F_GETFL, 0);
@@ -254,13 +254,14 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
|| -1 == (fcntl(d->connectingSocket, F_SETFL, flags | O_NONBLOCK))) {
d->errorOccurred(UnknownSocketError,
QLatin1String("QLocalSocket::connectToServer"));
- return;
+ return false;
}
// _q_connectToSocket does the actual connecting
- d->connectingName = name;
+ d->connectingName = d->serverName;
d->connectingOpenMode = openMode;
d->_q_connectToSocket();
+ return true;
}
/*!