HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/internet/iocpreactor/__pycache__/tcp.cpython-38.pyc
U

��W[�N�@s�dZddlZddlZddlZddlZddlmZmZddlm	Z	m
Z
mZmZm
Z
ddlmZddlmZmZddlmZmZmZmZmZmZmZddlmZmZmZdd	l m!Z!m"Z"dd
l#m$Z%m&Z&ddl'm(Z(ddl)m*Z*dd
l)m+Z+ddl)m,Z,ddl)m-Z-ddl)m.Z.zddl/m0Z1Wne2k
�r6dZ1YnXe-ej3e.ej4iZ5ee(e	j6e	j7�Gdd�de&j8ee��Z9e1dk	�r�ee9e	j:�Gdd�deee9�Z;Gdd�de9�Z<Gdd�de�Zee	j=�Gdd�dee��Z>dS)z
TCP support for IOCP reactor
�N)�implementer�classImplements)�
interfaces�error�address�main�defer)�Protocol)�	_LogOwner�
isIPv6Address)�
_SocketCloser�	Connector�_AbortingMixin�_BaseBaseClient�_BaseTCPClient�_resolveIPv6�_getsockname)�log�failure�reflect)�_PY3�nativeString)�iocpsupport�abstract)�IReadWriteHandle)�ERROR_IO_PENDING)�SO_UPDATE_CONNECT_CONTEXT)�SO_UPDATE_ACCEPT_CONTEXT)�ERROR_CONNECTION_REFUSED)�ERROR_NETWORK_UNREACHABLE)�startTLSc@s�eZdZdZdZd+dd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zedk	r�d,dd �Zd!d"�Zd#d$�Zd-d%d&�Zd'd(�Zd)d*�ZdS).�
Connectionz�
    @ivar TLS: C{False} to indicate the connection is in normal TCP mode,
        C{True} to indicate that TLS has been started and that operations must
        be routed through the L{TLSMemoryBIOProtocol} instance.
    FNcCs&tj�||�||_|j|_||_dS�N)r�
FileHandle�__init__�socket�fileno�
getFileHandle�protocol)�self�sock�proto�reactor�r-�B/usr/lib/python3/dist-packages/twisted/internet/iocpreactor/tcp.pyr$3szConnection.__init__cCs|jSr")r%�r)r-r-r.�	getHandle:szConnection.getHandlecCs@t|t�rn$t|t�r t|�}ntdt|���|j�|�dS)z`
        @param rbuffer: Data received.
        @type rbuffer: L{bytes} or L{bytearray}
        z%data must be bytes or bytearray, not N)�
isinstance�bytes�	bytearray�	TypeError�typer(�dataReceived)r)Zrbufferr-r-r.r6>s


�zConnection.dataReceivedcCst�|��||�Sr")�_iocpZrecvr')r)Zbufflist�evtr-r-r.�readFromHandleOszConnection.readFromHandlecCs(t|�}t�|��|d|j���|�S)z�
        Send C{buff} to current file handle using C{_iocp.send}. The buffer
        sent is limited to a size of C{self.SEND_LIMIT}.
        r)�
memoryviewr7�sendr'Z
SEND_LIMIT�tobytes)r)�buffr8Z	writeViewr-r-r.�
writeToHandleSs

