fmod/core/system/
network.rs

1// Copyright (c) 2024 Melody Madeline 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::{FmodResultExt, Result};
12use crate::{System, get_string};
13
14impl System {
15    /// Set a proxy server to use for all subsequent internet connections.
16    ///
17    /// Specify the proxy in `host:port` format e.g. `www.fmod.com:8888` (defaults to port 80 if no port is specified).
18    ///
19    /// Basic authentication is supported using `user:password@host:port` format e.g. `bob:sekrit123@www.fmod.com:8888`
20    pub fn set_network_proxy(&self, proxy: &Utf8CStr) -> Result<()> {
21        unsafe { FMOD_System_SetNetworkProxy(self.inner.as_ptr(), proxy.as_ptr()).to_result() }
22    }
23
24    /// Retrieves the URL of the proxy server used in internet streaming.
25    pub fn get_network_proxy(&self) -> Result<Utf8CString> {
26        get_string(|name| unsafe {
27            FMOD_System_GetNetworkProxy(
28                self.inner.as_ptr(),
29                name.as_mut_ptr().cast(),
30                name.len() as c_int,
31            )
32        })
33    }
34
35    /// Set the timeout for network streams.
36    pub fn set_network_timeout(&self, timeout: c_int) -> Result<()> {
37        unsafe { FMOD_System_SetNetworkTimeout(self.inner.as_ptr(), timeout).to_result() }
38    }
39
40    /// Retrieve the timeout value for network streams.
41    pub fn get_network_timeout(&self) -> Result<c_int> {
42        let mut timeout = 0;
43        unsafe {
44            FMOD_System_GetNetworkTimeout(self.inner.as_ptr(), &raw mut timeout).to_result()?;
45        }
46        Ok(timeout)
47    }
48}