https - Why does this SSL_pending call always return zero? -



https - Why does this SSL_pending call always return zero? -

this code https server using blocking sockets:

request := ''; start := gettickcount; repeat if ssl_pending(ssl) > 0 begin bytesin := ssl_read(ssl, buffer, sizeof(buffer)-1); if bytesin > 0 begin buffer[bytesin] := #0; request := request + buffer; end else break; // read failed end; // pending until (gettickcount - start) > largetimeout; // "request" ready, though perchance empty

ssl_pending() always returns 0 , ssl_read() never reached. if ssl_pending() phone call removed, ssl_read() executed. why doesn't ssl_pending() indicate how many bytes available?

note if phone call ssl_read() , number of bytes returned less buffer size, you've read , done.

if incoming info larger buffer size, first ssl_read() phone call fills buffer, , can repeat calling ssl_read() until can't fill buffer.

but if incoming info exact multiple of buffer size, lastly chunk of info fills buffer. if effort ssl_read() thinking there might more info on blocking socket, hangs indefinitely. hence want check ssl_pending() first. yet doesn't appear work.

how avoid hanging on final ssl_read()? (i can't imagine reply go non-blocking, since means never utilize ssl_read blocking.)

update: next works. apparently ssl_pending() doesn't work until after first ssl_read():

request := ''; repeat bytesin := ssl_read(ssl, buffer, sizeof(buffer)-1); if bytesin > 0 begin buffer[bytesin] := #0; request := request + buffer; end else break; // read failed until ssl_pending(ssl) <= 0; // "request" ready, though perchance empty

you using ssl_pending() wrong way. openssl uses state machine, ssl_pending() indicates if state machine has pending bytes have been buffered , awaiting processing. since never calling ssl_read(), never buffering info or advancing state machine.

https openssl winsock

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -