MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / client_test

Function client_test

extra/yassl/examples/client/client.cpp:64–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63
64void client_test(void* args)
65{
66#ifdef _WIN32
67 WSADATA wsd;
68 WSAStartup(0x0002, &wsd);
69#endif
70
71 SOCKET_T sockfd = 0;
72 int argc = 0;
73 char** argv = 0;
74
75 set_args(argc, argv, *static_cast<func_args*>(args));
76 tcp_connect(sockfd);
77#ifdef NON_BLOCKING
78 tcp_set_nonblocking(sockfd);
79#endif
80 SSL_METHOD* method = TLSv1_client_method();
81 SSL_CTX* ctx = SSL_CTX_new(method);
82
83 set_certs(ctx);
84 if (argc >= 2) {
85 printf("setting cipher list to %s\n", argv[1]);
86 if (SSL_CTX_set_cipher_list(ctx, argv[1]) != SSL_SUCCESS) {
87 ClientError(ctx, NULL, sockfd, "set_cipher_list error\n");
88 }
89 }
90 SSL* ssl = SSL_new(ctx);
91
92 SSL_set_fd(ssl, sockfd);
93
94
95#ifdef NON_BLOCKING
96 NonBlockingSSL_Connect(ssl, ctx, sockfd);
97#else
98 // if you get an error here see note at top of README
99 if (SSL_connect(ssl) != SSL_SUCCESS)
100 ClientError(ctx, ssl, sockfd, "SSL_connect failed");
101#endif
102 showPeer(ssl);
103
104 const char* cipher = 0;
105 int index = 0;
106 char list[1024];
107 strncpy(list, "cipherlist", 11);
108 while ( (cipher = SSL_get_cipher_list(ssl, index++)) ) {
109 strncat(list, ":", 2);
110 strncat(list, cipher, strlen(cipher) + 1);
111 }
112 printf("%s\n", list);
113 printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl));
114
115 char msg[] = "hello yassl!";
116 if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
117 ClientError(ctx, ssl, sockfd, "SSL_write failed");
118
119 char reply[1024];
120 int input = SSL_read(ssl, reply, sizeof(reply));
121 if (input > 0) {

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 15

set_argsFunction · 0.85
tcp_connectFunction · 0.85
tcp_set_nonblockingFunction · 0.85
TLSv1_client_methodFunction · 0.85
SSL_CTX_newFunction · 0.85
set_certsFunction · 0.85
SSL_CTX_set_cipher_listFunction · 0.85
ClientErrorFunction · 0.85
SSL_newFunction · 0.85
SSL_set_fdFunction · 0.85
NonBlockingSSL_ConnectFunction · 0.85
SSL_connectFunction · 0.85

Tested by 1

mainFunction · 0.68