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
/*-
* socket9 - A RAW networking sockets manipulation and configration basing on
* strong types.
*
* Copyright (C) 2021 Aleksandr Morozov, Lucia Hoffmann
* Copyright (C) 2025 Aleksandr Morozov
*
* The syslog-rs crate can be redistributed and/or modified
* under the terms of either of the following licenses:
*
* 1. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016 OR
*
* 2. the Mozilla Public License Version 2.0 (the “MPL”) OR
*
* 3. The MIT License (MIT)
*/
use std::{ffi::c_int, fmt, time::Duration};
use crate::{OptRMarker, OptWMarker, SockOptMarker};
use crate::{SOL_SOCKET, SO_LINGER, linger};
/// > linger on close if data present
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct SoLinger(linger);
#[cfg(windows)]
impl fmt::Debug for SoLinger
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
f.debug_tuple("SoLinger").finish()
}
}
#[cfg(unix)]
impl fmt::Debug for SoLinger
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
f.debug_tuple("SoLinger").field(&self.0).finish()
}
}
impl SockOptMarker for SoLinger
{
const SO_LEVEL: c_int = SOL_SOCKET;
const SO_OPTNAME: c_int = SO_LINGER;
type DataType = Option<Duration>;
type InputType = linger;
#[inline]
fn from(value: Self::InputType) -> Self
{
return Self(value);
}
#[inline]
fn get(self) -> Self::DataType
{
return
if self.0.l_onoff == 0
{
None
}
else
{
Some(Duration::from_secs(self.0.l_linger as u64))
};
}
fn from_user(dur: Self::DataType)-> Self where Self: Sized
{
return Self(
match dur
{
Some(duration) =>
linger{ l_onoff: 1, l_linger: duration.as_secs() as _},
None =>
linger {l_onoff: 0, l_linger: 0,}
}
);
}
}
impl OptRMarker for SoLinger {}
impl OptWMarker for SoLinger {}