Skip to content

PHPC-2022: Use mongoc_host_list in event structs #1291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions php_phongo_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,50 +292,44 @@ typedef struct {

typedef struct {
bson_oid_t topology_id;
char host[BSON_HOST_NAME_MAX + 1];
uint16_t port;
mongoc_host_list_t host;
mongoc_server_description_t* new_server_description;
mongoc_server_description_t* old_server_description;
zend_object std;
} php_phongo_serverchangedevent_t;

typedef struct {
bson_oid_t topology_id;
char host[BSON_HOST_NAME_MAX + 1];
uint16_t port;
zend_object std;
bson_oid_t topology_id;
mongoc_host_list_t host;
zend_object std;
} php_phongo_serverclosedevent_t;

typedef struct {
bool awaited;
uint64_t duration_micros;
zval z_error;
char host[BSON_HOST_NAME_MAX + 1];
uint16_t port;
zend_object std;
bool awaited;
uint64_t duration_micros;
zval z_error;
mongoc_host_list_t host;
zend_object std;
} php_phongo_serverheartbeatfailedevent_t;

typedef struct {
bool awaited;
char host[BSON_HOST_NAME_MAX + 1];
uint16_t port;
zend_object std;
bool awaited;
mongoc_host_list_t host;
zend_object std;
} php_phongo_serverheartbeatstartedevent_t;

typedef struct {
bool awaited;
uint64_t duration_micros;
char host[BSON_HOST_NAME_MAX + 1];
uint16_t port;
bson_t* reply;
zend_object std;
bool awaited;
uint64_t duration_micros;
mongoc_host_list_t host;
bson_t* reply;
zend_object std;
} php_phongo_serverheartbeatsucceededevent_t;

typedef struct {
bson_oid_t topology_id;
char host[BSON_HOST_NAME_MAX + 1];
uint16_t port;
zend_object std;
bson_oid_t topology_id;
mongoc_host_list_t host;
zend_object std;
} php_phongo_serveropeningevent_t;

typedef struct {
Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Monitoring/ServerChangedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static PHP_METHOD(ServerChangedEvent, getHost)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host);
RETVAL_STRING(intern->host.host);
} /* }}} */

/* {{{ proto integer ServerChangedEvent::getPort()
Expand All @@ -45,7 +45,7 @@ static PHP_METHOD(ServerChangedEvent, getPort)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->port);
RETVAL_LONG(intern->host.port);
} /* }}} */

/* {{{ proto MongoDB\Driver\ServerDescription ServerChangedEvent::getNewDescription()
Expand Down Expand Up @@ -140,8 +140,8 @@ static HashTable* php_phongo_serverchangedevent_get_debug_info(phongo_compat_obj
*is_temp = 1;
array_init_size(&retval, 4);

ADD_ASSOC_STRING(&retval, "host", intern->host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->port);
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);

{
zval topology_id;
Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Monitoring/ServerClosedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static PHP_METHOD(ServerClosedEvent, getHost)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host);
RETVAL_STRING(intern->host.host);
} /* }}} */

/* {{{ proto integer ServerClosedEvent::getPort()
Expand All @@ -45,7 +45,7 @@ static PHP_METHOD(ServerClosedEvent, getPort)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->port);
RETVAL_LONG(intern->host.port);
} /* }}} */

/* {{{ proto MongoDB\BSON\ObjectId ServerClosedEvent::getTopologyId()
Expand Down Expand Up @@ -108,8 +108,8 @@ static HashTable* php_phongo_serverclosedevent_get_debug_info(phongo_compat_obje
*is_temp = 1;
array_init_size(&retval, 3);

ADD_ASSOC_STRING(&retval, "host", intern->host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->port);
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);

{
zval topology_id;
Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static PHP_METHOD(ServerHeartbeatFailedEvent, getHost)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host);
RETVAL_STRING(intern->host.host);
} /* }}} */

