This is likely due to the double calls of BIO_do_accept ().
I took the OpenSSL S_SERVER.C code, made some changes and stuck it to a simpler version below. It works on Vista and Windows 7! It uses a completely different set of BIO calls from the above problem code, non-blocking jobs, and (unlike S_SERVER.C and most server examples on the network). Google Chrome ports are properly captured through timeouts to question 7054471 .
program s_server; uses sysutils, winsock, windows; const SSLEAY32DLL = 'ssleay32.dll'; SSL_FILETYPE_PEM = 1; SSL_SENT_SHUTDOWN = 1; SSL_RECEIVED_SHUTDOWN = 2; function BIO_f_ssl: pointer; cdecl; external SSLEAY32DLL; function SSL_CTX_check_private_key(ctx: pointer): BOOL; cdecl; external SSLEAY32DLL; function SSL_CTX_ctrl(ctx: pointer; cmd, i: integer; p: pointer): integer; cdecl; external SSLEAY32DLL; procedure SSL_CTX_free(ctx: pointer); cdecl; external SSLEAY32DLL; function SSL_CTX_new(meth: pointer): pointer; cdecl; external SSLEAY32DLL; procedure SSL_CTX_set_quiet_shutdown(ctx: pointer; mode: integer); cdecl; external SSLEAY32DLL; function SSL_CTX_use_certificate_chain_file(ctx: pointer; fname: pchar): integer; cdecl; external SSLEAY32DLL; function SSL_CTX_use_PrivateKey_file(ctx: pointer; fname: pchar; itype: integer): integer; cdecl; external SSLEAY32DLL; procedure SSL_library_init; cdecl; external SSLEAY32DLL; procedure SSL_load_error_strings; cdecl; external SSLEAY32DLL; function SSL_new(ctx: pointer): pointer; cdecl; external SSLEAY32DLL; procedure SSL_set_accept_state(b: pointer); cdecl; external SSLEAY32DLL; procedure SSL_set_bio(ssl, readbio, writebio: pointer); cdecl; external SSLEAY32DLL; procedure SSL_set_shutdown(ssl: pointer; mode: integer); cdecl; external SSLEAY32DLL; function SSLv23_server_method: pointer; cdecl; external SSLEAY32DLL; const LIBEAY32DLL = 'libeay32.dll'; BIO_NOCLOSE = $00; BIO_CLOSE = $01; function BIO_ctrl(bp: pointer; cmd: integer; larg: integer; parg: pointer): integer; cdecl; external LIBEAY32DLL; function BIO_f_buffer: pointer; cdecl; external LIBEAY32DLL; procedure BIO_free_all(bp: pointer); cdecl; external LIBEAY32DLL; function BIO_gets(b: pointer; buf: pchar; size: integer): integer; cdecl; external LIBEAY32DLL; function BIO_int_ctrl(bp: pointer; cmd: integer; i1, i2: integer): integer; cdecl; external LIBEAY32DLL; function BIO_new(t: pointer): pointer; cdecl; external LIBEAY32DLL; function BIO_new_socket(sock, flag: integer): pointer; cdecl; external LIBEAY32DLL; function BIO_push(b: pointer; append: pointer): pointer; cdecl; external LIBEAY32DLL; function BIO_socket_ioctl(sock: integer; ctl: cardinal; p: pointer): integer; cdecl; external LIBEAY32DLL; function BIO_test_flags(bp: pointer; flags: integer): integer; cdecl; external LIBEAY32DLL; function BIO_write(bp, buffer: pointer; size: integer): integer; cdecl; external LIBEAY32DLL; procedure OPENSSL_load_builtin_modules; cdecl; external LIBEAY32DLL; function BIO_flush(b: pointer): integer; const BIO_CTRL_FLUSH = 11; begin result := BIO_ctrl(b, BIO_CTRL_FLUSH, 0, nil); end; function BIO_set_ssl(b, ssl: pointer; c: integer): integer; const BIO_C_SET_SSL = 109; begin result := BIO_ctrl(b, BIO_C_SET_SSL, c, ssl); end; function BIO_should_retry(b: pointer): boolean; const BIO_FLAGS_SHOULD_RETRY = 8; begin result := BIO_test_flags(b, BIO_FLAGS_SHOULD_RETRY) <> 0; end; function SSL_CTX_set_options(ctx: pointer; op: integer): integer; const SSL_CTRL_OPTIONS = 32; begin result := SSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, op, nil); end; procedure confirm(b: boolean); begin {$WARN SYMBOL_PLATFORM OFF} win32check(b); {$WARN SYMBOL_PLATFORM ON} end; const DEFAULTPORT = 443; MAXWAIT = 500;
source share