Originally Posted by
d_stranz
Instead of creating your QSslSocket instance in the MySslClient constructor, create it in the same thread where you create the MySslClient instance and pass the pointer in as an additional argument to the MySslClient constructor. Basically, any QObjects that have a parent-child relationship all must be created in the same thread. So any children of MySslClient have to be created in the same thread where the MySslClient instance (and its parent QObject) are created.
Unfortunately, it didn’t work out. I get gRPC helloworld example https://github.com/plasticbox/grpc-w...helloworld/src
class GreeterServiceImpl final : public Greeter::Service {
public:
// begin attempt 1
QSslSocket* mSocket;
void setSslSocket(QSslSocket *socket = nullptr) {
mSocket = socket;
}
// end attemt 1
Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
// begin attemt 1
QSslConfiguration config = mSocket->sslConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::SecureProtocols);
mSocket->setSslConfiguration(config);
mSocket->connectToHostEncrypted("google.com", 8080);
// end attemt 1
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
return Status::OK;
}
};
class GreeterServiceImpl final : public Greeter::Service {
public:
// begin attempt 1
QSslSocket* mSocket;
void setSslSocket(QSslSocket *socket = nullptr) {
mSocket = socket;
}
// end attemt 1
Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
// begin attemt 1
QSslConfiguration config = mSocket->sslConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::SecureProtocols);
mSocket->setSslConfiguration(config);
mSocket->connectToHostEncrypted("google.com", 8080);
// end attemt 1
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
return Status::OK;
}
};
To copy to clipboard, switch view to plain text mode
void RunServer() {
std::string server_address("0.0.0.0:50051");
GreeterServiceImpl service;
// begin attemt 1
QSslSocket* sok = new QSslSocket;
service.setSslSocket(sok);
// end attemt 1
...
server->Wait();
}
int main(int argc, char** argv) {
RunServer();
return a.exec();
}
void RunServer() {
std::string server_address("0.0.0.0:50051");
GreeterServiceImpl service;
// begin attemt 1
QSslSocket* sok = new QSslSocket;
service.setSslSocket(sok);
// end attemt 1
...
server->Wait();
}
int main(int argc, char** argv) {
QCoreApplication a(argc, argv);
RunServer();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
$ ./server
Server listening on 0.0.0.0:50051
QObject: Cannot create children
for a parent that is in a different thread.
(Parent is QSslSocket(0x56117c127520), parent's thread is QThread(0x56117c120800), current thread is QThread(0x7fa828004510)
^C
$ ./server
Server listening on 0.0.0.0:50051
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QSslSocket(0x56117c127520), parent's thread is QThread(0x56117c120800), current thread is QThread(0x7fa828004510)
^C
To copy to clipboard, switch view to plain text mode
Bookmarks