@@ -105,25 +105,25 @@ PHP_METHOD(ReadPreference, __construct)
105105 bson_destroy (tags );
106106 }
107107
108- if (options && php_array_exists (options , "maxStalenessMS " )) {
109- phongo_long maxStalenessMS = php_array_fetchc_long (options , "maxStalenessMS " );
110-
111- if (maxStalenessMS < 0 ) {
112- phongo_throw_exception ( PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected maxStalenessMS to be >= 0, %" PHONGO_LONG_FORMAT " given" , maxStalenessMS );
113- return ;
114- }
115-
116- if (maxStalenessMS > INT32_MAX ) {
117- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected maxStalenessMS to be <= %" PRId32 ", %" PHONGO_LONG_FORMAT " given" , INT32_MAX , maxStalenessMS );
118- return ;
119- }
120-
121- if ( maxStalenessMS > 0 && mode == MONGOC_READ_PRIMARY ) {
122- phongo_throw_exception ( PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "maxStalenessMS may not be used with primary mode" ) ;
123- return ;
108+ if (options && php_array_exists (options , "maxStalenessSeconds " )) {
109+ phongo_long maxStalenessSeconds = php_array_fetchc_long (options , "maxStalenessSeconds " );
110+
111+ if (maxStalenessSeconds != MONGOC_NO_MAX_STALENESS ) {
112+ if ( maxStalenessSeconds < MONGOC_SMALLEST_MAX_STALENESS_SECONDS ) {
113+ phongo_throw_exception ( PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected maxStalenessSeconds to be >= %d, %" PHONGO_LONG_FORMAT " given" , MONGOC_SMALLEST_MAX_STALENESS_SECONDS , maxStalenessSeconds ) ;
114+ return ;
115+ }
116+ if (maxStalenessSeconds > INT32_MAX ) {
117+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected maxStalenessSeconds to be <= %" PRId32 ", %" PHONGO_LONG_FORMAT " given" , INT32_MAX , maxStalenessSeconds );
118+ return ;
119+ }
120+ if ( mode == MONGOC_READ_PRIMARY ) {
121+ phongo_throw_exception ( PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "maxStalenessSeconds may not be used with primary mode" );
122+ return ;
123+ }
124124 }
125125
126- mongoc_read_prefs_set_max_staleness_ms (intern -> read_preference , maxStalenessMS );
126+ mongoc_read_prefs_set_max_staleness_seconds (intern -> read_preference , maxStalenessSeconds );
127127 }
128128
129129 if (!mongoc_read_prefs_is_valid (intern -> read_preference )) {
@@ -133,9 +133,9 @@ PHP_METHOD(ReadPreference, __construct)
133133}
134134/* }}} */
135135
136- /* {{{ proto integer ReadPreference::getMaxStalenessMS ()
137- Returns the ReadPreference maxStalenessMS value */
138- PHP_METHOD (ReadPreference , getMaxStalenessMS )
136+ /* {{{ proto integer ReadPreference::getMaxStalenessSeconds ()
137+ Returns the ReadPreference maxStalenessSeconds value */
138+ PHP_METHOD (ReadPreference , getMaxStalenessSeconds )
139139{
140140 php_phongo_readpreference_t * intern ;
141141 SUPPRESS_UNUSED_WARNING (return_value_ptr ) SUPPRESS_UNUSED_WARNING (return_value_used )
@@ -146,7 +146,7 @@ PHP_METHOD(ReadPreference, getMaxStalenessMS)
146146 return ;
147147 }
148148
149- RETURN_LONG (mongoc_read_prefs_get_max_staleness_ms (intern -> read_preference ));
149+ RETURN_LONG (mongoc_read_prefs_get_max_staleness_seconds (intern -> read_preference ));
150150}
151151/* }}} */
152152
@@ -232,7 +232,7 @@ ZEND_END_ARG_INFO()
232232
233233static zend_function_entry php_phongo_readpreference_me [] = {
234234 PHP_ME (ReadPreference , __construct , ai_ReadPreference___construct , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
235- PHP_ME (ReadPreference , getMaxStalenessMS , ai_ReadPreference_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
235+ PHP_ME (ReadPreference , getMaxStalenessSeconds , ai_ReadPreference_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
236236 PHP_ME (ReadPreference , getMode , ai_ReadPreference_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
237237 PHP_ME (ReadPreference , getTagSets , ai_ReadPreference_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
238238 PHP_ME (ReadPreference , bsonSerialize , ai_ReadPreference_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
@@ -328,6 +328,8 @@ PHP_MINIT_FUNCTION(ReadPreference)
328328 zend_declare_class_constant_long (php_phongo_readpreference_ce , ZEND_STRL ("RP_SECONDARY" ), MONGOC_READ_SECONDARY TSRMLS_CC );
329329 zend_declare_class_constant_long (php_phongo_readpreference_ce , ZEND_STRL ("RP_SECONDARY_PREFERRED" ), MONGOC_READ_SECONDARY_PREFERRED TSRMLS_CC );
330330 zend_declare_class_constant_long (php_phongo_readpreference_ce , ZEND_STRL ("RP_NEAREST" ), MONGOC_READ_NEAREST TSRMLS_CC );
331+ zend_declare_class_constant_long (php_phongo_readpreference_ce , ZEND_STRL ("NO_MAX_STALENESS" ), MONGOC_NO_MAX_STALENESS TSRMLS_CC );
332+ zend_declare_class_constant_long (php_phongo_readpreference_ce , ZEND_STRL ("SMALLEST_MAX_STALENESS_SECONDS" ), MONGOC_SMALLEST_MAX_STALENESS_SECONDS TSRMLS_CC );
331333
332334 return SUCCESS ;
333335}
0 commit comments