�zConnection.writeToHandlecCsrz|j�d�Wntjk
r&YnXt�|jd�}|rnz|��Wn&t��}t	�
�|�|�YnXdS)N�)r%Zshutdownrr�IHalfCloseableProtocolr(ZwriteConnectionLostr�Failurer�err�connectionLost)r)�p�fr-r-r.�_closeWriteConnection]sz Connection._closeWriteConnectioncCsRt�|jd�}|rDz|��WqNt��|�t���YqNXn
|�|�dSr")	rr@r(�readConnectionLostrrBrCrrA)r)�reasonrDr-r-r.rGlszConnection.readConnectionLostcCsX|jr
dStj�||�|dkp,|�tj�}|�|�|j}|`|`	|`
|�|�dSr")�disconnectedrr#rCZcheckrZConnectionAborted�_closeSocketr(r%r')r)rHZisCleanr(r-r-r.rCxs�
zConnection.connectionLostcCs|jS)zN
        Return the prefix to log with when I own the logging thread.
        )�logstrr/r-r-r.�	logPrefix�szConnection.logPrefixcCst�|j�tjtj��Sr")�operator�truthr%�
getsockopt�IPPROTO_TCP�TCP_NODELAYr/r-r-r.�
getTcpNoDelay�s�zConnection.getTcpNoDelaycCs|j�tjtj|�dSr")r%�
setsockoptrPrQ�r)�enabledr-r-r.�
setTcpNoDelay�szConnection.setTcpNoDelaycCst�|j�tjtj��Sr")rMrNr%rO�
SOL_SOCKET�SO_KEEPALIVEr/r-r-r.�getTcpKeepAlive�s�zConnection.getTcpKeepAlivecCs|j�tjtj|�dSr")r%rSrWrXrTr-r-r.�setTcpKeepAlive�szConnection.setTcpKeepAliveTcCst|||tj�dS)z9
            @see: L{ITLSTransport.startTLS}
            N)�	_startTLSrr#)r)ZcontextFactoryZnormalr-r-r.r �szConnection.startTLScCs0|jr
dS|jr|j�|�ntj�||�dS)z�
        Write some data, either directly to the underlying handle or, if TLS
        has been started, to the L{TLSMemoryBIOProtocol} for it to encrypt and
        send.

        @see: L{twisted.internet.interfaces.ITransport.write}
        N)rI�TLSr(�writerr#)r)�datar-r-r.r]�s
zConnection.writecCs0|jr
dS|jr|j�|�ntj�||�dS)z�
        Write some data, either directly to the underlying handle or, if TLS
        has been started, to the L{TLSMemoryBIOProtocol} for it to encrypt and
        send.

        @see: L{twisted.internet.interfaces.ITransport.writeSequence}
        N)rIr\r(�
writeSequencerr#)r)Ziovecr-r-r.r_�s
zConnection.writeSequencecCs0|jr|jr,|js,|j��ntj�||�dS)z�
        Close the underlying handle or, if TLS has been started, first shut it
        down.

        @see: L{twisted.internet.interfaces.ITransport.loseConnection}
        N)r\�	connected�
disconnectingr(�loseConnectionrr#)r)rHr-r-r.rb�szConnection.loseConnectioncCs*|jr|j�||�ntj�|||�dS)zc
        Register a producer.

        If TLS is enabled, the TLS connection handles this.
        N)r\r(�registerProducerrr#)r)ZproducerZ	streamingr-r-r.rc�szConnection.registerProducercCs"|jr|j��ntj�|�dS)ze
        Unregister a producer.

        If TLS is enabled, the TLS connection handles this.
        N)r\r(�unregisterProducerrr#r/r-r-r.rd�szConnection.unregisterProducer)N)T)N)�__name__�
__module__�__qualname__�__doc__r\r$r0r6r9r>rFrGrCrLrRrVrYrZr[r r]r_rbrcrdr-r-r-r.r!(s,



r!c@sTeZdZdZejZejZdZ	e
Zdd�Zdd�Z
dd�Zd	d
�Zdd�Zd
d�ZdS)�Clientz�
    @ivar _tlsClientDefault: Always C{True}, indicating that this is a client
        connection, and by default when TLS is negotiated this class will act as
        a TLS client.
    TcCs*|dkrd}||_t�||||||�dS)N)�r)r,rr$)r)�host�port�bindAddress�	connectorr,r-r-r.r$s�zClient.__init__cCs|j�|j|j�S)zd
        Create a socket registered with the IOCP reactor.

        @see: L{_BaseTCPClient}
        )r,�createSocket�
addressFamily�
socketTyper/r-r-r.�createInternetSocket
szClient.createInternetSocketcCs|`|`dS)z�
        Clean up potentially circular references to the socket and to its
        C{getFileHandle} method.

        @see: L{_BaseBaseClient}
        N)r%r'r/r-r-r.�_collectSocketDetailsszClient._collectSocketDetailscCs|j�|�dS)z^
        Remove the active handle from the reactor.

        @see: L{_BaseBaseClient}
        N)r,�removeActiveHandler/r-r-r.�_stopReadingAndWritingszClient._stopReadingAndWritingc	Cs�|r0t�||�}|�t�|tj�|d�f��n~|j�tj	t
t�d|j�
���|j�|���|_d|_|�|j�}|d|_|jdkr�t�|_|��n|j�|�|��dS)Nz
Unknown error�PTz,client)�connectExErrors�getZfailIfNotConnectedrZgetConnectError�errno�	errorcoder%rSrWr�struct�packr&rn�
buildProtocol�getPeerr(r`�
_getLogPrefixrKr	rb�makeConnection�startReading)r)�rcr^r8rLr-r-r.�	cbConnect&s&
�
�


