Handle unknown socket kind

This commit is contained in:
Aviv Palivoda committed 2019-03-08 16:19:26 +02:00
1 parent 40c10ab70a
commit 3fae8ccfbc
2 files changed
+8 -5

No files matched your search

+3
View File
@@ -77,3 +77,6 @@ sock3.close()
### Errors
with assertRaises(OSError):
socket.socket(100, socket.SOCK_STREAM)
with assertRaises(OSError):
socket.socket(socket.AF_INET, 1000)
+5 -5
View File
@@ -41,11 +41,11 @@ enum SocketKind {
}
impl SocketKind {
fn from_i32(value: i32) -> SocketKind {
fn from_i32(vm: &mut VirtualMachine, value: i32) -> Result<SocketKind, PyObjectRef> {
match value {
1 => SocketKind::Stream,
2 => SocketKind::Dgram,
_ => panic!("Unknown value: {}", value),
1 => Ok(SocketKind::Stream),
2 => Ok(SocketKind::Dgram),
_ => Err(vm.new_os_error(format!("Unknown socket kind value: {}", value))),
}
}
}
@@ -148,7 +148,7 @@ fn socket_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let address_family =
AddressFamily::from_i32(vm, objint::get_value(family_int).to_i32().unwrap())?;
let kind = SocketKind::from_i32(objint::get_value(kind_int).to_i32().unwrap());
let kind = SocketKind::from_i32(vm, objint::get_value(kind_int).to_i32().unwrap())?;
let socket = RefCell::new(Socket::new(address_family, kind));