Looks like your code is impatient.
When you get continue, 4 retries won't be enough to
get the next response.
Basically, if you get an SSL_ERROR_WANT_READ, you
just need to keep continuing to retry the SSL_read, if you expect more data that
is. So, if you expect a server response, keep trying till you get some (you may
want to hack in a timeout there), then process the response. If it's a continue,
discard it and just start again reading till you get some...
- Original Message -
From:
Lin Ma
To: '[EMAIL PROTECTED]'
Cc: Lin Ma
Sent: Wednesday, October 30, 2002 11:17
PM
Subject: SSL_read() hang after read http
100 continue headers
Hi,My program is using
OpenSSL function SSL_read() to read http content.It works fine for most of
the headers, but after it receives HTTP/1.1100 Continue header (the first block of headers), it will hang
there. It shouldcontinue to read
the headers (which is HTTP/1.1 200 OK...). The following is the headerdumping
and the code I used. The http equivalent code works fine.After the first block of headers, it should
continually read the 2nd block of headers.
Is it
because after the first block of header (see the following), the
terminators0d 0a 0d 0a confused SSL_read? or the terminators are
the same as SSL block terminator? How can I get around it?
This is the first
block of headers
HTTP/1.1
100 Continue
Server:
Microsoft-IIS/5.0Date:Wed, 30 Oct
2002 06:34:56
GMT
Can
you help me?Thank
you.while (Retries = 4 ){len =
strlen(buf); printf("before
SSL_read(), buf len=%d\n",
len);r=SSL_read(Connect-ssl,buf,100);err =
SSL_get_error(Connect-ssl, r);printf("r=%d, err=%d\n", r,
err);if (err == SSL_ERROR_NONE) bytes =
r;if (err != SSL_ERROR_NONE err != SSL_ERROR_WANT_READ
err ==SSL_ERROR_ZERO_RETURN){printf("
SSL_ERROR_ZERO_RETURN\n");break;}if (err != SSL_ERROR_NONE
err != SSL_ERROR_WANT_READ err
==SSL_ERROR_SYSCALL){printf("
SSL_ERROR_SYSCALL\n");break;}if (err != SSL_ERROR_NONE
err != SSL_ERROR_WANT_READ err !=SSL_ERROR_SYSCALL
err != SSL_ERROR_ZERO_RETURN){printf("Reading header, SSL
read problem\n");break;}if (bytes 0
Control-AGW==1) {printf("read returned -1 (Error %d), returning
...\n", errno);break;}else if (bytes == 0)
{Retries++;}else if (bytes 0){buf[bytes] =
'\0';printf("read %d bytes, buf={%s}\n", bytes, buf);}}
0x | 48 54 54 50 2f 31 2e 31 20 31 30 30 20 43 6f 6e
|HTTP/1.1 100 Con0x0010 | 74 69 6e 75 65 0d 0a 53 65 72 76 65 72 3a 20
4d |tinue..Server: M0x0020 | 69 63 72 6f 73 6f 66 74 2d 49 49 53 2f 35
2e 30 |icrosoft-IIS/5.00x0030 | 0d 0a 44 61 74 65 3a 20 57 65 64 2c 20
33 30 20 | ..Date:Wed, 300x0040 | 4f 63 74 20 32 30 30 32 20 30 36 3a
33 34 3a 35 | Oct 2002
06:34:50x0050 | 36 20 47 4d 54 0d 0a 0d
0a
| 6 GMT0x | 48 54 54
50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d |HTTP/1.1 200 OK.0x0010 | 0a 53
65 72 76 65 72 3a 20 4d 69 63 72 6f 73 6f |.Server: Microso0x0020 | 66
74 2d 49 49 53 2f 35 2e 30 0d 0a 44 61 74 65 |ft-IIS/5.0..Date0x0030 |
3a 20 57 65 64 2c 20 33 30 20 4f 63 74 20 32 30 | : Wed,30 Oct
200x0040 | 30 32 20 30 36 3a 33 35 3a 30 37 20 47 4d 54 0d | 02 06:35:07 GMT.0x0050 | 0a 43 6f 6e 74
65 6e 74 2d 4c 65 6e 67 74 68 3a |.Content-Length:0x0060 | 20 31 38 36
33 0d 0a 43 6f 6e 74 65 6e 74 2d 54 |1863..Content-T0x0070 | 79 70 65
3a 20 74 65 78 74 2f 68 74 6d 6c 0d 0a | ype:text/html..0x0080 | 45 78
70 69 72 65 73 3a 20 57 65 64 2c 20 33 30 |Expires: Wed, 300x0090 | 20
4f 63 74 20 32 30 30 32 20 30 36 3a 33 35 3a | Oct 2002 06:35:0x00a0 | 30 37 20 47 4d 54
0d 0a 43 61 63 68 65 2d 63 6f | 07
GMT..Cache-co0x00b0 | 6e 74 72 6f 6c 3a 20 70 72 69 76 61 74 65
0d 0a | ntrol:
private..