Skip to content

Commit e56a995

Browse files
committed
Show SSL handshake time
1 parent 639098a commit e56a995

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

httpsget.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <ctype.h>
1111
#include "ssl.h"
1212
#include "iconv/iconv_mini.h"
13+
#ifdef __human68k__
14+
#include <x68k/iocs.h>
15+
#endif
1316

1417
char request[65536];
1518
char response[65536];
@@ -350,15 +353,28 @@ int main(int argc, char **argv)
350353

351354
printf("Connected to server successfully\n");
352355

356+
#ifdef __human68k__
357+
struct iocs_time tm1, tm2;
358+
tm1 = _iocs_ontime();
359+
#endif
353360

354361
SSL_CTX *ssl_ctx = ssl_ctx_new(SSL_SERVER_VERIFY_LATER, SSL_DEFAULT_CLNT_SESS);
355362
SSL_EXTENSIONS *ext = ssl_ext_new();
356363
SSL *ssl_sock = ssl_client_new(ssl_ctx, client_fd, NULL, 0, ext);
357364

365+
#ifdef __human68k__
366+
tm2 = _iocs_ontime();
367+
printf("Handshake time: %d ms\n", (tm2.sec - tm1.sec) * 10);
368+
#endif
369+
358370
int r = ssl_handshake_status(ssl_sock);
359371
printf("Handshake status: %d\n", r);
360-
361-
372+
if (r != SSL_OK) {
373+
ssl_free(ssl_sock);
374+
ssl_ctx_free(ssl_ctx);
375+
close(client_fd);
376+
return 1;
377+
}
362378

363379
// HTTP GETリクエストの作成
364380
snprintf(request, sizeof(request),
@@ -414,11 +430,17 @@ int main(int argc, char **argv)
414430
buffer = realloc(buffer, buffer_size);
415431
strcat(buffer, ptr);
416432
}
433+
putchar('.');
434+
fflush(stdout);
417435
}
436+
putchar('\n');
418437

419438
ssl_free(ssl_sock);
420439
ssl_ctx_free(ssl_ctx);
421440

441+
// HTML実体参照をデコード
442+
decode_html_entities((char *)buffer);
443+
422444
// printf("%s", buffer);
423445

424446
uint8_t *sbuffer = malloc(buffer_size);
@@ -439,9 +461,6 @@ int main(int argc, char **argv)
439461

440462
char *html_body = extract_html_body((char *)sbuffer);
441463

442-
// HTML実体参照をデコード
443-
decode_html_entities((char *)sbuffer);
444-
445464
fwrite(sbuffer, 1, html_body - (char *)sbuffer, stdout);
446465

447466
parse_html(html_body);

0 commit comments

Comments
 (0)