1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Socket option builder methods for `WireframeClientBuilder`.
//!
//! This module contains convenience methods that configure socket options
//! without changing the generic type parameters. These methods delegate
//! to `SocketOptions` methods internally.
use std::time::Duration;
use super::{SocketOptions, WireframeClientBuilder};
use crate::serializer::Serializer;
impl<S, P, C> WireframeClientBuilder<S, P, C>
where
S: Serializer + Send + Sync,
{
/// Replace the socket options applied before connecting.
///
/// # Examples
///
/// ```
/// use wireframe::client::{SocketOptions, WireframeClientBuilder};
///
/// let options = SocketOptions::default().nodelay(true);
/// let builder = WireframeClientBuilder::new().socket_options(options);
/// let _ = builder;
/// ```
#[must_use]
pub const fn socket_options(mut self, socket_options: SocketOptions) -> Self {
self.socket_options = socket_options;
self
}
/// Configure `TCP_NODELAY` for the connection.
///
/// # Examples
///
/// ```
/// use wireframe::client::WireframeClientBuilder;
///
/// let builder = WireframeClientBuilder::new().nodelay(true);
/// let _ = builder;
/// ```
#[must_use]
pub const fn nodelay(mut self, enabled: bool) -> Self {
self.socket_options = self.socket_options.nodelay(enabled);
self
}
/// Configure `SO_KEEPALIVE` for the connection.
///
/// # Examples
///
/// ```
/// use std::time::Duration;
///
/// use wireframe::client::WireframeClientBuilder;
///
/// let builder = WireframeClientBuilder::new().keepalive(Some(Duration::from_secs(30)));
/// let _ = builder;
/// ```
#[must_use]
pub const fn keepalive(mut self, duration: Option<Duration>) -> Self {
self.socket_options = self.socket_options.keepalive(duration);
self
}
/// Configure the socket send buffer size.
///
/// # Examples
///
/// ```
/// use wireframe::client::WireframeClientBuilder;
///
/// let builder = WireframeClientBuilder::new().send_buffer_size(4096);
/// let _ = builder;
/// ```
#[must_use]
pub const fn send_buffer_size(mut self, size: u32) -> Self {
self.socket_options = self.socket_options.send_buffer_size(size);
self
}
/// Configure the socket receive buffer size.
///
/// # Examples
///
/// ```
/// use wireframe::client::WireframeClientBuilder;
///
/// let builder = WireframeClientBuilder::new().recv_buffer_size(4096);
/// let _ = builder;
/// ```
#[must_use]
pub const fn recv_buffer_size(mut self, size: u32) -> Self {
self.socket_options = self.socket_options.recv_buffer_size(size);
self
}
/// Configure `SO_REUSEADDR` for the connection.
///
/// # Examples
///
/// ```
/// use wireframe::client::WireframeClientBuilder;
///
/// let builder = WireframeClientBuilder::new().reuseaddr(true);
/// let _ = builder;
/// ```
#[must_use]
pub const fn reuseaddr(mut self, enabled: bool) -> Self {
self.socket_options = self.socket_options.reuseaddr(enabled);
self
}
/// Configure `SO_REUSEPORT` for the connection on supported platforms.
///
/// # Examples
///
/// ```
/// use wireframe::client::WireframeClientBuilder;
///
/// let builder = WireframeClientBuilder::new().reuseport(true);
/// let _ = builder;
/// ```
#[cfg(all(
unix,
not(target_os = "solaris"),
not(target_os = "illumos"),
not(target_os = "cygwin"),
))]
#[must_use]
pub const fn reuseport(mut self, enabled: bool) -> Self {
self.socket_options = self.socket_options.reuseport(enabled);
self
}
}