@@ -350,30 +350,31 @@ static PHP_METHOD(Server, getInfo)
350350 mongoc_server_description_destroy (sd );
351351} /* }}} */
352352
353- /* {{{ proto integer MongoDB\Driver\Server::getLatency()
354- Returns the last measured latency for this Server */
353+ /* {{{ proto integer|null MongoDB\Driver\Server::getLatency()
354+ Returns the measured latency (i.e. round trip time in milliseconds) for
355+ this Server, or null if unset. */
355356static PHP_METHOD (Server , getLatency )
356357{
357- zend_error_handling error_handling ;
358358 php_phongo_server_t * intern ;
359359 mongoc_server_description_t * sd ;
360360
361+ PHONGO_PARSE_PARAMETERS_NONE ();
362+
361363 intern = Z_SERVER_OBJ_P (getThis ());
362364
363- zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling );
364- if (zend_parse_parameters_none () == FAILURE ) {
365- zend_restore_error_handling (& error_handling );
365+ if (!(sd = mongoc_client_get_server_description (Z_MANAGER_OBJ_P (& intern -> manager )-> client , intern -> server_id ))) {
366+ phongo_throw_exception (PHONGO_ERROR_RUNTIME , "Failed to get server description" );
366367 return ;
367368 }
368- zend_restore_error_handling (& error_handling );
369369
370- if ((sd = mongoc_client_get_server_description (Z_MANAGER_OBJ_P (& intern -> manager )-> client , intern -> server_id ))) {
370+ /* TODO: Use MONGOC_RTT_UNSET once it is added to libmongoc's public API (CDRIVER-4176) */
371+ if (mongoc_server_description_round_trip_time (sd ) == -1 ) {
372+ RETVAL_NULL ();
373+ } else {
371374 RETVAL_LONG ((zend_long ) mongoc_server_description_round_trip_time (sd ));
372- mongoc_server_description_destroy (sd );
373- return ;
374375 }
375376
376- phongo_throw_exception ( PHONGO_ERROR_RUNTIME , "Failed to get server description" );
377+ mongoc_server_description_destroy ( sd );
377378} /* }}} */
378379
379380/* {{{ proto integer MongoDB\Driver\Server::getPort()
0 commit comments