+
    BiO                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	H
t
HtHtHtHtHtHtHtHtHtHt ]! ]]]]]]04      t ] R t ! R R]4      t]]]3tR tR t R t!R	 t"RR
 lt#RR lt$]$t%RR lt& ! R R4      t' ! R R]'4      t(R t)RR lt*]PV                  R8X  d    ! R R4      t, ! R R]'4      t-R# R#   ] d    / t Li ; i)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 pre-emptive
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EINVALENOTCONN	ESHUTDOWNEISCONNEBADFECONNABORTEDEPIPEEAGAIN	errorcodec                      \         P                  ! V 4      #   \        \        \        3 d'    T \
        9   d   \
        T ,          u # R T ,          u # i ; i)zUnknown error %s)osstrerror
ValueErrorOverflowError	NameErrorr   )errs   &,/usr/lib/python3.14/test/support/asyncore.py	_strerrorr   J   sI    '{{3y1 ')S>!!3&&'s    .A	AAc                       ] tR t^RtRtR# )ExitNow N)__name__
__module____qualname____firstlineno____static_attributes__r       r   r   r   R   s    r    r   c                 n     V P                  4        R #   \         d    h  T P                  4         R # ; iN)handle_read_event_reraised_exceptionshandle_errorobjs   &r   readr(   W   1         4c                 n     V P                  4        R #   \         d    h  T P                  4         R # ; ir"   )handle_write_eventr$   r%   r&   s   &r   writer-   _   s1      r*   c                 n     V P                  4        R #   \         d    h  T P                  4         R # ; ir"   )handle_expt_eventr$   r%   r&   s   &r   
_exceptionr0   g   r)   r*   c                     V\         P                  ,          '       d   V P                  4        V\         P                  ,          '       d   V P	                  4        V\         P
                  ,          '       d   V P                  4        V\         P                  \         P                  ,          \         P                  ,          ,          '       d   V P                  4        R # R #   \         dG   pTP                  \        9  d   T P                  4         R p?R # T P                  4         R p?R # R p?i\         d    h  T P                  4         R # ; ir"   )selectPOLLINr#   POLLOUTr,   POLLPRIr/   POLLHUPPOLLERRPOLLNVALhandle_closeOSErrorerrno_DISCONNECTEDr%   r$   )r'   flagses   && r   	readwriter?   o   s    6==  !!#6>>!!""$6>>!!!!#FNNV^^3fooEFF G 77-' s;   C$ ,C$ ,C$ 9AC$ C$ $E/%D0D00E=Ec                 (   Vf   \         pV'       Ed   . p. p. p\        VP                  4       4       F  w  rVVP                  4       pVP	                  4       pV'       d   VP                  V4       V'       d$   VP                  '       g   VP                  V4       V'       g   V'       g   K{  VP                  V4       K  	  . Tu;8X  d   Tu;8X  d   V8X  d   M M\        P                  ! V 4       R # \        P                  ! W#W@4      w  r#pV F%  pVP                  V4      pVf   K  \        V4       K'  	  V F%  pVP                  V4      pVf   K  \        V4       K'  	  V F%  pVP                  V4      pVf   K  \        V4       K'  	  R # R # r"   )
socket_maplistitemsreadablewritableappend	acceptingtimesleepr2   getr(   r-   r0   )	timeoutmaprwr>   fdr'   is_ris_ws	   &&       r   pollrR      s3   
{
sBBCIIK(GB<<>D<<>DCMMMtt ) a1JJw--a1aB''"+C{I	  B''"+C{#J	  B''"+C{sO	 = r    c                    Vf   \         pV e   \        V R,          4      p \        P                  ! 4       pV'       Ed   \	        VP                  4       4       F  w  r4^ pVP                  4       '       d-   V\        P                  \        P                  ,          ,          pVP                  4       '       d*   VP                  '       g   V\        P                  ,          pV'       g   K  VP                  W54       K  	  VP                  V 4      pV F'  w  r5VP                  V4      pVf   K  \        WE4       K)  	  R # R # )Ni  )rA   intr2   rR   rB   rC   rD   r3   r5   rE   rG   r4   registerrJ   r?   )rK   rL   pollsterrO   r'   r=   rM   s   &&     r   poll2rW      s    
{gdl#{{}H
sCIIK(GBE||~~77||~~cmmm'u!!", ) MM'"IB''"+C{c!	  r    c                     Vf   \         pV'       d   \        \        R4      '       d   \        pM\        pVf   V'       d   V! W4       K  R # V'       d   V^ 8  d   V! W4       V^,
          pK"  R # R # )NrR   )rA   hasattrr2   rW   rR   )rK   use_pollrL   countpoll_funs   &&&& r   loopr]      s]    
{GFF++}W"  eaiW"AIE  cr    c                   B  a  ] tR t^t o RtRtRtRtRtRt	]
! R04      tR#R ltR tR$R ltR$R lt]P"                  ]P$                  3R ltR$R	 ltR
 tR tR tR tR tR tR tR tR tR tR tR%R lt R t!R t"R t#R t$R t%R t&R t'R t(R t)R t*R  t+R! t,R"t-V t.R# )&
dispatcherFNwarningc                z   Vf   \         V n        MW n        R V n        V'       dB   VP                  R4       V P	                  W4       RV n         VP                  4       V n        R # R V n        R #   \         d@   pTP                  \        \        39   d   RT n         R p?R # T P                  T4       h R p?ii ; i)NFT)rA   _map_filenosetblocking
set_socket	connectedgetpeernameaddrr:   r;   r   r   del_channelsocket)selfsockrL   r   s   &&& r   __init__dispatcher.__init__   s    ;"DII U#OOD&!DN ,,.	 DK  
996 22 &+DNN
 $$S)
s   A0 0B:;"B5#B55B:c                8   V P                   P                  R ,           V P                   P                  ,           .pV P                  '       d%   V P                  '       d   VP                  R4       M#V P                  '       d   VP                  R4       V P                  e$    VP                  RV P                  ,          4       RRP                  V4      \        V 4      3,          #   \         d(    TP                  \        T P                  4      4        LTi ; i).	listeningrf   z%s:%dz<%s at %#x> )	__class__r   r   rG   rh   rF   rf   	TypeErrorreprjoinid)rk   statuss   & r   __repr__dispatcher.__repr__  s    ..++C/0K0KKL>>>diiiMM+&^^^MM+&99 /g		12  0"T(;;;  /d499o./s   ""C' '/DDc                B    Vf   V P                   pWV P                  &   R # r"   )rb   rc   )rk   rL   s   &&r   add_channeldispatcher.add_channel  s    ;))C DLLr    c                \    V P                   pVf   V P                  pW!9   d   W R V n         R # r"   )rc   rb   )rk   rL   rO   s   && r   ri   dispatcher.del_channel  s*    \\;))C9r    c                    W3V n         \        P                  ! W4      pVP                  R 4       V P                  V4       R# FN)family_and_typerj   rd   re   )rk   familytyperl   s   &&& r   create_socketdispatcher.create_socket  s4    %|}}V*r    c                ^    Wn         VP                  4       V n        V P                  V4       R # r"   )rj   filenorc   r|   rk   rl   rL   s   &&&r   re   dispatcher.set_socket$  s"    {{}r    c                    V P                   P                  \         P                  \         P                  V P                   P	                  \         P                  \         P                  4      ^,          4       R#   \
         d     R# i ; i)   N)rj   
setsockopt
SOL_SOCKETSO_REUSEADDR
getsockoptr:   rk   s   &r   set_reuse_addrdispatcher.set_reuse_addr)  sj    	KK""!!6#6#6&&v'8'8'-':':<>?@
  		s   A6A: :B	B	c                    R # Tr   r   s   &r   rD   dispatcher.readable:      r    c                    R # r   r   r   s   &r   rE   dispatcher.writable=  r   r    c                    R V n         \        P                  R8X  d
   V^8  d   ^pV P                  P	                  V4      # )Tnt)rG   r   namerj   listen)rk   nums   &&r   r   dispatcher.listenD  s4    77d?sQwC{{!!#&&r    c                D    Wn         V P                  P                  V4      # r"   )rh   rj   bind)rk   rh   s   &&r   r   dispatcher.bindJ  s    	{{%%r    c                H   R V n         RV n        V P                  P                  V4      pV\        \
        \        39   g!   V\        8X  d   \        P                  R8X  d	   Wn
        R# V^ \        39   d   Wn
        V P                  4        R# \        V\        V,          4      h)FTr   N)rf   
connectingrj   
connect_exr   r   r   r   r   r   rh   r	   handle_connect_eventr:   r   )rk   addressr   s   && r   connectdispatcher.connectN  sz    kk$$W-;+66&=RWW_I1g,I%%'#y~..r    c                     V P                   P                  4       w  rW3#   \         d     R # \         d-   pTP                  \
        \        \        39   d    R p?R # h R p?ii ; ir"   )rj   acceptrt   r:   r;   r   r   r   )rk   connrh   whys   &   r   r   dispatcher.accept\  s[    
	++-JD :  	 	yy[,??		s$   ! A%A%A% A A  A%c                     V P                   P                  V4      pV#   \         dM   pTP                  \        8X  d    R p?^ # TP                  \
        9   d   T P                  4         R p?^ # h R p?ii ; ir"   )rj   sendr:   r;   r   r<   r9   )rk   dataresultr   s   &&  r   r   dispatcher.sendj  s]    
	[[%%d+FM 	yyK'm+!!#	s     A6A1%A10A11A6c                     V P                   P                  V4      pV'       g   V P                  4        R # V#   \         d2   pTP                  \
        9   d   T P                  4         Rp?R # h Rp?ii ; ir    N)rj   recvr9   r:   r;   r<   )rk   buffer_sizer   r   s   &&  r   r   dispatcher.recvw  sb    	;;##K0D !!# 	yyM)!!#	s#   "9 9 9 A5%A0/A00A5c                   R V n         R V n        R V n        V P                  4        V P                  e    V P                  P                  4        R# R#   \         d(   pTP                  \        \        39  d   h  Rp?R# Rp?ii ; ir   )
rf   rG   r   ri   rj   closer:   r;   r   r
   )rk   r   s   & r   r   dispatcher.close  sr    ;;"!!# #  99Xu$55 6s   A BB  Bc                d    \         P                  P                  R \        V4      ,          4       R# )zlog: %s
N)sysstderrr-   str)rk   messages   &&r   logdispatcher.log  s    

s7|34r    c                N    W P                   9  d   \        V: R V: 24       R# R# )z: N)ignore_log_typesprint)rk   r   r   s   &&&r   log_infodispatcher.log_info  s     ,,,dG,- -r    c                    V P                   '       d   V P                  4        R # V P                  '       g5   V P                  '       d   V P	                  4        V P                  4        R # V P                  4        R # r"   )rG   handle_acceptrf   r   r   handle_readr   s   &r   r#   dispatcher.handle_read_event  sO    >>>  ))+r    c                    V P                   P                  \         P                  \         P                  4      pV^ 8w  d   \	        V\        V4      4      hV P                  4        RV n        RV n        R# )    TFN)	rj   r   r   SO_ERRORr:   r   handle_connectrf   r   rk   r   s   & r   r   dispatcher.handle_connect_event  sT    kk$$V%6%6H!8#y~..r    c                    V P                   '       d   R # V P                  '       g#   V P                  '       d   V P                  4        V P	                  4        R # r"   )rG   rf   r   r   handle_writer   s   &r   r,   dispatcher.handle_write_event  s:    >>> ~~~))+r    c                    V P                   P                  \         P                  \         P                  4      pV^ 8w  d   V P	                  4        R# V P                  4        R# )r   N)rj   r   r   r   r9   handle_exptr   s   & r   r/   dispatcher.handle_expt_event  sE     kk$$V%6%6H!8 r    c                    \        4       w  rr4 \        V 4      pT P                  RT: RT: RT: RT: R2	R4       T P	                  4        R#    R \        T 4      ,          p LK; i)z)<__repr__(self) failed for object at %0x>z-uncaptured python exception, closing channel z (:rr   )errorN)compact_tracebackru   rw   r   r9   )rk   niltvtbinfo	self_reprs   &     r   r%   dispatcher.handle_error  sf    -/	OT
I 		 	 		OCbhNIs   A A%c                *    V P                  R R4       R# )z!unhandled incoming priority eventr`   Nr   r   s   &r   r   dispatcher.handle_expt  s    99Er    c                *    V P                  R R4       R# )zunhandled read eventr`   Nr   r   s   &r   r   dispatcher.handle_read  s    ,i8r    c                *    V P                  R R4       R# )zunhandled write eventr`   Nr   r   s   &r   r   dispatcher.handle_write  s    -y9r    c                *    V P                  R R4       R# )zunhandled connect eventr`   Nr   r   s   &r   r   dispatcher.handle_connect  s    /;r    c                R    V P                  4       pVe   V P                  ! V!   R # R # r"   )r   handle_accepted)rk   pairs   & r   r   dispatcher.handle_accept  s&    {{}  $' r    c                J    VP                  4        V P                  R R4       R# )zunhandled accepted eventr`   N)r   r   )rk   rl   rh   s   &&&r   r   dispatcher.handle_accepted  s    

