Macro sockopt_impl

Source
macro_rules! sockopt_impl {
    ($(#[$attr:meta])* $name:ident, GetOnly, $level:expr, $flag:path, bool) => { ... };
    ($(#[$attr:meta])* $name:ident, GetOnly, $level:expr, $flag:path, u8) => { ... };
    ($(#[$attr:meta])* $name:ident, GetOnly, $level:expr, $flag:path, usize) => { ... };
    ($(#[$attr:meta])* $name:ident, GetOnly, $level:expr, $flag:path, OwnedFd) => { ... };
    ($(#[$attr:meta])* $name:ident, SetOnly, $level:expr, $flag:path, bool) => { ... };
    ($(#[$attr:meta])* $name:ident, SetOnly, $level:expr, $flag:path, u8) => { ... };
    ($(#[$attr:meta])* $name:ident, SetOnly, $level:expr, $flag:path, usize) => { ... };
    ($(#[$attr:meta])* $name:ident, SetOnly, $level:expr, $flag:path, OwnedFd) => { ... };
    ($(#[$attr:meta])* $name:ident, Both, $level:expr, $flag:path, bool) => { ... };
    ($(#[$attr:meta])* $name:ident, Both, $level:expr, $flag:path, u8) => { ... };
    ($(#[$attr:meta])* $name:ident, Both, $level:expr, $flag:path, usize) => { ... };
    ($(#[$attr:meta])* $name:ident, Both, $level:expr, $flag:path, OwnedFd) => { ... };
    ($(#[$attr:meta])* $name:ident, Both, $level:expr, $flag:path,
     OsString<$array:ty>) => { ... };
    ($(#[$attr:meta])* $name:ident, GetOnly, $level:expr, $flag:path, $ty:ty) => { ... };
    ($(#[$attr:meta])* $name:ident, GetOnly, $level:expr, $flag:path, $ty:ty,
     $getter:ty) => { ... };
    ($(#[$attr:meta])* $name:ident, SetOnly, $level:expr, $flag:path, $ty:ty) => { ... };
    ($(#[$attr:meta])* $name:ident, SetOnly, $level:expr, $flag:path, $ty:ty,
     $setter:ty) => { ... };
    ($(#[$attr:meta])* $name:ident, Both, $level:expr, $flag:path, $ty:ty,
     $getter:ty, $setter:ty) => { ... };
    ($(#[$attr:meta])* $name:ident, Both, $level:expr, $flag:path, $ty:ty) => { ... };
}
Expand description

Helper to generate the sockopt accessors. See ::sys::socket::GetSockOpt and ::sys::socket::SetSockOpt.

This macro aims to help implementing GetSockOpt and SetSockOpt for different socket options that accept different kinds of data to be use with getsockopt and setsockopt respectively.

Basically this macro wraps up the getsockopt_impl! and setsockopt_impl! macros.

ยงArguments

  • GetOnly, SetOnly or Both: whether you want to implement only getter, only setter or both of them.
  • $name:ident: name of type GetSockOpt/SetSockOpt will be implemented for.
  • $level:expr : socket layer, or a protocol level: could be raw sockets (libc::SOL_SOCKET), ip protocol (libc::IPPROTO_IP), tcp protocol (libc::IPPROTO_TCP), and more. Please refer to your system manual for more options. Will be passed as the second argument (level) to the getsockopt/setsockopt call.
  • $flag:path: a flag name to set. Some examples: libc::SO_REUSEADDR, libc::TCP_NODELAY, libc::IP_ADD_MEMBERSHIP and others. Will be passed as the third argument (option_name) to the setsockopt/getsockopt call.
  • $ty:ty: type of the value that will be get/set.
  • $getter:ty: Get implementation; optional; only for GetOnly and Both.
  • $setter:ty: Set implementation; optional; only for SetOnly and Both.