"""
Auto-generated Python stub file from socket.py
Module: socket
"""


import t, c
from stdint import *
import string
import platmacro
import stdio
import w32.winsock2

AF_INET: t.CDefine = 2
AF_INET6: t.CDefine = 10
SOCK_STREAM: t.CDefine = 1
SOCK_DGRAM: t.CDefine = 2
SOCK_RAW: t.CDefine = 3
IPPROTO_TCP: t.CDefine = 6
IPPROTO_UDP: t.CDefine = 17
SOL_SOCKET: t.CDefine = 1
SO_RCVTIMEO: t.CDefine = 20
SO_SNDTIMEO: t.CDefine = 21
SO_REUSEADDR: t.CDefine = 2
INADDR_ANY: t.CDefine = 0
SOCKET_ERROR: t.CDefine = -1
INVALID_SOCKET: t.CDefine = -1
SOCKET_DEFAULT_TIMEOUT: t.CDefine = 0

class SocketAddr:
    family: u16
    port: u16
    addr: u32
    zero: u64
class HostEnt:
    h_name: CHARPTR
    h_aliases: CHARPTR
    h_addrtype: INT
    h_length: INT
    h_addr_list: CHARPTR
class timeval:
    tv_sec: INT
    tv_usec: INT

def socket(family: INT, type: INT, protocol: INT) -> u64 | t.CExtern | t.CExport: pass

def connect(fd: u64, addr: SocketAddr | t.CPtr, addrlen: INT) -> INT | t.CExtern | t.CExport: pass

def send(fd: u64, buf: t.CVoid | t.CPtr, len: INT, flags: INT) -> INT | t.CExtern | t.CExport: pass

def recv(fd: u64, buf: t.CVoid | t.CPtr, len: INT, flags: INT) -> INT | t.CExtern | t.CExport: pass

def bind(fd: u64, addr: SocketAddr | t.CPtr, addrlen: INT) -> INT | t.CExtern | t.CExport: pass

def listen(fd: u64, backlog: INT) -> INT | t.CExtern | t.CExport: pass

def accept(fd: u64, addr: SocketAddr | t.CPtr, addrlen: INT | t.CPtr) -> u64 | t.CExtern | t.CExport: pass

def setsockopt(fd: u64, level: INT, optname: INT, optval: t.CVoid | t.CPtr, optlen: INT) -> INT | t.CExtern | t.CExport: pass

def gethostbyname(name: t.CChar | t.CConst | t.CPtr) -> HostEnt | t.CPtr | t.CExtern | t.CExport: pass

def ntohs(netshort: u16) -> u16 | t.CExtern | t.CExport: pass

def htons(hostshort: u16) -> u16 | t.CExtern | t.CExport: pass

def close(fd: u64) -> INT | t.CExtern | t.CExport: pass

def _CloseFd(fd: INT) -> INT: pass

def _MakeAddr(host: str, port: INT) -> SocketAddr: pass

def _ParseIPv4(ip_str: str, out_addr: u32 | t.CPtr) -> bool: pass


class Socket:
    fd: INT
    family: INT
    type: INT
    protocol: INT
    def __init__(self: Socket, family: INT, type: INT, protocol: INT) -> t.CInt: pass
    def connect(self: Socket, host: str, port: INT) -> INT: pass
    def send(self: Socket, data: t.CVoid | t.CPtr, length: INT) -> INT: pass
    def recv(self: Socket, buf: t.CVoid | t.CPtr, bufsize: INT) -> INT: pass
    def sendall(self: Socket, data: t.CVoid | t.CPtr, length: INT) -> INT: pass
    def close(self: Socket) -> INT: pass
    def bind(self: Socket, host: str, port: INT) -> INT: pass
    def listen(self: Socket, backlog: INT) -> INT: pass
    def accept(self: Socket, out_client: 'Socket' | t.CPtr) -> INT: pass
    def settimeout(self: Socket, timeout_ms: INT) -> INT: pass
    def fileno(self: Socket) -> INT: pass

def SocketInit() -> INT: pass

def SocketCleanup() -> INT: pass

def SocketCreate(family: INT, type: INT, protocol: INT, out_sock: Socket | t.CPtr) -> INT: pass

def SocketConnect(sock: Socket | t.CPtr, host: str, port: INT) -> INT: pass

def SocketSend(sock: Socket | t.CPtr, data: t.CVoid | t.CPtr, length: INT) -> INT: pass

def SocketRecv(sock: Socket | t.CPtr, buf: t.CVoid | t.CPtr, bufsize: INT) -> INT: pass

def SocketClose(sock: Socket | t.CPtr) -> INT: pass

def SocketBind(sock: Socket | t.CPtr, host: str, port: INT) -> INT: pass

def SocketListen(sock: Socket | t.CPtr, backlog: INT) -> INT: pass

def SocketAccept(sock: Socket | t.CPtr, out_client: Socket | t.CPtr) -> INT: pass

def SocketSetTimeout(sock: Socket | t.CPtr, timeout_ms: INT) -> INT: pass

def SocketIsValid(sock: Socket | t.CPtr) -> bool: pass
