@@ -174,14 +174,14 @@ static int handle_ssl_error(php_stream *stream, int nr_bytes, zend_bool is_init
174
174
return retry ;
175
175
}
176
176
177
- static size_t php_openssl_sockop_write (php_stream * stream , const char * buf , size_t count TSRMLS_DC )
177
+ static size_t php_openssl_sockop_read (php_stream * stream , char * buf , size_t count TSRMLS_DC )
178
178
{
179
- return php_openssl_sockop_io ( 0 , stream , buf , count TSRMLS_CC );
179
+ return php_openssl_sockop_io (1 , stream , buf , count TSRMLS_CC );
180
180
}
181
181
182
- static size_t php_openssl_sockop_read (php_stream * stream , char * buf , size_t count TSRMLS_DC )
182
+ static size_t php_openssl_sockop_write (php_stream * stream , const char * buf , size_t count TSRMLS_DC )
183
183
{
184
- return php_openssl_sockop_io ( 1 , stream , buf , count TSRMLS_CC );
184
+ return php_openssl_sockop_io (0 , stream , ( char * ) buf , count TSRMLS_CC );
185
185
}
186
186
187
187
/**
@@ -194,15 +194,15 @@ static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t coun
194
194
static size_t php_openssl_sockop_io (int read , php_stream * stream , char * buf , size_t count TSRMLS_DC )
195
195
{
196
196
php_openssl_netstream_data_t * sslsock = (php_openssl_netstream_data_t * )stream -> abstract ;
197
- int nr_bytes = 0 ;
197
+ int nr_bytes = 0 ;
198
198
199
- /* Only do this if SSL is active. */
199
+ /* Only do this if SSL is active. */
200
200
if (sslsock -> ssl_active ) {
201
201
int retry = 1 ;
202
- struct timeval start_time ,
203
- * timeout ;
204
- int blocked = sslsock -> s .is_blocked ,
205
- has_timeout = 0 ;
202
+ struct timeval start_time ;
203
+ struct timeval * timeout ;
204
+ int blocked = sslsock -> s .is_blocked ;
205
+ int has_timeout = 0 ;
206
206
207
207
/* Begin by making the socket non-blocking. This allows us to check the timeout. */
208
208
if (SUCCESS == php_set_sock_blocking (sslsock -> s .socket , 0 TSRMLS_CC )) {
@@ -216,7 +216,7 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
216
216
/* gettimeofday is not monotonic; using it here is not strictly correct */
217
217
if (has_timeout ) {
218
218
gettimeofday (& start_time , NULL );
219
- }
219
+ }
220
220
221
221
/* Main IO loop. */
222
222
do {
@@ -263,7 +263,7 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
263
263
if (errno == EAGAIN && err == SSL_ERROR_WANT_READ && read ) {
264
264
retry = 1 ;
265
265
}
266
- if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0 ) {
266
+ if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0 ) {
267
267
retry = 1 ;
268
268
}
269
269
@@ -289,18 +289,20 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
289
289
int err = SSL_get_error (sslsock -> ssl_handle , nr_bytes );
290
290
291
291
/* If we didn't get any error, then let's return it to PHP. */
292
- if (err == SSL_ERROR_NONE )
293
- break ;
292
+ if (err == SSL_ERROR_NONE ) {
293
+ break ;
294
+ }
294
295
295
296
/* Otherwise, we need to wait again (up to time_left or we get an error) */
296
- if (blocked )
297
+ if (blocked ) {
297
298
if (read ) {
298
299
php_pollfd_for (sslsock -> s .socket , (err == SSL_ERROR_WANT_WRITE ) ?
299
300
(POLLOUT |POLLPRI ) : (POLLIN |POLLPRI ), has_timeout ? & left_time : NULL );
300
301
} else {
301
302
php_pollfd_for (sslsock -> s .socket , (err == SSL_ERROR_WANT_READ ) ?
302
303
(POLLIN |POLLPRI ) : (POLLOUT |POLLPRI ), has_timeout ? & left_time : NULL );
303
304
}
305
+ }
304
306
}
305
307
/* Finally, we keep going until we got data, and an SSL_ERROR_NONE, unless we had an error. */
306
308
} while (retry );
@@ -312,21 +314,19 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
312
314
313
315
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
314
316
if (blocked ) {
315
- php_set_sock_blocking (sslsock -> s .socket , 1 TSRMLS_CC );
316
- sslsock -> s .is_blocked = 1 ;
317
- }
318
- } else {
319
- /*
320
- * This block is if we had no timeout... We will just sit and wait forever on the IO operation.
321
- */
322
- if (read ) {
323
- nr_bytes = php_stream_socket_ops .read (stream , buf , count TSRMLS_CC );
324
- } else {
325
- nr_bytes = php_stream_socket_ops .write (stream , buf , count TSRMLS_CC );
317
+ php_set_sock_blocking (sslsock -> s .socket , 1 TSRMLS_CC );
318
+ sslsock -> s .is_blocked = 1 ;
319
+ }
320
+ } else {
321
+ /* This block is if we had no timeout... We will just sit and wait forever on the IO operation. */
322
+ if (read ) {
323
+ nr_bytes = php_stream_socket_ops .read (stream , buf , count TSRMLS_CC );
324
+ } else {
325
+ nr_bytes = php_stream_socket_ops .write (stream , buf , count TSRMLS_CC );
326
+ }
326
327
}
327
- }
328
328
329
- /* PHP doesn't expect a negative return. */
329
+ /* PHP doesn't expect a negative return. */
330
330
if (nr_bytes < 0 ) {
331
331
nr_bytes = 0 ;
332
332
}
0 commit comments