Commits

Ginés Martínez Sánchez committed 42123e6 Draft

convert write_soon() and send_some () to events

  • Participants
  • Parent commits 0f517b3

Comments (0)

Files changed (2)

File ginsfsm/protocols/http/common/response.py

     def __init__(self, request):
         self.request = request
         self.gsock = request.channel.gsock
+        self.channel = request.channel
         self.response_headers = []
         version = request.version
         if version not in ('1.0', '1.1'):
             self.write(b'')
         if self.chunked_response:
             # not self.write, it will chunk it!
-            self.gsock.write_soon(b'0\r\n\r\n')
-        self.gsock.send_some()
+            self.channel.send_event(
+                self.gsock,
+                'EV_WRITE_OUTPUT_DATA',
+                b'0\r\n\r\n'
+            )
+        self.channel.send_event(self.gsock, 'EV_FLUSH_OUTPUT_DATA')
 
     def write(self, data):
         if not self.complete:
         gsock = self.gsock
         if not self.wrote_header:
             rh = self.build_response_header()
-            gsock.write_soon(rh)
+            self.channel.send_event(gsock, 'EV_WRITE_OUTPUT_DATA', data=rh)
             self.wrote_header = True
         if data:
             towrite = data
                         'bytes specified by Content-Length header (%s)' % cl)
                     self.logged_write_excess = True
             if towrite:
-                gsock.write_soon(towrite)
+                self.channel.send_event(
+                    gsock,
+                    'EV_WRITE_OUTPUT_DATA',
+                    data=towrite)
 
 
 class HttpErrorResponse(HttpResponse):

File ginsfsm/protocols/http/server/c_http_clisrv.py

             new_request.expect_continue = False
 
             if not self.sent_continue:
-                # there's no current task, so we don't need to try to
-                # lock the outbuf to append to it.
-                # TODO: BAD! using gsock without events!!
-                gsock.outbufs[-1].append(b'HTTP/1.1 100 Continue\r\n\r\n')
+                self.send_event(gsock, b'HTTP/1.1 100 Continue\r\n\r\n')
                 self.sent_continue = True
-                gsock.send_some()
                 new_request.completed = False
 
         if new_request.completed:
         'EV_DEQUEUE_REQUEST',
         'EV_TRANSMIT_READY: bottom input',
         'EV_SEND_DATA: bottom output',
+        'EV_FLUSH_OUTPUT_DATA: bottom output',
+        'EV_WRITE_OUTPUT_DATA: bottom output',
         'EV_HTTP_CHANNEL_OPENED: top output',
         'EV_HTTP_CHANNEL_CLOSED: top output',
         'EV_HTTP_REQUEST: top output',
         )
 
     def enqueue_request(self, new_request):
-        # TODO: check limit queue size
         self.dl_requests.append(new_request)
         if self.maximum_simultaneous_requests > 0 and \
                 len(self.dl_requests) > self.maximum_simultaneous_requests: