Skip to content

Commit ffdfc8c

Browse files
committed
Update ServerOpeningEvent::getHost(), add getPort()
1 parent c401be8 commit ffdfc8c

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

php_phongo_structs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,10 @@ typedef struct {
285285
} php_phongo_commandsucceededevent_t;
286286

287287
typedef struct {
288-
bson_oid_t topology_id;
289-
const mongoc_host_list_t* host;
290-
zend_object std;
288+
bson_oid_t topology_id;
289+
char host[BSON_HOST_NAME_MAX + 1];
290+
uint16_t port;
291+
zend_object std;
291292
} php_phongo_serveropeningevent_t;
292293

293294
typedef struct {

src/MongoDB/Monitoring/ServerOpeningEvent.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ static PHP_METHOD(ServerOpeningEvent, getHost)
3434

3535
PHONGO_PARSE_PARAMETERS_NONE();
3636

37-
RETVAL_STRING((intern->host)->host);
37+
RETVAL_STRING(intern->host);
38+
} /* }}} */
39+
40+
/* {{{ proto integer ServerOpeningEvent::getPort()
41+
Returns this event's port */
42+
static PHP_METHOD(ServerOpeningEvent, getPort)
43+
{
44+
php_phongo_serveropeningevent_t* intern = Z_SERVEROPENINGEVENT_OBJ_P(getThis());
45+
46+
PHONGO_PARSE_PARAMETERS_NONE();
47+
48+
RETVAL_LONG(intern->port);
3849
} /* }}} */
3950

4051
/* {{{ proto MongoDB\BSON\ObjectId ServerOpeningEvent::getTopologyId()
@@ -61,6 +72,7 @@ static zend_function_entry php_phongo_serveropeningevent_me[] = {
6172
/* clang-format off */
6273
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_ServerOpeningEvent_void, ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)
6374
PHP_ME(ServerOpeningEvent, getHost, ai_ServerOpeningEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
75+
PHP_ME(ServerOpeningEvent, getPort, ai_ServerOpeningEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
6476
PHP_ME(ServerOpeningEvent, getTopologyId, ai_ServerOpeningEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
6577
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_ServerOpeningEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
6678
PHP_FE_END
@@ -100,9 +112,10 @@ static HashTable* php_phongo_serveropeningevent_get_debug_info(phongo_compat_obj
100112

101113
intern = Z_OBJ_SERVEROPENINGEVENT(PHONGO_COMPAT_GET_OBJ(object));
102114
*is_temp = 1;
103-
array_init_size(&retval, 2);
115+
array_init_size(&retval, 3);
104116

105-
ADD_ASSOC_STRING(&retval, "host", (intern->host)->host);
117+
ADD_ASSOC_STRING(&retval, "host", intern->host);
118+
ADD_ASSOC_LONG_EX(&retval, "port", intern->port);
106119

107120
bson_oid_to_string(&intern->topology_id, topology_id);
108121
ADD_ASSOC_STRING(&retval, "topologyId", topology_id);

src/phongo_apm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ static void phongo_apm_server_opening(const mongoc_apm_server_opening_t* event)
268268
HashTable* subscribers;
269269
php_phongo_serveropeningevent_t* p_event;
270270
zval z_event;
271+
const mongoc_host_list_t* host_list;
271272

272273
client = mongoc_apm_server_opening_get_context(event);
273274
subscribers = phongo_apm_get_subscribers_to_notify(php_phongo_sdamsubscriber_ce, client);
@@ -280,8 +281,11 @@ static void phongo_apm_server_opening(const mongoc_apm_server_opening_t* event)
280281
object_init_ex(&z_event, php_phongo_serveropeningevent_ce);
281282
p_event = Z_SERVEROPENINGEVENT_OBJ_P(&z_event);
282283

284+
host_list = mongoc_apm_server_opening_get_host(event);
285+
memcpy(&p_event->host, &host_list->host, BSON_HOST_NAME_MAX + 1);
286+
p_event->port = host_list->port;
287+
283288
mongoc_apm_server_opening_get_topology_id(event, &p_event->topology_id);
284-
p_event->host = mongoc_apm_server_opening_get_host(event);
285289

286290
phongo_apm_dispatch_event(subscribers, "serverOpening", &z_event);
287291
zval_ptr_dtor(&z_event);

tests/apm/monitoring-serverOpening-001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
2121

2222
$this->serverOpened = true;
2323
echo "- getHost() returns a string: ", is_string($event->getHost()) ? 'yes' : 'no', "\n";
24+
echo "- getPort() returns an integer: ", is_integer($event->getPort()) ? 'yes' : 'no', "\n";
2425
echo "- getTopologyId() returns an ObjectId: ", ($event->getTopologyId() instanceof MongoDB\BSON\ObjectId) ? 'yes' : 'no', "\n";
2526
}
2627

@@ -40,5 +41,6 @@ $m->executeCommand(DATABASE_NAME, $command);
4041
<?php exit(0); ?>
4142
--EXPECT--
4243
- getHost() returns a string: yes
44+
- getPort() returns an integer: yes
4345
- getTopologyId() returns an ObjectId: yes
4446
===DONE===

0 commit comments

Comments
 (0)