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

Extend the socket module #1176

Open
windelbouwman opened this issue Jul 24, 2019 · 5 comments
Open

Extend the socket module #1176

windelbouwman opened this issue Jul 24, 2019 · 5 comments

Comments

@windelbouwman
Copy link
Member

@windelbouwman windelbouwman commented Jul 24, 2019

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.

@posutsai
Copy link

@posutsai posutsai commented Aug 12, 2019

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?

@windelbouwman
Copy link
Member Author

@windelbouwman windelbouwman commented Aug 12, 2019

@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.

@palaviv
Copy link
Contributor

@palaviv palaviv commented Aug 13, 2019

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
@posutsai
Copy link

@posutsai posutsai commented Aug 22, 2019

@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.

@windelbouwman
Copy link
Member Author

@windelbouwman windelbouwman commented Aug 23, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.