0

After I've called QSslSocket::startServerEncryption(), can I proceed to immediately use the socket as an ordinary QTcpSocket, reading and writing data from it, or do I need to call waitForStartEncrypted() before using it?

socket->startServerEncryption();
socket->waitForEncrypted(); // <==== Is this line necessary?
socket->write(data);
QByteArray response = socket->read();
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

0

You can start to use it immediately. The data will be buffered and sent later. Note that you can't read any data from it yet, since none will have arrived. The actual connection and handshake will not occur until you enter the event loop.

Richard Moore
  • 441
  • 3
  • 3
  • OK, but my FTP server just blocks when I don't call `waitForEncrypted()` for the data connection. When I do call it right after `startServerEncryption()` it does works fine. But according to the documentation, as I've read, `waitForEncrypted()` shouldn't be needed! – sashoalm Mar 02 '13 at 12:24
  • You have to make sure you re-enter the main event loop otherwise your data will not get transmitted. – Richard Moore Mar 02 '13 at 16:43
  • When, between `socket->startServerEncryption()` and any reading or writing of data? And `socket->waitForEncrypted()` doesn't really reenter the event loop, it just blocks, right? But it still makes the code working. – sashoalm Mar 02 '13 at 20:08
  • socket->waitForEncrypted() creates a nested event loop - it appears to block from the callers point of view, but underneath it does not. – Richard Moore Mar 02 '13 at 20:52
  • I tried using `socket->waitForEncrypted(0)` right after `socket->startServerEncryption()`, but it didn't help, so just entering the event loop briefly isn't enough. – sashoalm Mar 07 '13 at 15:02