本文整理汇总了C++中connection::Ptr::SetCertificateKeyPair方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::SetCertificateKeyPair方法的具体用法?C++ Ptr::SetCertificateKeyPair怎么用?C++ Ptr::SetCertificateKeyPair使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection::Ptr
的用法示例。
在下文中一共展示了Ptr::SetCertificateKeyPair方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// Create our TCP listener socket.
auto listener = sfn::TcpListener::Create();
// Listen on 0.0.0.0:443
listener->Listen( sfn::Endpoint{ sfn::IpAddress{ "0.0.0.0" }, 443 } );
// Start 3 network processing threads.
sfn::Start( 3 );
// Just to make our lives easier...
typedef sfn::TlsConnection<sfn::TcpSocket, sfn::TlsEndpointType::Server, sfn::TlsVerificationType::None> Connection;
// A place to store all active connections.
std::deque<Connection::Ptr> connections;
const std::string certificate_string =
"-----BEGIN CERTIFICATE-----\r\n"
"MIIDPjCCAiagAwIBAgIBAjANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJGUjEO\r\n"
"MAwGA1UEBxMFUGFyaXMxDjAMBgNVBAoTBVh5U1NMMRYwFAYDVQQDEw1YeVNTTCBU\r\n"
"ZXN0IENBMB4XDTA3MDcwNzA1MDEyOVoXDTA4MDcwNjA1MDEyOVowMTELMAkGA1UE\r\n"
"BhMCRlIxDjAMBgNVBAoTBVh5U1NMMRIwEAYDVQQDEwlsb2NhbGhvc3QwggEiMA0G\r\n"
"CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC40PDcGTgmHkt6noXDfkjVuymjiNYB\r\n"
"gjtiL7uA1Ke3tXStacEecQek/OJxYqYr7ffcWalS29LL6HbKpi0xLZKBbD9ACkDh\r\n"
"1Z/SvHlyQPILJdYb9DMw+kzZds5myXUjzn7Aem1YjoxMZUAMyc34i2900X2pL0v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YrqqZFq\r\n"
"d4zp+E6h5oLBgCGkbFgimrH9evhM6GJqDjqMwxqmEB46/Di3UrZEPOI5AoGBALI8\r\n"
"IJTSDG7D+jWN1rYLFtnL0SZT96sRfT37Sf5M59ClIQ+r/P1ZrEAVj0t+x1nRmS2h\r\n"
"4eZrVs10veLoDcNYAzdhJDNAxE+bM5aepfFyCgIGaW/OTNp4uM7mmEygtAcmaZp+\r\n"
"+4Ibq7Gi/cXweLcvIdQXZzyTScvq5yYne+O7O7gBAoGAFIBIwAlLrcz1QkHURrPL\r\n"
"a/Y1bDTgKbM3FR9ase4ql38LaKThAq7SxE6v0qeQODHESGMObuVeGVbXY9TjbI5G\r\n"
"y3kjcRprUJ+Lgo8Wf+jO36I0FivN3xPK+duqR0QKXT4bYWj8RHg1EK/trbhY0Sw4\r\n"
"wbMZGrDlydImuNtktgxojIo=\r\n"
"-----END PRIVATE KEY-----\r\n";
// Load the certificate and key
auto certificate = sfn::TlsCertificate::Create( certificate_string );
auto key = sfn::TlsKey::Create( key_string );
std::atomic_bool exit{ false };
std::cout << "Press ENTER to exit.\n";
// Don't use sfn::Thread for your own projects, it is not what you think it is.
sfn::Thread exit_handler( [&]() { std::cin.get(); exit = true; } );
while( !exit ) {
{
Connection::Ptr connection;
// Dequeue any connections from the listener.
while( ( connection = listener->GetPendingConnection<Connection>() ) ) {
// Set the server certificate and key pair.
connection->SetCertificateKeyPair( certificate, key );
// Turn of connection lingering.
connection->SetLinger( 0 );
char response[] =
"HTTP/1.1 200 OK\r\n"
"Server: SFNUL HTTPS Server\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
"Connection: close\r\n\r\n"
"<html><head><title>SFNUL HTTPS Server Page</title></head>"
"<body>SFNUL HTTPS Server Document</body></html>\r\n\r\n";
// Send the HTTP response.
connection->Send( response, sizeof( response ) - 1 );
//.........这里部分代码省略.........