@@ -1776,6 +1776,15 @@ static int php_openssl_capture_peer_certs(php_stream *stream,
1776
1776
}
1777
1777
/* }}} */
1778
1778
1779
+ static zend_result php_openssl_set_blocking (php_openssl_netstream_data_t * sslsock , int block )
1780
+ {
1781
+ zend_result result = php_set_sock_blocking (sslsock -> s .socket , block );
1782
+ if (EXPECTED (SUCCESS == result )) {
1783
+ sslsock -> s .is_blocked = block ;
1784
+ }
1785
+ return result ;
1786
+ }
1787
+
1779
1788
static int php_openssl_enable_crypto (php_stream * stream ,
1780
1789
php_openssl_netstream_data_t * sslsock ,
1781
1790
php_stream_xport_crypto_param * cparam ) /* {{{ */
@@ -1804,8 +1813,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
1804
1813
sslsock -> state_set = 1 ;
1805
1814
}
1806
1815
1807
- if (SUCCESS == php_set_sock_blocking (sslsock -> s .socket , 0 )) {
1808
- sslsock -> s .is_blocked = 0 ;
1816
+ if (SUCCESS == php_openssl_set_blocking (sslsock , 0 )) {
1809
1817
/* The following mode are added only if we are able to change socket
1810
1818
* to non blocking mode which is also used for read and write */
1811
1819
SSL_set_mode (sslsock -> ssl_handle , SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER );
@@ -1858,8 +1866,8 @@ static int php_openssl_enable_crypto(php_stream *stream,
1858
1866
}
1859
1867
} while (retry );
1860
1868
1861
- if (sslsock -> s .is_blocked != blocked && SUCCESS == php_set_sock_blocking ( sslsock -> s . socket , blocked ) ) {
1862
- sslsock -> s . is_blocked = blocked ;
1869
+ if (sslsock -> s .is_blocked != blocked ) {
1870
+ php_openssl_set_blocking ( sslsock , blocked ) ;
1863
1871
}
1864
1872
1865
1873
if (n == 1 ) {
@@ -1942,8 +1950,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
1942
1950
timeout = & sslsock -> s .timeout ;
1943
1951
}
1944
1952
1945
- if (timeout && php_set_sock_blocking ( sslsock -> s . socket , 0 ) == SUCCESS ) {
1946
- sslsock -> s . is_blocked = 0 ;
1953
+ if (timeout ) {
1954
+ php_openssl_set_blocking ( sslsock , 0 ) ;
1947
1955
}
1948
1956
1949
1957
if (!sslsock -> s .is_blocked && timeout && (timeout -> tv_sec > 0 || (timeout -> tv_sec == 0 && timeout -> tv_usec ))) {
@@ -1967,8 +1975,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
1967
1975
if (php_openssl_compare_timeval (elapsed_time , * timeout ) > 0 ) {
1968
1976
/* If the socket was originally blocking, set it back. */
1969
1977
if (began_blocked ) {
1970
- php_set_sock_blocking (sslsock -> s .socket , 1 );
1971
- sslsock -> s .is_blocked = 1 ;
1978
+ php_openssl_set_blocking (sslsock , 1 );
1972
1979
}
1973
1980
sslsock -> s .timeout_event = 1 ;
1974
1981
return -1 ;
@@ -2063,8 +2070,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
2063
2070
}
2064
2071
2065
2072
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
2066
- if (began_blocked && php_set_sock_blocking ( sslsock -> s . socket , 1 ) == SUCCESS ) {
2067
- sslsock -> s . is_blocked = 1 ;
2073
+ if (began_blocked ) {
2074
+ php_openssl_set_blocking ( sslsock , 1 ) ;
2068
2075
}
2069
2076
2070
2077
return 0 > nr_bytes ? 0 : nr_bytes ;
@@ -2370,8 +2377,8 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
2370
2377
timeout = & tv ;
2371
2378
}
2372
2379
2373
- if (timeout && php_set_sock_blocking ( sslsock -> s . socket , 0 ) == SUCCESS ) {
2374
- sslsock -> s . is_blocked = 0 ;
2380
+ if (timeout ) {
2381
+ php_openssl_set_blocking ( sslsock , 0 ) ;
2375
2382
}
2376
2383
2377
2384
if (!sslsock -> s .is_blocked && timeout && (timeout -> tv_sec > 0 || (timeout -> tv_sec == 0 && timeout -> tv_usec ))) {
@@ -2395,8 +2402,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
2395
2402
if (php_openssl_compare_timeval (elapsed_time , * timeout ) > 0 ) {
2396
2403
/* If the socket was originally blocking, set it back. */
2397
2404
if (began_blocked ) {
2398
- php_set_sock_blocking (sslsock -> s .socket , 1 );
2399
- sslsock -> s .is_blocked = 1 ;
2405
+ php_openssl_set_blocking (sslsock , 1 );
2400
2406
}
2401
2407
sslsock -> s .timeout_event = 1 ;
2402
2408
return PHP_STREAM_OPTION_RETURN_ERR ;
@@ -2447,8 +2453,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
2447
2453
2448
2454
if (began_blocked && !sslsock -> s .is_blocked ) {
2449
2455
// Set it back to blocking
2450
- php_set_sock_blocking (sslsock -> s .socket , 1 );
2451
- sslsock -> s .is_blocked = 1 ;
2456
+ php_openssl_set_blocking (sslsock , 1 );
2452
2457
}
2453
2458
} else {
2454
2459
#ifdef PHP_WIN32
0 commit comments