Struct WebSocketConfig

struct WebSocketConfig { ... }

The configuration for WebSocket connection.

Example

# use tungstenite::protocol::WebSocketConfig;;
let conf = WebSocketConfig::default()
    .read_buffer_size(256 * 1024)
    .write_buffer_size(256 * 1024);

Fields

read_buffer_size: usize

Read buffer capacity. This buffer is eagerly allocated and used for receiving messages.

For high read load scenarios a larger buffer, e.g. 128 KiB, improves performance.

For scenarios where you expect a lot of connections and don't need high read load performance a smaller buffer, e.g. 4 KiB, would be appropriate to lower total memory usage.

The default value is 128 KiB.

write_buffer_size: usize

The target minimum size of the write buffer to reach before writing the data to the underlying stream. The default value is 128 KiB.

If set to 0 each message will be eagerly written to the underlying stream. It is often more optimal to allow them to buffer a little, hence the default value.

Note: flush will always fully write the buffer regardless.

max_write_buffer_size: usize

The max size of the write buffer in bytes. Setting this can provide backpressure in the case the write buffer is filling up due to write errors. The default value is unlimited.

Note: The write buffer only builds up past write_buffer_size when writes to the underlying stream are failing. So the write buffer can not fill up if you are not observing write errors even if not flushing.

Note: Should always be at least write_buffer_size + 1 message and probably a little more depending on error handling strategy.

max_message_size: Option<usize>

The maximum size of an incoming message. None means no size limit. The default value is 64 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user.

max_frame_size: Option<usize>

The maximum size of a single incoming message frame. None means no size limit. The limit is for frame payload NOT including the frame header. The default value is 16 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user.

accept_unmasked_frames: bool

When set to true, the server will accept and handle unmasked frames from the client. According to the RFC 6455, the server must close the connection to the client in such cases, however it seems like there are some popular libraries that are sending unmasked frames, ignoring the RFC. By default this option is set to false, i.e. according to RFC 6455.

Implementations

impl WebSocketConfig

fn read_buffer_size(self: Self, read_buffer_size: usize) -> Self

Set Self::read_buffer_size.

fn write_buffer_size(self: Self, write_buffer_size: usize) -> Self

Set Self::write_buffer_size.

fn max_write_buffer_size(self: Self, max_write_buffer_size: usize) -> Self

Set Self::max_write_buffer_size.

fn max_message_size(self: Self, max_message_size: Option<usize>) -> Self

Set Self::max_message_size.

fn max_frame_size(self: Self, max_frame_size: Option<usize>) -> Self

Set Self::max_frame_size.

fn accept_unmasked_frames(self: Self, accept_unmasked_frames: bool) -> Self

Set Self::accept_unmasked_frames.

impl Clone for WebSocketConfig

fn clone(self: &Self) -> WebSocketConfig

impl Copy for WebSocketConfig

impl Debug for WebSocketConfig

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Default for WebSocketConfig

fn default() -> Self

impl Freeze for WebSocketConfig

impl RefUnwindSafe for WebSocketConfig

impl Send for WebSocketConfig

impl Sync for WebSocketConfig

impl Unpin for WebSocketConfig

impl UnsafeUnpin for WebSocketConfig

impl UnwindSafe for WebSocketConfig

impl<T> Any for WebSocketConfig

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for WebSocketConfig

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for WebSocketConfig

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for WebSocketConfig

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for WebSocketConfig

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Same for WebSocketConfig

impl<T> ToOwned for WebSocketConfig

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for WebSocketConfig

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for WebSocketConfig

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for WebSocketConfig

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<V, T> VZip for WebSocketConfig

fn vzip(self: Self) -> V