Skip to content

Commit 11572c2

Browse files
committed
Annotate sockopts for docsrs
1 parent e79b421 commit 11572c2

File tree

1 file changed

+54
-29
lines changed

1 file changed

+54
-29
lines changed

src/sys/socket/sockopt.rs

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ macro_rules! getsockopt_impl {
129129
/// * `$ty:ty`: type of the value that will be get/set.
130130
/// * `$getter:ty`: `Get` implementation; optional; only for `GetOnly` and `Both`.
131131
/// * `$setter:ty`: `Set` implementation; optional; only for `SetOnly` and `Both`.
132-
// TODO: make sockopt_impl work with:
133-
// * cfg(doc) (and therefore feature!)
134132
macro_rules! sockopt_impl {
135133
($(#[$attr:meta])* $name:ident, GetOnly, $level:expr, $flag:path, bool) => {
136134
sockopt_impl!($(#[$attr])*
@@ -254,8 +252,9 @@ sockopt_impl!(
254252
/// Permits multiple AF_INET or AF_INET6 sockets to be bound to an
255253
/// identical socket address.
256254
ReusePort, Both, libc::SOL_SOCKET, libc::SO_REUSEPORT, bool);
257-
#[cfg(feature = "net")]
258255
sockopt_impl!(
256+
#[cfg(feature = "net")]
257+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
259258
/// Under most circumstances, TCP sends data when it is presented; when
260259
/// outstanding data has not yet been acknowledged, it gathers small amounts
261260
/// of output to be sent in a single packet once an acknowledgement is
@@ -269,24 +268,28 @@ sockopt_impl!(
269268
/// queued messages for the socket have been successfully sent or the
270269
/// linger timeout has been reached.
271270
Linger, Both, libc::SOL_SOCKET, libc::SO_LINGER, libc::linger);
272-
#[cfg(feature = "net")]
273271
sockopt_impl!(
272+
#[cfg(feature = "net")]
273+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
274274
/// Join a multicast group
275275
IpAddMembership, SetOnly, libc::IPPROTO_IP, libc::IP_ADD_MEMBERSHIP,
276276
super::IpMembershipRequest);
277-
#[cfg(feature = "net")]
278277
sockopt_impl!(
278+
#[cfg(feature = "net")]
279+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
279280
/// Leave a multicast group.
280281
IpDropMembership, SetOnly, libc::IPPROTO_IP, libc::IP_DROP_MEMBERSHIP,
281282
super::IpMembershipRequest);
282283
cfg_if! {
283284
if #[cfg(any(target_os = "android", target_os = "linux"))] {
284-
#[cfg(feature = "net")]
285285
sockopt_impl!(
286+
#[cfg(feature = "net")]
287+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
286288
/// Join an IPv6 multicast group.
287289
Ipv6AddMembership, SetOnly, libc::IPPROTO_IPV6, libc::IPV6_ADD_MEMBERSHIP, super::Ipv6MembershipRequest);
288-
#[cfg(feature = "net")]
289290
sockopt_impl!(
291+
#[cfg(feature = "net")]
292+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
290293
/// Leave an IPv6 multicast group.
291294
Ipv6DropMembership, SetOnly, libc::IPPROTO_IPV6, libc::IPV6_DROP_MEMBERSHIP, super::Ipv6MembershipRequest);
292295
} else if #[cfg(any(target_os = "dragonfly",
@@ -297,31 +300,36 @@ cfg_if! {
297300
target_os = "netbsd",
298301
target_os = "openbsd",
299302
target_os = "solaris"))] {
300-
#[cfg(feature = "net")]
301303
sockopt_impl!(
304+
#[cfg(feature = "net")]
305+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
302306
/// Join an IPv6 multicast group.
303307
Ipv6AddMembership, SetOnly, libc::IPPROTO_IPV6,
304308
libc::IPV6_JOIN_GROUP, super::Ipv6MembershipRequest);
305-
#[cfg(feature = "net")]
306309
sockopt_impl!(
310+
#[cfg(feature = "net")]
311+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
307312
/// Leave an IPv6 multicast group.
308313
Ipv6DropMembership, SetOnly, libc::IPPROTO_IPV6,
309314
libc::IPV6_LEAVE_GROUP, super::Ipv6MembershipRequest);
310315
}
311316
}
312-
#[cfg(feature = "net")]
313317
sockopt_impl!(
318+
#[cfg(feature = "net")]
319+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
314320
/// Set or read the time-to-live value of outgoing multicast packets for
315321
/// this socket.
316322
IpMulticastTtl, Both, libc::IPPROTO_IP, libc::IP_MULTICAST_TTL, u8);
317-
#[cfg(feature = "net")]
318323
sockopt_impl!(
324+
#[cfg(feature = "net")]
325+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
319326
/// Set or read a boolean integer argument that determines whether sent
320327
/// multicast packets should be looped back to the local sockets.
321328
IpMulticastLoop, Both, libc::IPPROTO_IP, libc::IP_MULTICAST_LOOP, bool);
322329
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
323-
#[cfg(feature = "net")]
324330
sockopt_impl!(
331+
#[cfg(feature = "net")]
332+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
325333
/// If enabled, this boolean option allows binding to an IP address that
326334
/// is nonlocal or does not (yet) exist.
327335
IpFreebind, Both, libc::IPPROTO_IP, libc::IP_FREEBIND, bool);
@@ -360,8 +368,9 @@ sockopt_impl!(
360368
PeerCredentials, GetOnly, libc::SOL_SOCKET, libc::SO_PEERCRED, super::UnixCredentials);
361369
#[cfg(any(target_os = "ios",
362370
target_os = "macos"))]
363-
#[cfg(feature = "net")]
364371
sockopt_impl!(
372+
#[cfg(feature = "net")]
373+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
365374
/// Specify the amount of time, in seconds, that the connection must be idle
366375
/// before keepalive probes (if enabled) are sent.
367376
TcpKeepAlive, Both, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, u32);
@@ -370,8 +379,9 @@ sockopt_impl!(
370379
target_os = "freebsd",
371380
target_os = "linux",
372381
target_os = "nacl"))]
373-
#[cfg(feature = "net")]
374382
sockopt_impl!(
383+
#[cfg(feature = "net")]
384+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
375385
/// The time (in seconds) the connection needs to remain idle before TCP
376386
/// starts sending keepalive probes
377387
TcpKeepIdle, Both, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, u32);
@@ -387,8 +397,9 @@ cfg_if! {
387397
}
388398
}
389399
#[cfg(not(target_os = "openbsd"))]
390-
#[cfg(feature = "net")]
391400
sockopt_impl!(
401+
#[cfg(feature = "net")]
402+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
392403
/// The maximum number of keepalive probes TCP should send before
393404
/// dropping the connection.
394405
TcpKeepCount, Both, libc::IPPROTO_TCP, libc::TCP_KEEPCNT, u32);
@@ -400,13 +411,15 @@ sockopt_impl!(
400411
// Not documented by Linux!
401412
TcpRepair, Both, libc::IPPROTO_TCP, libc::TCP_REPAIR, u32);
402413
#[cfg(not(target_os = "openbsd"))]
403-
#[cfg(feature = "net")]
404414
sockopt_impl!(
415+
#[cfg(feature = "net")]
416+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
405417
/// The time (in seconds) between individual keepalive probes.
406418
TcpKeepInterval, Both, libc::IPPROTO_TCP, libc::TCP_KEEPINTVL, u32);
407419
#[cfg(any(target_os = "fuchsia", target_os = "linux"))]
408-
#[cfg(feature = "net")]
409420
sockopt_impl!(
421+
#[cfg(feature = "net")]
422+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
410423
/// Specifies the maximum amount of time in milliseconds that transmitted
411424
/// data may remain unacknowledged before TCP will forcibly close the
412425
/// corresponding connection
@@ -441,8 +454,9 @@ sockopt_impl!(
441454
/// Bind this socket to a particular device like “eth0”.
442455
BindToDevice, Both, libc::SOL_SOCKET, libc::SO_BINDTODEVICE, OsString<[u8; libc::IFNAMSIZ]>);
443456
#[cfg(any(target_os = "android", target_os = "linux"))]
444-
#[cfg(feature = "net")]
445457
sockopt_impl!(
458+
#[cfg(feature = "net")]
459+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
446460
#[allow(missing_docs)]
447461
// Not documented by Linux!
448462
OriginalDst, GetOnly, libc::SOL_IP, libc::SO_ORIGINAL_DST, libc::sockaddr_in);
@@ -459,19 +473,22 @@ sockopt_impl!(
459473
/// Enable or disable the receiving of the `SO_TIMESTAMPNS` control message.
460474
ReceiveTimestampns, Both, libc::SOL_SOCKET, libc::SO_TIMESTAMPNS, bool);
461475
#[cfg(any(target_os = "android", target_os = "linux"))]
462-
#[cfg(feature = "net")]
463476
sockopt_impl!(
477+
#[cfg(feature = "net")]
478+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
464479
/// Setting this boolean option enables transparent proxying on this socket.
465480
IpTransparent, Both, libc::SOL_IP, libc::IP_TRANSPARENT, bool);
466481
#[cfg(target_os = "openbsd")]
467-
#[cfg(feature = "net")]
468482
sockopt_impl!(
483+
#[cfg(feature = "net")]
484+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
469485
/// Allows the socket to be bound to addresses which are not local to the
470486
/// machine, so it can be used to make a transparent proxy.
471487
BindAny, Both, libc::SOL_SOCKET, libc::SO_BINDANY, bool);
472488
#[cfg(target_os = "freebsd")]
473-
#[cfg(feature = "net")]
474489
sockopt_impl!(
490+
#[cfg(feature = "net")]
491+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
475492
/// Can `bind(2)` to any address, even one not bound to any available
476493
/// network interface in the system.
477494
BindAny, Both, libc::IPPROTO_IP, libc::IP_BINDANY, bool);
@@ -486,8 +503,9 @@ sockopt_impl!(
486503
/// message.
487504
PassCred, Both, libc::SOL_SOCKET, libc::SO_PASSCRED, bool);
488505
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
489-
#[cfg(feature = "net")]
490506
sockopt_impl!(
507+
#[cfg(feature = "net")]
508+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
491509
/// This option allows the caller to set the TCP congestion control
492510
/// algorithm to be used, on a per-socket basis.
493511
TcpCongestion, Both, libc::IPPROTO_TCP, libc::TCP_CONGESTION, OsString<[u8; TCP_CA_NAME_MAX]>);
@@ -498,8 +516,9 @@ sockopt_impl!(
498516
target_os = "macos",
499517
target_os = "netbsd",
500518
))]
501-
#[cfg(feature = "net")]
502519
sockopt_impl!(
520+
#[cfg(feature = "net")]
521+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
503522
/// Pass an `IP_PKTINFO` ancillary message that contains a pktinfo
504523
/// structure that supplies some information about the incoming packet.
505524
Ipv4PacketInfo, Both, libc::IPPROTO_IP, libc::IP_PKTINFO, bool);
@@ -512,8 +531,9 @@ sockopt_impl!(
512531
target_os = "netbsd",
513532
target_os = "openbsd",
514533
))]
515-
#[cfg(feature = "net")]
516534
sockopt_impl!(
535+
#[cfg(feature = "net")]
536+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
517537
/// Set delivery of the `IPV6_PKTINFO` control message on incoming
518538
/// datagrams.
519539
Ipv6RecvPacketInfo, Both, libc::IPPROTO_IPV6, libc::IPV6_RECVPKTINFO, bool);
@@ -524,8 +544,9 @@ sockopt_impl!(
524544
target_os = "netbsd",
525545
target_os = "openbsd",
526546
))]
527-
#[cfg(feature = "net")]
528547
sockopt_impl!(
548+
#[cfg(feature = "net")]
549+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
529550
/// The `recvmsg(2)` call returns a `struct sockaddr_dl` corresponding to
530551
/// the interface on which the packet was received.
531552
Ipv4RecvIf, Both, libc::IPPROTO_IP, libc::IP_RECVIF, bool);
@@ -536,20 +557,23 @@ sockopt_impl!(
536557
target_os = "netbsd",
537558
target_os = "openbsd",
538559
))]
539-
#[cfg(feature = "net")]
540560
sockopt_impl!(
561+
#[cfg(feature = "net")]
562+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
541563
/// The `recvmsg(2)` call will return the destination IP address for a UDP
542564
/// datagram.
543565
Ipv4RecvDstAddr, Both, libc::IPPROTO_IP, libc::IP_RECVDSTADDR, bool);
544566
#[cfg(target_os = "linux")]
545-
#[cfg(feature = "net")]
546567
sockopt_impl!(
568+
#[cfg(feature = "net")]
569+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
547570
#[allow(missing_docs)]
548571
// Not documented by Linux!
549572
UdpGsoSegment, Both, libc::SOL_UDP, libc::UDP_SEGMENT, libc::c_int);
550573
#[cfg(target_os = "linux")]
551-
#[cfg(feature = "net")]
552574
sockopt_impl!(
575+
#[cfg(feature = "net")]
576+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
553577
#[allow(missing_docs)]
554578
// Not documented by Linux!
555579
UdpGroSegment, Both, libc::IPPROTO_UDP, libc::UDP_GRO, bool);
@@ -559,8 +583,9 @@ sockopt_impl!(
559583
/// be attached to received skbs indicating the number of packets dropped by
560584
/// the socket since its creation.
561585
RxqOvfl, Both, libc::SOL_SOCKET, libc::SO_RXQ_OVFL, libc::c_int);
562-
#[cfg(feature = "net")]
563586
sockopt_impl!(
587+
#[cfg(feature = "net")]
588+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
564589
/// The socket is restricted to sending and receiving IPv6 packets only.
565590
Ipv6V6Only, Both, libc::IPPROTO_IPV6, libc::IPV6_V6ONLY, bool);
566591
#[cfg(any(target_os = "android", target_os = "linux"))]

0 commit comments

Comments
 (0)