@@ -1901,6 +1901,15 @@ static int php_openssl_capture_peer_certs(php_stream *stream,
1901
1901
}
1902
1902
/* }}} */
1903
1903
1904
+ static zend_result php_openssl_set_blocking (php_openssl_netstream_data_t * sslsock , int block )
1905
+ {
1906
+ zend_result result = php_set_sock_blocking (sslsock -> s .socket , block );
1907
+ if (EXPECTED (SUCCESS == result )) {
1908
+ sslsock -> s .is_blocked = block ;
1909
+ }
1910
+ return result ;
1911
+ }
1912
+
1904
1913
static int php_openssl_enable_crypto (php_stream * stream ,
1905
1914
php_openssl_netstream_data_t * sslsock ,
1906
1915
php_stream_xport_crypto_param * cparam ) /* {{{ */
@@ -1929,8 +1938,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
1929
1938
sslsock -> state_set = 1 ;
1930
1939
}
1931
1940
1932
- if (SUCCESS == php_set_sock_blocking (sslsock -> s .socket , 0 )) {
1933
- sslsock -> s .is_blocked = 0 ;
1941
+ if (SUCCESS == php_openssl_set_blocking (sslsock , 0 )) {
1934
1942
/* The following mode are added only if we are able to change socket
1935
1943
* to non blocking mode which is also used for read and write */
1936
1944
SSL_set_mode (sslsock -> ssl_handle , SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER );
@@ -1983,8 +1991,8 @@ static int php_openssl_enable_crypto(php_stream *stream,
1983
1991
}
1984
1992
} while (retry );
1985
1993
1986
- if (sslsock -> s .is_blocked != blocked && SUCCESS == php_set_sock_blocking ( sslsock -> s . socket , blocked ) ) {
1987
- sslsock -> s . is_blocked = blocked ;
1994
+ if (sslsock -> s .is_blocked != blocked ) {
1995
+ php_openssl_set_blocking ( sslsock , blocked ) ;
1988
1996
}
1989
1997
1990
1998
if (n == 1 ) {
@@ -2067,8 +2075,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
2067
2075
timeout = & sslsock -> s .timeout ;
2068
2076
}
2069
2077
2070
- if (timeout && php_set_sock_blocking ( sslsock -> s . socket , 0 ) == SUCCESS ) {
2071
- sslsock -> s . is_blocked = 0 ;
2078
+ if (timeout ) {
2079
+ php_openssl_set_blocking ( sslsock , 0 ) ;
2072
2080
}
2073
2081
2074
2082
if (!sslsock -> s .is_blocked && timeout && (timeout -> tv_sec > 0 || (timeout -> tv_sec == 0 && timeout -> tv_usec ))) {
@@ -2092,9 +2100,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
2092
2100
if (php_openssl_compare_timeval (elapsed_time , * timeout ) > 0 ) {
2093
2101
/* If the socket was originally blocking, set it back. */
2094
2102
if (began_blocked ) {
2095
- if (php_set_sock_blocking (sslsock -> s .socket , 1 ) == SUCCESS ) {
2096
- sslsock -> s .is_blocked = 1 ;
2097
- }
2103
+ php_openssl_set_blocking (sslsock , 1 );
2098
2104
}
2099
2105
sslsock -> s .timeout_event = 1 ;
2100
2106
return -1 ;
@@ -2189,8 +2195,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
2189
2195
}
2190
2196
2191
2197
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
2192
- if (began_blocked && php_set_sock_blocking ( sslsock -> s . socket , 1 ) == SUCCESS ) {
2193
- sslsock -> s . is_blocked = 1 ;
2198
+ if (began_blocked ) {
2199
+ php_openssl_set_blocking ( sslsock , 1 ) ;
2194
2200
}
2195
2201
2196
2202
return 0 > nr_bytes ? 0 : nr_bytes ;
@@ -2496,8 +2502,8 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
2496
2502
timeout = & tv ;
2497
2503
}
2498
2504
2499
- if (timeout && php_set_sock_blocking ( sslsock -> s . socket , 0 ) == SUCCESS ) {
2500
- sslsock -> s . is_blocked = 0 ;
2505
+ if (timeout ) {
2506
+ php_openssl_set_blocking ( sslsock , 0 ) ;
2501
2507
}
2502
2508
2503
2509
if (!sslsock -> s .is_blocked && timeout && (timeout -> tv_sec > 0 || (timeout -> tv_sec == 0 && timeout -> tv_usec ))) {
@@ -2521,9 +2527,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
2521
2527
if (php_openssl_compare_timeval (elapsed_time , * timeout ) > 0 ) {
2522
2528
/* If the socket was originally blocking, set it back. */
2523
2529
if (began_blocked ) {
2524
- if (php_set_sock_blocking (sslsock -> s .socket , 1 ) == SUCCESS ) {
2525
- sslsock -> s .is_blocked = 1 ;
2526
- }
2530
+ php_openssl_set_blocking (sslsock , 1 );
2527
2531
}
2528
2532
sslsock -> s .timeout_event = 1 ;
2529
2533
return PHP_STREAM_OPTION_RETURN_ERR ;
@@ -2574,9 +2578,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
2574
2578
2575
2579
if (began_blocked && !sslsock -> s .is_blocked ) {
2576
2580
// Set it back to blocking
2577
- if (php_set_sock_blocking (sslsock -> s .socket , 1 ) == SUCCESS ) {
2578
- sslsock -> s .is_blocked = 1 ;
2579
- }
2581
+ php_openssl_set_blocking (sslsock , 1 );
2580
2582
}
2581
2583
} else {
2582
2584
#ifdef PHP_WIN32
0 commit comments