@@ -117,7 +117,6 @@ cdef class Loop:
117
117
self ._poll_write_events_total = 0
118
118
self ._poll_write_cb_errors_total = 0
119
119
120
- self ._sock_try_read_total = 0
121
120
self ._sock_try_write_total = 0
122
121
123
122
self ._debug_exception_handler_cnt = 0
@@ -548,49 +547,43 @@ cdef class Loop:
548
547
nr.query(addr, flags)
549
548
return fut
550
549
551
- cdef _sock_recv(self , fut, int registered, sock, n):
552
- # _sock_recv() can add itself as an I/O callback if the operation can't
553
- # be done immediately. Don't use it directly, call sock_recv().
550
+ cdef _sock_recv(self , fut, sock, n):
554
551
cdef:
555
552
Handle handle
553
+ int fd
556
554
557
555
fd = sock.fileno()
558
556
if fut.cancelled():
559
- if registered:
560
- self ._remove_reader(fd)
557
+ self ._remove_reader(fd)
561
558
return
559
+
562
560
try :
563
561
data = sock.recv(n)
564
562
except (BlockingIOError, InterruptedError):
565
- handle = new_MethodHandle4 (
563
+ handle = new_MethodHandle3 (
566
564
self ,
567
565
" Loop._sock_recv" ,
568
- < method4_t * > & self ._sock_recv,
566
+ < method3_t * > & self ._sock_recv,
569
567
self ,
570
- fut, 1 , sock, n)
571
-
568
+ fut, sock, n)
572
569
self ._add_reader(fd, handle)
573
570
except Exception as exc:
574
571
fut.set_exception(exc)
575
- if registered:
576
- self ._remove_reader(fd)
572
+ self ._remove_reader(fd)
577
573
else :
578
- IF DEBUG:
579
- if not registered:
580
- self ._sock_try_read_total += 1
581
574
fut.set_result(data)
582
- if registered:
583
- self ._remove_reader(fd)
575
+ self ._remove_reader(fd)
584
576
585
- cdef _sock_sendall(self , fut, int registered, sock, data):
577
+ cdef _sock_sendall(self , fut, sock, data):
586
578
cdef:
587
579
Handle handle
580
+ int n
581
+ int fd
588
582
589
583
fd = sock.fileno()
590
584
591
585
if fut.cancelled():
592
- if registered:
593
- self ._remove_writer(fd)
586
+ self ._remove_writer(fd)
594
587
return
595
588
596
589
try :
@@ -599,60 +592,50 @@ cdef class Loop:
599
592
n = 0
600
593
except Exception as exc:
601
594
fut.set_exception(exc)
602
- if registered:
603
- self ._remove_writer(fd)
595
+ self ._remove_writer(fd)
604
596
return
605
- else :
606
- IF DEBUG:
607
- if not registered:
608
- # This can be a partial success, i.e. only part
609
- # of the data was sent
610
- self ._sock_try_write_total += 1
611
597
612
598
if n == len (data):
613
599
fut.set_result(None )
614
- if registered:
615
- self ._remove_writer(fd)
600
+ self ._remove_writer(fd)
616
601
else :
617
602
if n:
618
603
if not isinstance (data, memoryview):
619
604
data = memoryview(data)
620
605
data = data[n:]
621
606
622
- handle = new_MethodHandle4 (
607
+ handle = new_MethodHandle3 (
623
608
self ,
624
609
" Loop._sock_sendall" ,
625
- < method4_t * > & self ._sock_sendall,
610
+ < method3_t * > & self ._sock_sendall,
626
611
self ,
627
- fut, 1 , sock, data)
612
+ fut, sock, data)
628
613
629
614
self ._add_writer(fd, handle)
630
615
631
- cdef _sock_accept(self , fut, int registered, sock):
616
+ cdef _sock_accept(self , fut, sock):
632
617
cdef:
633
618
Handle handle
634
619
635
620
fd = sock.fileno()
636
- if registered:
637
- self ._remove_reader(fd)
621
+
638
622
if fut.cancelled():
623
+ self ._remove_reader(fd)
639
624
return
625
+
640
626
try :
641
627
conn, address = sock.accept()
642
628
conn.setblocking(False )
643
629
except (BlockingIOError, InterruptedError):
644
- handle = new_MethodHandle3(
645
- self ,
646
- " Loop._sock_accept" ,
647
- < method3_t* > & self ._sock_accept,
648
- self ,
649
- fut, 1 , sock)
650
-
651
- self ._add_reader(fd, handle)
630
+ # There is an active reader for _sock_accept, so
631
+ # do nothing, it will be called again.
632
+ pass
652
633
except Exception as exc:
653
634
fut.set_exception(exc)
635
+ self ._remove_reader(fd)
654
636
else :
655
637
fut.set_result((conn, address))
638
+ self ._remove_reader(fd)
656
639
657
640
cdef _sock_connect(self , fut, sock, address):
658
641
cdef:
@@ -823,8 +806,6 @@ cdef class Loop:
823
806
print ()
824
807
825
808
print (' --- Sock ops successfull on 1st try: ---' )
826
- print (' Socket try-reads: {}' .format(
827
- self ._sock_try_read_total))
828
809
print (' Socket try-writes: {}' .format(
829
810
self ._sock_try_write_total))
830
811
@@ -1629,10 +1610,23 @@ cdef class Loop:
1629
1610
1630
1611
This method is a coroutine.
1631
1612
"""
1613
+ cdef:
1614
+ Handle handle
1615
+ int fd
1616
+
1632
1617
if self ._debug and sock.gettimeout() != 0 :
1633
1618
raise ValueError (" the socket must be non-blocking" )
1619
+
1634
1620
fut = self ._new_future()
1635
- self ._sock_recv(fut, 0 , sock, n)
1621
+ handle = new_MethodHandle3(
1622
+ self ,
1623
+ " Loop._sock_recv" ,
1624
+ < method3_t* > & self ._sock_recv,
1625
+ self ,
1626
+ fut, sock, n)
1627
+
1628
+ fd = sock.fileno()
1629
+ self ._add_reader(fd, handle)
1636
1630
return fut
1637
1631
1638
1632
async def sock_sendall(self , sock, data):
@@ -1646,6 +1640,11 @@ cdef class Loop:
1646
1640
1647
1641
This method is a coroutine.
1648
1642
"""
1643
+ cdef:
1644
+ Handle handle
1645
+ int n
1646
+ int fd
1647
+
1649
1648
if self ._debug and sock.gettimeout() != 0 :
1650
1649
raise ValueError (" the socket must be non-blocking" )
1651
1650
@@ -1669,7 +1668,15 @@ cdef class Loop:
1669
1668
data = data[n:]
1670
1669
1671
1670
fut = self ._new_future()
1672
- self ._sock_sendall(fut, 0 , sock, data)
1671
+ handle = new_MethodHandle3(
1672
+ self ,
1673
+ " Loop._sock_sendall" ,
1674
+ < method3_t* > & self ._sock_sendall,
1675
+ self ,
1676
+ fut, sock, data)
1677
+
1678
+ fd = sock.fileno()
1679
+ self ._add_writer(fd, handle)
1673
1680
return await fut
1674
1681
1675
1682
def sock_accept (self , sock ):
@@ -1682,10 +1689,23 @@ cdef class Loop:
1682
1689
1683
1690
This method is a coroutine.
1684
1691
"""
1692
+ cdef:
1693
+ Handle handle
1694
+ int fd
1695
+
1685
1696
if self ._debug and sock.gettimeout() != 0 :
1686
1697
raise ValueError (" the socket must be non-blocking" )
1698
+
1687
1699
fut = self ._new_future()
1688
- self ._sock_accept(fut, 0 , sock)
1700
+ handle = new_MethodHandle2(
1701
+ self ,
1702
+ " Loop._sock_accept" ,
1703
+ < method2_t* > & self ._sock_accept,
1704
+ self ,
1705
+ fut, sock)
1706
+
1707
+ fd = sock.fileno()
1708
+ self ._add_reader(fd, handle)
1689
1709
return fut
1690
1710
1691
1711
def sock_connect (self , sock , address ):
0 commit comments