Skip to content

Extend the socket module #1176

Closed
Closed

Description

@windelbouwman

The socket module is still incomplete. Many methods and types are missing. To add methods to this module, edit the file vm/src/stdlib/socket.rs accordingly.

Activity

  1. posutsai commented on Aug 12, 2019

    @posutsai

    Hi, I would like to contribute to extending the socket module. Are there any remaining methods which are not assigned to anybody? Should I open another issue and specify which method I want, preventing others from doing the same thing? Or which method is the first priority?

  2. windelbouwman commented on Aug 12, 2019

    @windelbouwman
    ContributorAuthor

    @posutsai you could add a series of checkboxes in this issue, and mention what you implement. There is not a fixed list, but there is a helper script to determine the missing methods, called whats_left.sh

    I think it is good to mention here what you will start on.

  3. palaviv commented on Aug 13, 2019

    @palaviv
    Contributor

    Hi, I would like to contribute to extending the socket module. Are there any remaining methods which are not assigned to anybody? Should I open another issue and specify which method I want, preventing others from doing the same thing? Or which method is the first priority?

    I would recommend trying to implement the methods needed by socketserver as it is something that would be great to add. From a quick look we should add:

    • gettimeout
    • setsockopt
    • shutdown
  4. posutsai commented on Aug 22, 2019

    @posutsai

    @palaviv
    I start with setsockopt function. However, I meet issues at the beginning and I can't find a great existing solution on google. I would like to hear your comment or any suggestion.

    According to the document on the official Python website, setsockopt takes three or four arguments. However, as I know, Rust doesn't provide function overloading. It is possible to do it with trait if it takes three arguments in each implementation.

    I have referred to the implementation of sendto and there is also an optional argument flag on the document. Seems like current implementation simply ignores the optional argument.

    Could you give me some hint to implement the function? Sorry for asking such an elementary question, since I just start to learn rust and try to understand it deeper by solving a real problem.

  5. windelbouwman commented on Aug 23, 2019

    @windelbouwman
    ContributorAuthor

    Hi @posutsai ,

    Your best option at this point would be to use OptionalArg in some way like this:

    fn setsockopt(level: PyIntRef, optname: PyObjectRef, value: OptionalArg<PyObjectRef>, optlen: OptionalArg<PyObjectRef>, vm: &VirtualMachine) {
        // handle value and optlen combinations here:
        if value.is(vm.get_none()) {
              if let Present = oplen {
              } else {
                  return Err(vm.new_type_error("optlen must be supplied when value is None"));
              }
        } else {
              if let Present = oplen {
                  return Err(vm.new_type_error("optlen must not be supplied when value is not None"));
              }
        }
    }

    We did not yet build function polymorphism macros into rustpython, and rust does not support it, so this is currently the way to go forwards.

  6. rodrigocam commented on Oct 22, 2020

    @rodrigocam
    Contributor

    Hello, may I implement sendfile method?

  7. coolreader18 commented on Oct 22, 2020

    @coolreader18
    Member

    @rodrigocam Yeah, feel free to take a shot at it!

  8. rodrigocam commented on Oct 22, 2020

    @rodrigocam
    Contributor

    What do you think of this implementation? I'm using the algorithm os::read uses to fill the byte buffer that we are going to send.

        #[pymethod]
        fn sendfile(&self, fd: i64, offset: OptionalArg<u64>, count: OptionalArg<u64>, vm: &VirtualMachine) -> PyResult<usize> {
            let mut file = rust_file(fd);
            let mut bufsize: u64 = 0;
    
            if let Ok(metadata) = file.metadata() {
                bufsize = metadata.len();
            }
    
            if let OptionalArg::Present(c) = count {
                bufsize = c;
            }
    
            let mut buffer = vec![0u8; bufsize as usize];
    
            let n = file
                .read(&mut buffer)
                .map_err(|err| err.into_pyexception(vm))?;
    
            buffer.truncate(n);
    
            let bytes = PyBytesLike::try_from_object(vm, vm.ctx.new_bytes(buffer))?;
            self.send(bytes, vm)
        }
    
    
  9. coolreader18 commented on Oct 24, 2020

    @coolreader18
    Member

    @rodrigocam looks pretty good! Do you wanna make a PR for that?

  10. rodrigocam commented on Oct 26, 2020

    @rodrigocam
    Contributor
  11. hk1997 commented on Sep 9, 2021

    @hk1997

    Hi, I would like to contribute to this.
    Is it still open?
    Are there some methods which need to be implemented?

  12. DimitrisJim commented on Sep 9, 2021

    @DimitrisJim
    Member

    From a quick comparison I see gethostbyname_ex missing and a good number of the constants that are exported.

  13. nbykovsky commented on Sep 29, 2021

    @nbykovsky

    Hi there, I want to start contributing with something. Are here any methods which needs to be implemented?

  14. DimitrisJim commented on Sep 29, 2021

    @DimitrisJim
    Member

    my previous comment still stands, (also, try running whats_left and seeing what it reports for socket).

  15. varun-krishnan commented on Oct 10, 2021

    @varun-krishnan
    Contributor

    if no one has taken gethostbyname_ex, can I take a crack at it?

  16. youknowone commented on Jun 1, 2022

    @youknowone
    Member

    yes, exactly

  17. youknowone commented on Jun 1, 2022

    @youknowone
    Member

    it seems most of features are done but many properties left

  18. linked a pull request that will close this issueAdd `_socket` constants from CPython 3.10 #3840on Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions