|
205 | 205 | //! ## Idle connection timeout
|
206 | 206 | //!
|
207 | 207 | //! Now, for this example in particular, we need set the idle connection timeout.
|
208 |
| -//! Otherwise, the connection will be closed immediately. |
| 208 | +//! The default connection timeout is 10 seconds. |
209 | 209 | //!
|
210 | 210 | //! Whether you need to set this in your application too depends on your usecase.
|
211 | 211 | //! Typically, connections are kept alive if they are "in use" by a certain protocol.
|
212 | 212 | //! The ping protocol however is only an "auxiliary" kind of protocol.
|
213 |
| -//! Thus, without any other behaviour in place, we would not be able to observe the pings. |
| 213 | +//! Thus, without any other behaviour in place, we would not be able to observe any pings after 10s. |
214 | 214 | //!
|
215 | 215 | //! ```rust
|
216 | 216 | //! use std::{error::Error, time::Duration};
|
|
232 | 232 | //! yamux::Config::default,
|
233 | 233 | //! )?
|
234 | 234 | //! .with_behaviour(|_| ping::Behaviour::default())?
|
| 235 | +//! .with_swarm_config(|cfg| { |
| 236 | +//! cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX)) |
| 237 | +//! }) // Allows us to observe pings indefinitely. |
235 | 238 | //! .build();
|
236 | 239 | //!
|
237 | 240 | //! Ok(())
|
|
284 | 287 | //! yamux::Config::default,
|
285 | 288 | //! )?
|
286 | 289 | //! .with_behaviour(|_| ping::Behaviour::default())?
|
| 290 | +//! .with_swarm_config(|cfg| { |
| 291 | +//! cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX)) |
| 292 | +//! }) // Allows us to observe pings indefinitely. |
287 | 293 | //! .build();
|
288 | 294 | //!
|
289 | 295 | //! // Tell the swarm to listen on all interfaces and a random, OS-assigned
|
|
329 | 335 | //! yamux::Config::default,
|
330 | 336 | //! )?
|
331 | 337 | //! .with_behaviour(|_| ping::Behaviour::default())?
|
| 338 | +//! .with_swarm_config(|cfg| { |
| 339 | +//! cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX)) |
| 340 | +//! }) // Allows us to observe pings indefinitely. |
332 | 341 | //! .build();
|
333 | 342 | //!
|
334 | 343 | //! // Tell the swarm to listen on all interfaces and a random, OS-assigned
|
|
0 commit comments