zClient.cbConnectcCsft|d�sdStjst�|j�|�t�|j|�}t�|j	�
�|j|�}|rb|tkrb|�|d|�dS)Nrnr)
�hasattrr7Zhave_connectex�AssertionErrorr,�addActiveHandle�Eventr�Zconnectr%r&ZrealAddressr)r)r8r�r-r-r.�	doConnectBs

zClient.doConnectN)rerfrgrhr%�AF_INETrp�SOCK_STREAMrq�_tlsClientDefaultr!Z_commonConnectionr$rrrsrur�r�r-r-r-r.ri�s		
	ric@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�ServeraV
    Serverside socket-stream connection class.

    I am a serverside network connection transport; a socket which came from an
    accept() on a server.

    @ivar _tlsClientDefault: Always C{False}, indicating that this is a server
        connection, and by default when TLS is negotiated this class will act as
        a TLS server.
    FcCspt�||||�||_||_||_|�|j�}d|||jjf|_d|jj	j
|j|jjf|_d|_
|��dS)a

        Server(sock, protocol, client, server, sessionno)

        Initialize me with a socket, a protocol, a descriptor for my peer (a
        tuple of host, port describing the other end of the connection), an
        instance of Port, and a session number.
        z%s,%s,%sz<%s #%s on %s>TN)r!r$�
serverAddr�
clientAddr�	sessionnorr(rkrK�	__class__rerl�repstrr`r�)r)r*r(r�r�r�r,rLr-r-r.r$`s
�zServer.__init__cCs|jS)z=
        A string representation of this connection.
        )r�r/r-r-r.�__repr__tszServer.__repr__cCs|jS)zW
        Returns an IPv4Address.

        This indicates the server's address.
        )r�r/r-r-r.�getHost{szServer.getHostcCs|jS)zW
        Returns an IPv4Address.

        This indicates the client's address.
        )r�r/r-r-r.r~�szServer.getPeerN)	rerfrgrhr�r$r�r�r~r-r-r-r.r�Qs	r�c@seZdZdd�ZdS)r
cCst|j|j|j||j�Sr")rirkrlrmr,r/r-r-r.�_makeTransport�s�zConnector._makeTransportN)rerfrgr�r-r-r-r.r
�sr
c@s�eZdZdZdZdZejZej	Z
ejZ
dZdZdZddd�Zd	d
�Zdd�Ze�ej�fd
d�ZeZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z dS)�PortFrN�TCP�2rjcCs:||_||_||_||_||_t|�r6tj|_t	j
|_dSr")rl�factory�backlog�	interfacer,rr%�AF_INET6rprZIPv6Address�_addressType)r)rlr�r�r�r,r-r-r.r$�sz
Port.__init__cCs6|jdk	r d|j|jj|jfSd|j|jjfSdS)Nz<%s of %s on %s>z<%s of %s (not listening)>)�_realPortNumberr�r�r/r-r-r.r��s
��z
Port.__repr__c
CszH|j�|j|j�}|jtjkr0t|j|j�}n|j|jf}|�	|�Wn6tj
k
r~}zt
�|j|j|��W5d}~XYnXt�
|���|_|��d|_t�d|�|j�|jf�|j��|�|j�d|_d|_|j�|�||_|jj|_|��dS)Nr?z%s starting on %sTF)r,rorprqr%r�rr�rlZbindrZCannotListenErrorr7Z
maxAddrLenr&�addrLenZgetsocknamer�r�msgrr�ZdoStartZlistenr�r`rIr�r'�doAccept)r)ZsktZaddr�ler-r-r.�startListening�s.
�$�

zPort.startListeningcCs2d|_|jr.t��|_|j�d|j|�|jSdS)z�
        Stop accepting connections on this port.

        This will shut down my socket and call self.connectionLost().
        It returns a deferred which will fire successfully when the
        port is actually closed.
        TrN)rar`rZDeferred�deferredr,Z	callLaterrC)r)ZconnDoner-r-r.rb�s

zPort.loseConnectioncCst�d|j|jf�dS)z.
        Log message for closing port
        z(%s Port %s Closed)N)rr��_typer�r/r-r-r.�_logConnectionLostMsg�szPort._logConnectionLostMsgcCs�|��d|_d}t|d�r&|j}|`d|_|j�|�d|_|�d�|`	|`
z|j��Wn,d|_
|dk	r�|�t���n�YnXd|_
|dk	r�|�d�dS)z'
        Cleans up the socket.
        Nr�TF)r�r�r�r�rIr,rtr`rJr%r'r�ZdoStopraZerrbackrrA�callback)r)rH�dr-r-r.rC�s,

zPort.connectionLostcCst�|jj�S)zK
        Returns the name of my class, to prefix log entries with.
        )rZqualr�r�r/r-r-r.rLszPort.logPrefixcCs|jdt|j���S)zf
        Returns an IPv4Address or IPv6Address.

        This indicates the server's address.
        r�)r�)r�rr%r/r-r-r.r�szPort.getHostcCs$|�||�|js |js |��dSr")�handleAcceptrarIr�)r)r�r^r8r-r-r.�cbAccept'sz
Port.cbAcceptc
	Cs�|js|jrdS|r4t�dtj�|d�|f�dS|j�t	j
tt�
d|j	����t�|j��|j�\}}}ts�t|d�|df}t|d�|df}||jks�t�d|dkr�t|d�d�d�}|d|dd|f}d|dk�rt|d�d�d�}|d|dd|f}|j�|jd
|���}|dk�rB|j��nD|j}|d|_t|j||jd|��|jd|��||j�}	|�|	�d	SdS)
NFz*Could not accept new connection -- %s (%s)z
unknown errorrvrr?�%r�T)r�)r�)r�) rarIrr�ryrzrx�newsktrSr%rWrr{r|r&r7Zget_accept_addrsr=rrrpr��int�splitr�r}r��closer�r�r,r�)
r)r�r8ZfamilyZlAddrZrAddrZscoper(�sZ	transportr-r-r.r�-sP���
�

�
zPort.handleAcceptcCstt�|j|�}td|jd�|_}|j�|j|j	�|_
}t�|j�
�|�
�||�}|rp|tkrp|�||�dS)N��)r7r�r�r3r�r=r,rorprqr�Zacceptr%r&rr�)r)r8r=r�r�r-r-r.r�^s
�
z
Port.doAccept)r�rjN)!rerfrgr`rIrar%r�rpr�rqrZIPv4Addressr�r�r�r�r$r�r�rrArZCONNECTION_DONErbZ
stopListeningr�rCrLr�r�r�r�r-r-r-r.r��s*

  	1r�)?rhr%rMryr{Zzope.interfacerrZtwisted.internetrrrrrZtwisted.internet.protocolr	Ztwisted.internet.abstractr
rZtwisted.internet.tcprr
ZTCPConnectorrrrrrZtwisted.pythonrrrZtwisted.python.compatrrZtwisted.internet.iocpreactorrr7rZ'twisted.internet.iocpreactor.interfacesrZ"twisted.internet.iocpreactor.constrrrrrZtwisted.internet._newtlsr r[�ImportErrorZWSAECONNREFUSEDZWSAENETUNREACHrwZ
ITCPTransportZ
ISystemHandler#r!Z
ITLSTransportrir�ZIListeningPortr�r-r-r-r.�<module>sH $
��G
\=