fn get_peer_by_this()

in src/plugin/plugin_mysqli.rs [203:227]


fn get_peer_by_this(this: &mut ZObj) -> Option<String> {
    let handle = this.handle();

    debug!(handle, "start to call mysqli_get_host_info");

    let host_info = match call("mysqli_get_host_info", [ZVal::from(this.to_ref_owned())]) {
        Ok(host_info) => host_info,
        Err(err) => {
            error!(handle, ?err, "call mysqli_get_host_info failed");
            return None;
        }
    };

    host_info
        .as_z_str()
        .and_then(|info| info.to_str().ok())
        .and_then(|info| info.split(' ').next())
        .map(ToOwned::to_owned)
        .map(|mut info| {
            if !info.contains(':') {
                info.push_str(":3306");
            }
            info
        })
}