]>
git.proxmox.com Git - rustc.git/blob - src/vendor/net2/src/unix.rs
1 //! Unix-specific extensions to the `std::net` types.
4 use sys
::c
::{self, c_int}
;
6 use {TcpBuilder, UdpBuilder}
;
7 use ext
::{self, AsSock}
;
9 /// Unix-specific extensions for the `TcpBuilder` type in this library.
10 pub trait UnixTcpBuilderExt
{
11 /// Set value for the `SO_REUSEPORT` option on this socket.
13 /// This indicates that futher calls to `bind` may allow reuse of local
14 /// addresses. For IPv4 sockets this means that a socket may bind even when
15 /// there's a socket already listening on this port.
16 fn reuse_port(&self, reuse
: bool
) -> io
::Result
<&Self>;
18 /// Check the value of the `SO_REUSEPORT` option on this socket.
19 fn get_reuse_port(&self) -> io
::Result
<bool
>;
22 impl UnixTcpBuilderExt
for TcpBuilder
{
23 fn reuse_port(&self, reuse
: bool
) -> io
::Result
<&Self> {
24 ext
::set_opt(self.as_sock(), c
::SOL_SOCKET
, c
::SO_REUSEPORT
,
25 reuse
as c_int
).map(|()| self)
28 fn get_reuse_port(&self) -> io
::Result
<bool
> {
29 ext
::get_opt(self.as_sock(), c
::SOL_SOCKET
, c
::SO_REUSEPORT
)
34 /// Unix-specific extensions for the `UdpBuilder` type in this library.
35 pub trait UnixUdpBuilderExt
{
36 /// Set value for the `SO_REUSEPORT` option on this socket.
38 /// This indicates that futher calls to `bind` may allow reuse of local
39 /// addresses. For IPv4 sockets this means that a socket may bind even when
40 /// there's a socket already listening on this port.
41 fn reuse_port(&self, reuse
: bool
) -> io
::Result
<&Self>;
43 /// Check the value of the `SO_REUSEPORT` option on this socket.
44 fn get_reuse_port(&self) -> io
::Result
<bool
>;
47 impl UnixUdpBuilderExt
for UdpBuilder
{
48 fn reuse_port(&self, reuse
: bool
) -> io
::Result
<&Self> {
49 ext
::set_opt(self.as_sock(), c
::SOL_SOCKET
, c
::SO_REUSEPORT
,
50 reuse
as c_int
).map(|()| self)
53 fn get_reuse_port(&self) -> io
::Result
<bool
> {
54 ext
::get_opt(self.as_sock(), c
::SOL_SOCKET
, c
::SO_REUSEPORT
)