Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys::socket adding sockopt::LingerSec for Apple targets. #2572

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

devnexen
Copy link
Contributor

#define SO_LINGER 0x0080 /* linger on close if data present (in ticks) */
#define SO_LINGER_SEC 0x1080 /* linger on close if data present (in seconds) */

Comment on lines 1100 to 1115
#[cfg(apple_targets)]
sockopt_impl!(
LingerSec,
Both,
libc::SOL_SOCKET,
libc::SO_LINGER_SEC,
libc::linger
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you forgot to remove this:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I did the same than with the above test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emmm, why do we need to define it here?

Copy link
Contributor Author

@devnexen devnexen Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to "fix" both tests if you like ? I guess this is because of this ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this module mod sockopt_impl { is for testing the sockopt_impl! macro, we made it and related stuff public in #2556 so that users can define socket options without contributing to Nix. We should not put the fn test_linger_sec() test here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the test before that module, and if so, I guess we do not need to re-define the LingerSec socket option

Comment on lines 377 to 378
/// `SO_LINGER_SEC` on apple targets is the genuine equivalent to
/// other platforms `SO_LINGER`. Indeed, the latter uses ticks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the genuine equivalent to other platforms SO_LINGER.

This makes me feel that macOS does not provide SO_LINGER but only SO_LINGER_SEC, can we just say something like:

Same as SO_LINGETR, but the duration is in seconds rather than kernel ticks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me feel that macOS does not provide SO_LINGER but only SO_LINGER_SEC

oh apple does provide it (see my commit message, that s the C header snapshot).

, can we just say something like:

Same as SO_LINGETR, but the duration is in seconds rather than kernel ticks.

Sure.

@devnexen devnexen force-pushed the sockopt_so_linger_sec branch from 925d413 to 28d4ca9 Compare December 29, 2024 08:22
Comment on lines 1073 to 1099
sockopt_impl!(
Linger,
Both,
libc::SOL_SOCKET,
libc::SO_LINGER,
libc::linger
);
#[test]
fn test_linger() {
let fd = socket(
AddressFamily::Inet,
SockType::Stream,
SockFlag::empty(),
None,
)
.unwrap();

let set_linger = libc::linger {
l_onoff: 1,
l_linger: 42,
};
setsockopt(&fd, Linger, &set_linger).unwrap();

let get_linger = getsockopt(&fd, Linger).unwrap();
assert_eq!(get_linger.l_linger, set_linger.l_linger);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other changes look good. Could you please not remove this test from this module, it is for user-defined socket options rather than the one provided by Nix

@devnexen devnexen force-pushed the sockopt_so_linger_sec branch from 47e027a to 4b21447 Compare December 30, 2024 04:41
Copy link
Member

@SteveLauC SteveLauC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@SteveLauC SteveLauC added this pull request to the merge queue Dec 30, 2024
Merged via the queue into nix-rust:master with commit 826203a Dec 30, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants