fmod/core/system/
network.rs

1// Copyright (c) 2024 Lily Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use fmod_sys::*;
8use lanyard::{Utf8CStr, Utf8CString};
9use std::ffi::c_int;
10
11use crate::{get_string, System};
12
13impl System {
14    /// Set a proxy server to use for all subsequent internet connections.
15    ///
16    /// Specify the proxy in `host:port` format e.g. `www.fmod.com:8888` (defaults to port 80 if no port is specified).
17    ///
18    /// Basic authentication is supported using `user:password@host:port` format e.g. `bob:sekrit123@www.fmod.com:8888`
19    pub fn set_network_proxy(&self, proxy: &Utf8CStr) -> Result<()> {
20        unsafe { FMOD_System_SetNetworkProxy(self.inner, proxy.as_ptr()).to_result() }
21    }
22
23    /// Retrieves the URL of the proxy server used in internet streaming.
24    pub fn get_network_proxy(&self) -> Result<Utf8CString> {
25        get_string(|name| unsafe {
26            FMOD_System_GetNetworkProxy(self.inner, name.as_mut_ptr().cast(), name.len() as c_int)
27        })
28    }
29
30    /// Set the timeout for network streams.
31    pub fn set_network_timeout(&self, timeout: c_int) -> Result<()> {
32        unsafe { FMOD_System_SetNetworkTimeout(self.inner, timeout).to_result() }
33    }
34
35    /// Retrieve the timeout value for network streams.
36    pub fn get_network_timeout(&self) -> Result<c_int> {
37        let mut timeout = 0;
38        unsafe {
39            FMOD_System_GetNetworkTimeout(self.inner, &mut timeout).to_result()?;
40        }
41        Ok(timeout)
42    }
43}