Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2809

Pass non-const event structs to APM callbacks

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.0
    • Affects Version/s: None
    • Component/s: libmongoc
    • Labels:
      None

      The event structs passed to SDAM monitoring callbacks are const, e.g.:

      typedef void (*mongoc_apm_topology_changed_cb_t) (
         const mongoc_apm_topology_changed_t *event); 
      

      Furthermore, the event accessors give const pointers:

      MONGOC_EXPORT (const mongoc_topology_description_t *)
      mongoc_apm_topology_changed_get_previous_description (
         const mongoc_apm_topology_changed_t *event);
      

      However, mongoc_topology_description_has_readable_server / writable server take non-const mongoc_topology_description_t pointers, because they must perform server selection which is a non-const operation on the topology description.

      Calling mongoc_topology_description_has_readable_server / writable_server on the topology description provided to an SDAM monitoring callback is a documented use case in the SDAM monitoring spec, it shouldn't require the user to cast away const.

      We can de-const some types without breaking compatibility.

      Since we provide no public setter functions for any event structs, we could de-const them all without changing semantics significantly, and keep all the callback signatures consistent. Let's consider doing that.

        1. patch
          37 kB

            Assignee:
            Unassigned Unassigned
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: