Edit File: asyncore_25.cpython-36.pyc
3 �k�`�A � @ sB d Z ddlZddlZddlZddlZddlZddlmZmZm Z m Z mZmZm Z mZmZ ddlmZmZ ye W n ek r� i ZY nX G dd� de�Zdd� Zd d � Zdd� Zd d� Zd%dd�Zd&dd�ZeZd'dd�ZG dd� d�ZG dd� de�Z dd� Z!d(dd�Z"ej#d k�r>ddl$Z$G d!d"� d"�Z%G d#d$� d$e�Z&dS ))a� Basic infrastructure for asynchronous socket service clients and servers. There are only two ways to have a program on a single processor do "more than one thing at a time". Multi-threaded programming is the simplest and most popular way to do it, but there is another very different technique, that lets you have nearly all the advantages of multi-threading, without actually using multiple threads. it's really only practical if your program is largely I/O bound. If your program is CPU bound, then preemptive scheduled threads are probably what you really need. Network servers are rarely CPU-bound, however. If your operating system supports the select() system call in its I/O library (and nearly all do), then you can use it to juggle multiple communication channels at once; doing other work while your I/O is taking place in the "background." Although this strategy can seem strange and complex, especially at first, it is in many ways easier to understand and control than multi-threaded programming. The module documented here solves many of the difficult problems for you, making the task of building sophisticated high-performance network servers and clients a snap. � N) �EALREADY�EINPROGRESS�EWOULDBLOCK� ECONNRESET�ENOTCONN� ESHUTDOWN�EINTR�EISCONN� errorcode)� as_string�as_bytesc @ s e Zd ZdS )�ExitNowN)�__name__� __module__�__qualname__� r r �!/usr/lib/python3.6/asyncore_25.pyr A s r c C s: y| j � W n( tk r" � Y n | j� Y nX d S )N)�handle_read_eventr �handle_error)�objr r r �readD s r c C s: y| j � W n( tk r" � Y n | j� Y nX d S )N)�handle_write_eventr r )r r r r �writeL s r c C s: y| j � W n( tk r" � Y n | j� Y nX d S )N)�handle_expt_eventr r )r r r r � _exceptionT s r c C sz yL|t jt jB @ r| j� |t j@ r,| j� |t jt jB t jB @ rJ| j � W n( t k rb � Y n | j� Y nX d S )N)�select�POLLIN�POLLPRIr �POLLOUTr �POLLERR�POLLHUP�POLLNVALr r r )r �flagsr r r � readwrite\ s r# � c C s� |d krt }|�r�g }g }g }xR|j� D ]F\}}|j� }|j� }|rN|j|� |r\|j|� |sd|r(|j|� q(W g | ko�| ko�|kn r�tj| � nVytj|||| �\}}}W n: tjk r� } z| j d t kr� nd S W Y d d } ~ X nX x*|D ]"}|j|�}|d k�rq�t|� q�W x.|D ]&}|j|�}|d k�rD�q(t |� �q(W x.|D ]&}|j|�}|d k�rt�qXt|� �qXW d S )Nr )� socket_map�items�readable�writable�append�timeZsleepr �error�argsr �getr r r ) �timeout�map�r�w�e�fdr Zis_rZis_w�errr r r �polli sL " r5 c C s |d krt }| d k r t| d �} tj� }|�rxh|j� D ]\\}}d}|j� r\|tjtjB O }|j� rn|tj O }|r8|tj tjB tjB O }|j ||� q8W y|j| �}W n8 tjk r� } z|jd tkrʂ g }W Y d d }~X nX x0|D ](\}}|j|�}|d k�rq�t||� q�W d S )Ni� r )r% �intr r5 r&