/* {{{ proto integer ServerHeartbeatFailedEvent::getPort()
Expand All @@ -67,7 +67,7 @@ static PHP_METHOD(ServerHeartbeatFailedEvent, getPort)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->port);
RETVAL_LONG(intern->host.port);
} /* }}} */

/* {{{ proto boolean ServerHeartbeatFailedEvent::isAwaited()
Expand Down Expand Up @@ -136,8 +136,8 @@ static HashTable* php_phongo_serverheartbeatfailedevent_get_debug_info(phongo_co
*is_temp = 1;
array_init_size(&retval, 5);

ADD_ASSOC_STRING(&retval, "host", intern->host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->port);
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_BOOL_EX(&retval, "awaited", intern->awaited);
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);

Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static PHP_METHOD(ServerHeartbeatStartedEvent, getHost)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host);
RETVAL_STRING(intern->host.host);
} /* }}} */

/* {{{ proto integer ServerHeartbeatStartedEvent::getPort()
Expand All @@ -45,7 +45,7 @@ static PHP_METHOD(ServerHeartbeatStartedEvent, getPort)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->port);
RETVAL_LONG(intern->host.port);
} /* }}} */

/* {{{ proto boolean ServerHeartbeatStartedEvent::isAwaited()
Expand Down Expand Up @@ -108,8 +108,8 @@ static HashTable* php_phongo_serverheartbeatstartedevent_get_debug_info(phongo_c
*is_temp = 1;
array_init_size(&retval, 4);

ADD_ASSOC_STRING(&retval, "host", intern->host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->port);
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_BOOL_EX(&retval, "awaited", intern->awaited);

return Z_ARRVAL(retval);
Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static PHP_METHOD(ServerHeartbeatSucceededEvent, getHost)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host);
RETVAL_STRING(intern->host.host);
} /* }}} */

/* {{{ proto integer ServerHeartbeatSucceededEvent::getPort()
Expand All @@ -56,7 +56,7 @@ static PHP_METHOD(ServerHeartbeatSucceededEvent, getPort)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->port);
RETVAL_LONG(intern->host.port);
} /* }}} */

/* {{{ proto integer ServerHeartbeatSucceededEvent::getReply()
Expand Down Expand Up @@ -147,8 +147,8 @@ static HashTable* php_phongo_serverheartbeatsucceededevent_get_debug_info(phongo
*is_temp = 1;
array_init_size(&retval, 4);

ADD_ASSOC_STRING(&retval, "host", intern->host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->port);
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_BOOL_EX(&retval, "awaited", intern->awaited);

if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Monitoring/ServerOpeningEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static PHP_METHOD(ServerOpeningEvent, getHost)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host);
RETVAL_STRING(intern->host.host);
} /* }}} */

/* {{{ proto integer ServerOpeningEvent::getPort()
Expand All @@ -45,7 +45,7 @@ static PHP_METHOD(ServerOpeningEvent, getPort)

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->port);
RETVAL_LONG(intern->host.port);
} /* }}} */

