Added type hints to socket
This commit is contained in:
parent
71ec419da6
commit
9116470fd7
@ -93,7 +93,7 @@ STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
|
||||
}
|
||||
}
|
||||
|
||||
//| def bind(self, address: tuple) -> Any:
|
||||
//| def bind(self, address: tuple) -> None:
|
||||
//| """Bind a socket to an address
|
||||
//|
|
||||
//| :param ~tuple address: tuple of (remote_address, remote_port)"""
|
||||
@ -120,7 +120,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
|
||||
|
||||
//| def listen(self, backlog: int) -> Any:
|
||||
//| def listen(self, backlog: int) -> None:
|
||||
//| """Set socket to listen for incoming connections
|
||||
//|
|
||||
//| :param ~int backlog: length of backlog queue for waiting connetions"""
|
||||
@ -145,7 +145,7 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
|
||||
|
||||
//| def accept(self) -> Any:
|
||||
//| def accept(self) -> tuple:
|
||||
//| """Accept a connection on a listening socket of type SOCK_STREAM,
|
||||
//| creating a new socket of type SOCK_STREAM.
|
||||
//| Returns a tuple of (new_socket, remote_address)"""
|
||||
@ -182,7 +182,7 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
|
||||
|
||||
//| def connect(self, address: tuple) -> Any:
|
||||
//| def connect(self, address: tuple) -> None:
|
||||
//| """Connect a socket to a remote address
|
||||
//|
|
||||
//| :param ~tuple address: tuple of (remote_address, remote_port)"""
|
||||
@ -209,7 +209,7 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
|
||||
|
||||
//| def send(self, bytes: bytes) -> Any:
|
||||
//| def send(self, bytes: bytes) -> int:
|
||||
//| """Send some bytes to the connected remote address.
|
||||
//| Suits sockets of type SOCK_STREAM
|
||||
//|
|
||||
@ -246,7 +246,7 @@ STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_
|
||||
}
|
||||
|
||||
|
||||
//| def recv_into(self, buffer: bytearray, bufsize: int) -> Any:
|
||||
//| def recv_into(self, buffer: WriteableBuffer, bufsize: int) -> int:
|
||||
//| """Reads some bytes from the connected remote address, writing
|
||||
//| into the provided buffer. If bufsize <= len(buffer) is given,
|
||||
//| a maximum of bufsize bytes will be read into the buffer. If no
|
||||
@ -282,7 +282,7 @@ STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_into_obj, 2, 3, socket_recv_into);
|
||||
|
||||
//| def recv(self, bufsize: int) -> Any:
|
||||
//| def recv(self, bufsize: int) -> bytes:
|
||||
//| """Reads some bytes from the connected remote address.
|
||||
//| Suits sockets of type SOCK_STREAM
|
||||
//| Returns a bytes() of length <= bufsize
|
||||
@ -309,7 +309,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv);
|
||||
|
||||
//| def sendto(self, bytes: bytes, address: tuple) -> Any:
|
||||
//| def sendto(self, bytes: bytes, address: tuple) -> int:
|
||||
//| """Send some bytes to a specific address.
|
||||
//| Suits sockets of type SOCK_DGRAM
|
||||
//|
|
||||
@ -343,7 +343,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
|
||||
|
||||
//| def recvfrom(self, bufsize: int) -> Any:
|
||||
//| def recvfrom(self, bufsize: int) -> Tuple[bytes, tuple]:
|
||||
//| """Reads some bytes from the connected remote address.
|
||||
//| Suits sockets of type SOCK_STREAM
|
||||
//|
|
||||
@ -382,7 +382,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
|
||||
|
||||
//| def setsockopt(self, level: Any, optname: Any, value: Any) -> Any:
|
||||
//| def setsockopt(self, level: int, optname: int, value: int) -> None:
|
||||
//| """Sets socket options"""
|
||||
//| ...
|
||||
//|
|
||||
@ -416,7 +416,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt);
|
||||
|
||||
//| def settimeout(self, value: int) -> Any:
|
||||
//| def settimeout(self, value: int) -> None:
|
||||
//| """Set the timeout value for this socket.
|
||||
//|
|
||||
//| :param ~int value: timeout in seconds. 0 means non-blocking. None means block indefinitely."""
|
||||
@ -447,7 +447,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout);
|
||||
|
||||
//| def setblocking(self, flag: bool) -> Any:
|
||||
//| def setblocking(self, flag: bool) -> Optional[int]:
|
||||
//| """Set the blocking behaviour of this socket.
|
||||
//|
|
||||
//| :param ~bool flag: False means non-blocking, True means block indefinitely."""
|
||||
|
Loading…
Reference in New Issue
Block a user