Changeset View
Changeset View
Standalone View
Standalone View
src/core/connection.cpp
Show All 29 Lines | |||||
30 | #include <QElapsedTimer> | 30 | #include <QElapsedTimer> | ||
31 | #include <QApplication> | 31 | #include <QApplication> | ||
32 | #include <QDateTime> | 32 | #include <QDateTime> | ||
33 | 33 | | |||
34 | #include <private/xdgbasedirs_p.h> | 34 | #include <private/xdgbasedirs_p.h> | ||
35 | #include <private/protocol_exception_p.h> | 35 | #include <private/protocol_exception_p.h> | ||
36 | #include <private/standarddirs_p.h> | 36 | #include <private/standarddirs_p.h> | ||
37 | 37 | | |||
38 | #ifdef Q_OS_FREEBSD | ||||
39 | #include <sys/types.h> | ||||
40 | #include <sys/socket.h> | ||||
41 | | ||||
42 | void adjustSocketBuffer( int real_fd ) | ||||
43 | { | ||||
44 | int so_data = 0; | ||||
45 | socklen_t so_len = sizeof(so_data); | ||||
46 | int r = getsockopt(real_fd, SOL_SOCKET, SO_SNDBUF, &so_data, &so_len); | ||||
47 | qDebug() << "SNDBUF" << r << so_data; | ||||
48 | if (!r && (so_data < 65536)) | ||||
49 | { | ||||
50 | so_data = 65536; | ||||
51 | r = setsockopt(real_fd, SOL_SOCKET, SO_SNDBUF, &so_data, sizeof(so_data)); | ||||
52 | if (r) | ||||
53 | qCDebug(AKONADICORE_LOG) << "Could not enlarge send buffer" << r; | ||||
54 | } | ||||
55 | r = getsockopt(real_fd, SOL_SOCKET, SO_SNDBUF, &so_data, &so_len); | ||||
56 | qDebug() << "SNDBUF" << r << so_data; | ||||
57 | | ||||
58 | r = getsockopt(real_fd, SOL_SOCKET, SO_RCVBUF, &so_data, &so_len); | ||||
59 | qDebug() << "RCVBUF" << r << so_data; | ||||
60 | if (!r && (so_data < 65536)) | ||||
61 | { | ||||
62 | so_data = 65536; | ||||
63 | r = setsockopt(real_fd, SOL_SOCKET, SO_RCVBUF, &so_data, sizeof(so_data)); | ||||
64 | if (r) | ||||
65 | qCDebug(AKONADICORE_LOG) << "Could not enlarge recv buffer" << r; | ||||
66 | } | ||||
67 | r = getsockopt(real_fd, SOL_SOCKET, SO_RCVBUF, &so_data, &so_len); | ||||
68 | qDebug() << "RCVBUF" << r << so_data; | ||||
69 | } | ||||
70 | | ||||
71 | static void _adjustSocketBuffer( QLocalSocket* sock ) | ||||
72 | { | ||||
73 | qintptr fd = sock->socketDescriptor(); | ||||
74 | int real_fd = static_cast<int>(fd); | ||||
75 | if ((fd != -1) && (real_fd >= 0)) | ||||
76 | { | ||||
77 | adjustSocketBuffer( real_fd ); | ||||
78 | } | ||||
79 | else | ||||
80 | qDebug() << "No socket descriptor." << fd << real_fd; | ||||
81 | qDebug() << "Qreadbuf" << sock->readBufferSize(); | ||||
82 | if (sock->readBufferSize() < 65536) | ||||
83 | sock->setReadBufferSize(65536); | ||||
84 | qDebug() << "Qreadbuf" << sock->readBufferSize(); | ||||
85 | } | ||||
86 | #endif | ||||
87 | | ||||
38 | using namespace Akonadi; | 88 | using namespace Akonadi; | ||
39 | 89 | | |||
40 | Connection::Connection(ConnectionType connType, const QByteArray &sessionId, QObject *parent) | 90 | Connection::Connection(ConnectionType connType, const QByteArray &sessionId, QObject *parent) | ||
41 | : QObject(parent) | 91 | : QObject(parent) | ||
42 | , mConnectionType(connType) | 92 | , mConnectionType(connType) | ||
43 | , mSocket(nullptr) | 93 | , mSocket(nullptr) | ||
44 | , mLogFile(nullptr) | 94 | , mLogFile(nullptr) | ||
45 | , mSessionId(sessionId) | 95 | , mSessionId(sessionId) | ||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 192 | if (!mSocket) { | |||
144 | connect(mSocket, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(&QLocalSocket::error), this, | 194 | connect(mSocket, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(&QLocalSocket::error), this, | ||
145 | [this](QLocalSocket::LocalSocketError) { | 195 | [this](QLocalSocket::LocalSocketError) { | ||
146 | qCWarning(AKONADICORE_LOG) << mSocket->errorString() << mSocket->serverName(); | 196 | qCWarning(AKONADICORE_LOG) << mSocket->errorString() << mSocket->serverName(); | ||
147 | Q_EMIT socketError(mSocket->errorString()); | 197 | Q_EMIT socketError(mSocket->errorString()); | ||
148 | Q_EMIT socketDisconnected(); | 198 | Q_EMIT socketDisconnected(); | ||
149 | }); | 199 | }); | ||
150 | connect(mSocket, &QLocalSocket::disconnected, this, &Connection::socketDisconnected); | 200 | connect(mSocket, &QLocalSocket::disconnected, this, &Connection::socketDisconnected); | ||
151 | connect(mSocket, &QLocalSocket::readyRead, this, &Connection::dataReceived); | 201 | connect(mSocket, &QLocalSocket::readyRead, this, &Connection::dataReceived); | ||
202 | #ifdef Q_OS_FREEBSD | ||||
203 | connect(mSocket, static_cast<void(QLocalSocket::*)()>(&QLocalSocket::connected), this, | ||||
204 | [this]() | ||||
205 | { | ||||
206 | qDebug() << "Connected"; | ||||
207 | _adjustSocketBuffer(mSocket); | ||||
208 | }); | ||||
209 | connect(mSocket, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketState)>(&QLocalSocket::stateChanged), this, | ||||
210 | [this](QLocalSocket::LocalSocketState state) | ||||
211 | { | ||||
212 | qDebug() << "StateChange" << state; | ||||
213 | if ((state == QLocalSocket::ConnectingState) || (state == QLocalSocket::ConnectedState)) | ||||
214 | _adjustSocketBuffer(mSocket); | ||||
215 | }); | ||||
216 | #endif | ||||
152 | } | 217 | } | ||
153 | 218 | | |||
154 | // actually do connect | 219 | // actually do connect | ||
155 | qCDebug(AKONADICORE_LOG) << "connectToServer" << serverAddress; | 220 | qCDebug(AKONADICORE_LOG) << "connectToServer" << serverAddress; | ||
156 | mSocket->connectToServer(serverAddress); | 221 | mSocket->connectToServer(serverAddress); | ||
157 | 222 | | |||
158 | Q_EMIT reconnected(); | 223 | Q_EMIT reconnected(); | ||
159 | } | 224 | } | ||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |