Skip to content

Conversation

@kristof-mattei
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @kristof-mattei, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the socket non-blocking API by renaming the set_non_blocking function to set_nonblocking. This change aims to improve consistency with established Rust naming conventions and external crates like socket2, enhancing the overall clarity and maintainability of the codebase, particularly in the smol and tokio integration modules.

Highlights

  • API Renaming: The set_non_blocking function in src/socket.rs has been renamed to set_nonblocking to align with the naming conventions used in Rust's standard library and the socket2 crate.
  • Usage Updates: All instances where the set_non_blocking function was called, specifically within src/smol.rs and src/tokio.rs, have been updated to use the new set_nonblocking name.
  • Test Alignment: The corresponding test case in src/socket.rs has been updated to reflect the new function name, ensuring continued test coverage.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors set_non_blocking to set_nonblocking for consistency with the standard library and socket2 crate. The renaming is applied consistently. However, I've identified several instances where set_nonblocking is called redundantly, as the async wrappers used (async_io::Async and tokio::io::unix::AsyncFd) already configure the socket for non-blocking I/O. Some of these redundant calls could also lead to panics due to the use of .unwrap(). I've provided suggestions to remove these calls for cleaner and safer code. Additionally, I've made a minor suggestion to improve variable naming in the set_nonblocking function to avoid shadowing, which enhances code clarity.

unsafe fn from_raw_fd(fd: RawFd) -> Self {
let socket = Socket::from_raw_fd(fd);
socket.set_non_blocking(true).unwrap();
socket.set_nonblocking(true).unwrap();

Choose a reason for hiding this comment

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

high

The call to socket.set_nonblocking(true) is redundant because async_io::Async::new() already sets the file descriptor to non-blocking mode. Removing this line also eliminates a potential panic from the use of .unwrap().

unsafe fn from_raw_fd(fd: RawFd) -> Self {
let socket = Socket::from_raw_fd(fd);
socket.set_non_blocking(true).unwrap();
socket.set_nonblocking(true).unwrap();

Choose a reason for hiding this comment

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

high

The call to socket.set_nonblocking(true) is redundant because tokio::io::unix::AsyncFd::new() already sets the file descriptor to non-blocking mode. Removing this line also eliminates a potential panic from the use of .unwrap().

Comment on lines +141 to +143
let mut nonblocking = nonblocking as libc::c_int;
let res = unsafe {
libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut non_blocking)
libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut nonblocking)

Choose a reason for hiding this comment

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

medium

To improve clarity and avoid shadowing the nonblocking parameter, consider using a different name for this variable, for example mode. This aligns with general Rust API guidelines that discourage shadowing except in specific cases.

Suggested change
let mut nonblocking = nonblocking as libc::c_int;
let res = unsafe {
libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut non_blocking)
libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut nonblocking)
let mut mode = nonblocking as libc::c_int;
let res = unsafe {
libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut mode)

fn new(protocol: isize) -> io::Result<Self> {
let socket = Socket::new(protocol)?;
socket.set_non_blocking(true)?;
socket.set_nonblocking(true)?;

Choose a reason for hiding this comment

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

medium

This call to socket.set_nonblocking(true) is redundant. The AsyncFd::new(socket)? call on the next line already sets the socket to non-blocking mode, so this line can be safely removed.

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.

1 participant