0)<r    c                J    V P                  R R4       V P                  4        R# )zunhandled close eventr`   N)r   r   r   s   &r   r9   dispatcher.handle_close  s    -y9

r    )rc   rb   rG   rh   rf   r   r   rj   NNr"   )info)/r   r   r   r   debugrf   rG   r   closingrh   	frozensetr   rm   ry   r|   ri   rj   AF_INETSOCK_STREAMr   re   r   rD   rE   r   r   r   r   r   r   r   r   r   r#   r   r,   r/   r%   r   r   r   r   r   r   r9   r   __classdictcell____classdict__s   @r   r_   r_      s     EIIJGD )-@<! $*>>8J8J 
	"'&/$
 5.
 	(F9:<(
= r    r_   c                   B   a  ] tR tRt o R	R ltR tR tR tR tRt	V t
R# )
dispatcher_with_sendi   Nc                @    \         P                  WV4       R V n        R# r   )r_   rm   
out_bufferr   s   &&&r   rm   dispatcher_with_send.__init__  s    D,r    c                ~    ^ p\         P                  W P                  R,          4      pV P                  VR V n        R# )r   :Ni   NN)r_   r   r  )rk   num_sents   & r   initiate_send"dispatcher_with_send.initiate_send  s0    ??4)@A//()4r    c                &    V P                  4        R # r"   )r  r   s   &r   r   !dispatcher_with_send.handle_write  s    r    c                ^    V P                   '       * ;'       g    \        V P                  4      # r"   )rf   lenr  r   s   &r   rE   dispatcher_with_send.writable  s     NN";;s4??';;r    c                    V P                   '       d"   V P                  R \        V4      ,          4       V P                  V,           V n        V P	                  4        R# )z
sending %sN)r   r   ru   r  r  )rk   r   s   &&r   r   dispatcher_with_send.send  s<    :::MM,d34//D0r    )r  r   )r   r   r   r   rm   r  r   rE   r   r   r   r   s   @r   r   r      s#     5
< r    r   c                     \         P                  ! 4       p V P                  pV'       g   \        R 4      h. pV'       dr   VP	                  VP
                  P                  P                  VP
                  P                  P                  \        VP                  4      34       VP                  pKy  ?VR,          w  r4pRP                  V Uu. uF  pRV,          NK  	  up4      pW4V3\        V 4      W3# u upi )ztraceback does not existrr   z