/* {{{ proto MongoDB\BSON\ObjectId ServerOpeningEvent::getTopologyId()
Expand Down Expand Up @@ -108,8 +108,8 @@ static HashTable* php_phongo_serveropeningevent_get_debug_info(phongo_compat_obj
*is_temp = 1;
array_init_size(&retval, 3);

ADD_ASSOC_STRING(&retval, "host", intern->host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->port);
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);

{
zval topology_id;
Expand Down
41 changes: 6 additions & 35 deletions src/phongo_apm.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ static void phongo_apm_server_changed(const mongoc_apm_server_changed_t* event)
HashTable* subscribers;
php_phongo_serverchangedevent_t* p_event;
zval z_event;
const mongoc_host_list_t* host_list;

client = mongoc_apm_server_changed_get_context(event);
subscribers = phongo_apm_get_subscribers_to_notify(php_phongo_sdamsubscriber_ce, client);
Expand All @@ -296,10 +295,7 @@ static void phongo_apm_server_changed(const mongoc_apm_server_changed_t* event)
object_init_ex(&z_event, php_phongo_serverchangedevent_ce);
p_event = Z_SERVERCHANGEDEVENT_OBJ_P(&z_event);

host_list = mongoc_apm_server_changed_get_host(event);
memcpy(&p_event->host, &host_list->host, BSON_HOST_NAME_MAX + 1);
p_event->port = host_list->port;

memcpy(&p_event->host, mongoc_apm_server_changed_get_host(event), sizeof(mongoc_host_list_t));
mongoc_apm_server_changed_get_topology_id(event, &p_event->topology_id);
p_event->new_server_description = mongoc_server_description_new_copy(mongoc_apm_server_changed_get_new_description(event));
p_event->old_server_description = mongoc_server_description_new_copy(mongoc_apm_server_changed_get_previous_description(event));
Expand All @@ -318,7 +314,6 @@ static void phongo_apm_server_closed(const mongoc_apm_server_closed_t* event)
HashTable* subscribers;
php_phongo_serverclosedevent_t* p_event;
zval z_event;
const mongoc_host_list_t* host_list;

client = mongoc_apm_server_closed_get_context(event);
subscribers = phongo_apm_get_subscribers_to_notify(php_phongo_sdamsubscriber_ce, client);
Expand All @@ -331,11 +326,7 @@ static void phongo_apm_server_closed(const mongoc_apm_server_closed_t* event)
object_init_ex(&z_event, php_phongo_serverclosedevent_ce);
p_event = Z_SERVERCLOSEDEVENT_OBJ_P(&z_event);

host_list = mongoc_apm_server_closed_get_host(event);
memset(p_event->host, 0, sizeof(p_event->host));
bson_strncpy(p_event->host, host_list->host, sizeof(p_event->host));
p_event->port = host_list->port;

memcpy(&p_event->host, mongoc_apm_server_closed_get_host(event), sizeof(mongoc_host_list_t));
mongoc_apm_server_closed_get_topology_id(event, &p_event->topology_id);

phongo_apm_dispatch_event(subscribers, "serverClosed", &z_event);
Expand All @@ -352,7 +343,6 @@ static void phongo_apm_server_heartbeat_failed(const mongoc_apm_server_heartbeat
HashTable* subscribers;
php_phongo_serverheartbeatfailedevent_t* p_event;
zval z_event;
const mongoc_host_list_t* host_list;
bson_error_t tmp_error = { 0 };

client = mongoc_apm_server_heartbeat_failed_get_context(event);
Expand All @@ -366,11 +356,7 @@ static void phongo_apm_server_heartbeat_failed(const mongoc_apm_server_heartbeat
object_init_ex(&z_event, php_phongo_serverheartbeatfailedevent_ce);
p_event = Z_SERVERHEARTBEATFAILEDEVENT_OBJ_P(&z_event);

host_list = mongoc_apm_server_heartbeat_failed_get_host(event);
memset(p_event->host, 0, sizeof(p_event->host));
bson_strncpy(p_event->host, host_list->host, sizeof(p_event->host));
p_event->port = host_list->port;

memcpy(&p_event->host, mongoc_apm_server_heartbeat_failed_get_host(event), sizeof(mongoc_host_list_t));
p_event->awaited = mongoc_apm_server_heartbeat_failed_get_awaited(event);
p_event->duration_micros = mongoc_apm_server_heartbeat_failed_get_duration(event);

Expand All @@ -397,7 +383,6 @@ static void phongo_apm_server_heartbeat_succeeded(const mongoc_apm_server_heartb
HashTable* subscribers;
php_phongo_serverheartbeatsucceededevent_t* p_event;
zval z_event;
const mongoc_host_list_t* host_list;

client = mongoc_apm_server_heartbeat_succeeded_get_context(event);
subscribers = phongo_apm_get_subscribers_to_notify(php_phongo_sdamsubscriber_ce, client);
Expand All @@ -410,11 +395,7 @@ static void phongo_apm_server_heartbeat_succeeded(const mongoc_apm_server_heartb
object_init_ex(&z_event, php_phongo_serverheartbeatsucceededevent_ce);
p_event = Z_SERVERHEARTBEATSUCCEEDEDEVENT_OBJ_P(&z_event);

host_list = mongoc_apm_server_heartbeat_succeeded_get_host(event);
memset(p_event->host, 0, sizeof(p_event->host));
bson_strncpy(p_event->host, host_list->host, sizeof(p_event->host));
p_event->port = host_list->port;

memcpy(&p_event->host, mongoc_apm_server_heartbeat_succeeded_get_host(event), sizeof(mongoc_host_list_t));
p_event->awaited = mongoc_apm_server_heartbeat_succeeded_get_awaited(event);
p_event->duration_micros = mongoc_apm_server_heartbeat_succeeded_get_duration(event);
p_event->reply = bson_copy(mongoc_apm_server_heartbeat_succeeded_get_reply(event));
Expand All @@ -433,7 +414,6 @@ static void phongo_apm_server_heartbeat_started(const mongoc_apm_server_heartbea
HashTable* subscribers;
php_phongo_serverheartbeatstartedevent_t* p_event;
zval z_event;
const mongoc_host_list_t* host_list;

client = mongoc_apm_server_heartbeat_started_get_context(event);
subscribers = phongo_apm_get_subscribers_to_notify(php_phongo_sdamsubscriber_ce, client);
Expand All @@ -446,11 +426,7 @@ static void phongo_apm_server_heartbeat_started(const mongoc_apm_server_heartbea
object_init_ex(&z_event, php_phongo_serverheartbeatstartedevent_ce);
p_event = Z_SERVERHEARTBEATSTARTEDEVENT_OBJ_P(&z_event);

host_list = mongoc_apm_server_heartbeat_started_get_host(event);
memset(p_event->host, 0, sizeof(p_event->host));
bson_strncpy(p_event->host, host_list->host, sizeof(p_event->host));
p_event->port = host_list->port;

memcpy(&p_event->host, mongoc_apm_server_heartbeat_started_get_host(event), sizeof(mongoc_host_list_t));
p_event->awaited = mongoc_apm_server_heartbeat_started_get_awaited(event);

phongo_apm_dispatch_event(subscribers, "serverHeartbeatStarted", &z_event);
Expand All @@ -467,7 +443,6 @@ static void phongo_apm_server_opening(const mongoc_apm_server_opening_t* event)
HashTable* subscribers;
php_phongo_serveropeningevent_t* p_event;
zval z_event;
const mongoc_host_list_t* host_list;

client = mongoc_apm_server_opening_get_context(event);
subscribers = phongo_apm_get_subscribers_to_notify(php_phongo_sdamsubscriber_ce, client);
Expand All @@ -480,11 +455,7 @@ static void phongo_apm_server_opening(const mongoc_apm_server_opening_t* event)
object_init_ex(&z_event, php_phongo_serveropeningevent_ce);
p_event = Z_SERVEROPENINGEVENT_OBJ_P(&z_event);

host_list = mongoc_apm_server_opening_get_host(event);
memset(p_event->host, 0, sizeof(p_event->host));
bson_strncpy(p_event->host, host_list->host, sizeof(p_event->host));
p_event->port = host_list->port;

memcpy(&p_event->host, mongoc_apm_server_opening_get_host(event), sizeof(mongoc_host_list_t));
mongoc_apm_server_opening_get_topology_id(event, &p_event->topology_id);

phongo_apm_dispatch_event(subscribers, "serverOpening", &z_event);
Expand Down
4 changes: 2 additions & 2 deletions tests/apm/serverHeartbeatFailedEvent-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ MongoDB\Driver\Monitoring\ServerHeartbeatFailedEvent
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_live(); ?>
<?php skip_if_no_failcommand_failpoint(); ?>
<?php skip_if_multiple_mongos(); ?>
<?php skip_if_load_balanced(); ?>
<?php skip_if_not_standalone(); ?>
<?php skip_if_auth(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
Expand Down