SSL 서버를 만들려고 QTcpServer를 서브 클래스 화하고 incomingConnection()
을 재정의합니다. 여기에서 QSslSocket
을 만들고 설명자를 설정하고 QSslSocket::startServerEncryption
을 호출합니다. 이 시점에서 QSslSocket::encrypted()
신호가 방출 될 때까지 기다릴 필요가 있습니다. 그 후에야 내 서버가 newConnection()
신호를 방출해야합니다. 클라이언트 코드는 QTcpSocket을 사용하고 있다고 생각하지만 사실 안전한 소켓을 사용하게 될 것입니다. 항상newConnection()
incomingConnection()
를 호출 한 후 방출 QTcpServerQTcpServer를 서브 클래스화할 때 newConnection() 신호가 출력되는 것을 어떻게 지연시킬 수 있습니까?
그러나 은 (내가 the source of QTcpServer에서 보았다) :
그래서 내 질문은void QTcpServerPrivate::readNotification()
{
// .........
q->incomingConnection(descriptor);
QPointer<QTcpServer> that = q;
emit q->newConnection();
// .........
}
, 난 때까지 , 나는 newConnection()
발광에서 QTcpServer
을 방지 할 수있는 방법이 나 자신을 방출 할 준비가 되셨습니까?
I이 원하는 그 이유는 나는 그것이 QTcpServer으로 정확하게 행동해야한다, 그래서 내 클래스는, 그것을 사용하고 인식하지 못하는 코드에 의해, QTcpServer의 드롭 인 교체로 사용할 수 있도록하려는 것입니다 :
QTcpServer* getServer(bool ssl)
{
return ssl ? new SslServer : new QTcpServer;
}
SslServer 클래스 내 코드는 현재 이것이다 : 당신이 일반적으로 구현할 수 없기 때문에, 당신은 아마, Qt를의 실제 소스를 편집해야합니다
void SslServer::ready()
{
QSslSocket *socket = (QSslSocket *) sender();
addPendingConnection(socket);
emit newConnection();
}
void SslServer::incomingConnection(int socketDescriptor)
{
QSslSocket *serverSocket = new QSslSocket;
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
serverSocket->startServerEncryption();
} else {
delete serverSocket;
}
}
신호를 분리하고 나중에 다시 연결하면 어떨까요? 가능한가? 그리고 아니오, 확실히 Qt 소스를 다시 쓸 필요가 없습니다. – sashoalm
시도해 볼 수 있습니다 : ['QObject :: disconnect'] (http://qt-project.org/doc/qt-4.8/qobject.html#disconnect). 나는 그것을 잘 알기에 충분하지 못했다. – phyatt
문제는 나중에 신호를 다시 연결해야하므로 신호에 대한 수신기 목록을 어떻게 든 가져와야합니다. 저는 이것을 새로운 질문으로 게시하고 있습니다 - http://stackoverflow.com/q/14144415/492336. – sashoalm