相應的初始化後,這裏是一個無限循環,以服務傳入的HTTPS請求,但每個請求只有一個連接(假設請求只需要一個讀):改變這一行是否實現持久保持連接?
while TRUE do
begin // wait for incoming TCP connection
if listen(listen_socket, 100) 0 then continue; // listen failed
client_len := SizeOf(sa_cli);
sock := accept(listen_socket, @sa_cli, @client_len); // create socket for connection
if sock = INVALID_SOCKET then continue; // accept failed
ssl := SSL_new(ctx); // TCP connection ready, create ssl structure
if assigned(ssl) then
begin
SSL_set_fd(ssl, sock); // assign socket to ssl structure
if SSL_accept(ssl) = 1 then // handshake worked
begin
bytesin := SSL_read(ssl, buffer, sizeof(buffer)-1);
if bytesin > 0 then
begin
buffer[bytesin] := #0;
// decide on response here...
response := 'HTTP/1.0 200 OK'#13#10 + etc;
SSL_write(ssl, pchar(response)^, length(response));
end; // else read empty or failed
end; // else handshake failed
SSL_set_shutdown(ssl, SSL_SENT_SHUTDOWN or SSL_RECEIVED_SHUTDOWN);
CloseSocket(sock);
SSL_free(ssl);
end; // else ssl creation failed
end; // while
正在改變
if ssl_accept(ssl) = 1 then
到
while ssl_accept(ssl) = 1 do
所有這一切都需要正確支持默認的HTTP 1.1保持活動(即,每個c的多個請求onnection)?
假設整個請求將在一個讀呼叫滿足是導致失敗。 – EricLaw
這樣做僅僅是爲了保持代碼簡潔並且不會分散問題。 –