[%s|%s|%s])r   	exception__traceback__AssertionErrorrF   tb_framef_codeco_filenameco_namer   	tb_linenotb_nextrv   r   )exctbr   filefunctionlinexr   s           r   r   r     s    
--/C			B788F
KK**KK&& 	
 ZZ 	!":DD88v6v!\A%%v67DD!49c77 7s   C5c                 D   V f   \         p \        V P                  4       4       F  p VP                  4        K  	  V P                  4        R #   \         d0   pTP
                  \        8X  d    R p?KP  T'       g   h  R p?K_  R p?i\         d    h  T'       g   h  K{  ; ir"   )	rA   rB   valuesr   r:   r;   r
   r$   clear)rL   
ignore_allr  s   && r   	close_allr#  0  s|    
{#**,	GGI   IIK  	ww%  # 		 s/   ABB4B<BB
BBposixc                   V   a  ] tR tRt o R tR tR tR tRR lt]t	]t
R tR	 tR
tV tR# )file_wrapperiP  c                <    \         P                  ! V4      V n        R # r"   )r   duprO   rk   rO   s   &&r   rm   file_wrapper.__init__U  s    ffRjDGr    c                    V P                   ^ 8  d%   \        P                  ! RV ,          \        V R7       V P	                  4        R# )r   zunclosed file %r)sourceN)rO   warningswarnResourceWarningr   r   s   &r   __del__file_wrapper.__del__X  s/    ww!|047%)+JJLr    c                F    \         P                  ! V P                  .VO5!  # r"   )r   r(   rO   rk   argss   &*r   r   file_wrapper.recv^  s    77477*T**r    c                F    \         P                  ! V P                  .VO5!  # r"   )r   r-   rO   r3  s   &*r   r   file_wrapper.senda  s    88DGG+d++r    Nc                    V\         P                  8X  d    V\         P                  8X  d   V'       g   ^ # \        R4      h)r   z-Only asyncore specific behaviour implemented.)rj   r   r   NotImplementedError)rk   leveloptnamebuflens   &&&&r   r   file_wrapper.getsockoptd  s4    ***6??*% '5 6 6r    c                ~    V P                   ^ 8  d   R# V P                   pRV n         \        P                  ! V4       R# )r   Nr  )rO   r   r   r)  s   & r   r   file_wrapper.closeo  s+    ww{BDGHHRLr    c                    V P                   # r"   rO   r   s   &r   r   file_wrapper.filenov  s    77Nr    rA  r"   )r   r   r   r   rm   r0  r   r   r   r(   r-   r   r   r   r   r   s   @r   r&  r&  P  s9     
	!		+	,	6 		 	r    r&  c                   0   a  ] tR tRt o RR ltR tRtV tR# )file_dispatcheriy  Nc                    \         P                  V R V4       RV n         VP                  4       pV P                  V4       \        P                  ! VR4       R #   \         d     L7i ; i)NTF)r_   rm   rf   r   AttributeErrorset_filer   set_blocking)rk   rO   rL   s   &&&r   rm   file_dispatcher.__init__{  s[    dC0!DNYY[ MM"OOB&	 " s   A A('A(c                    \        V4      V n        V P                  P                  4       V n        V P	                  4        R # r"   )r&  rj   r   rc   r|   r)  s   &&r   rG  file_dispatcher.set_file  s.    &r*DK;;--/DLr    )rc   rf   rj   r"   )r   r   r   r   rm   rG  r   r   r   s   @r   rD  rD  y  s     		'	 	r    rD  )g        N)g      >@FNN)NF).__doc__r2   rj   r   rH   r-  r   r;   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r<   rA   r   r   	Exceptionr   KeyboardInterrupt
SystemExitr$   r(   r-   r0   r?   rR   rW   poll3r]   r_   r   r   r#  r   r&  rD  r   r    r   <module>rQ     s
  B*   
   	   
 :xL% " #'	i 	  !2J? (%N"4 	$a aP	: 68*> 77g' 'R* U Q  Js   C 	CC