MCPcopy Create free account
hub / github.com/MITK/MITK / sendMessage

Method sendMessage

Utilities/qtsingleapplication/qtlocalpeer.cpp:134–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134bool QtLocalPeer::sendMessage(const QByteArray &message, int timeout)
135{
136 if (!isClient())
137 return false;
138
139 QLocalSocket socket;
140 bool connOk = false;
141 for (int i = 0; i < 2; i++)
142 {
143 // Try twice, in case the other instance is just starting up
144 socket.connectToServer(socketName);
145 connOk = socket.waitForConnected(timeout / 2);
146 if (connOk || i)
147 break;
148 int ms = 250;
149#if defined(Q_OS_WIN)
150 Sleep(DWORD(ms));
151#else
152 struct timespec ts = {ms / 1000, (ms % 1000) * 1000 * 1000};
153 nanosleep(&ts, nullptr);
154#endif
155 }
156 if (!connOk)
157 return false;
158
159 QDataStream ds(&socket);
160 ds.writeBytes(message.constData(), message.size());
161 bool res = socket.waitForBytesWritten(timeout);
162 if (res)
163 {
164 res &= socket.waitForReadyRead(timeout); // wait for ack
165 if (res)
166 res &= (socket.read(qstrlen(ack)) == ack);
167 }
168 return res;
169}
170
171void QtLocalPeer::receiveConnection()
172{

Callers 1

handleNewAppInstanceFunction · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected