Exemple #1
0
 def next_event(self, t):
     while True:
         ev = self.iom.next_event(None)
         # non read channels are simple.
         if not isinstance(ev, ioman_base.event_read):
             return ev
         # an event from a read channel.
         # we may receive a part of a message, in which case
         # we should not return
         ch = ev.ch
         buf = ch.buf
         if ev.data is not None:
             buf.write(ev.data)
         # an I/O error or EOF. we return anyway
         if ev.eof:
             data_to_return = buf.getvalue()
             return ioman_base.event_read(ch, data_to_return, 1, ev.err)
         elif ev.ch.flag == conf.SOCKET_OUT:
             # the first 10 bytes is the length of the mssage
             if ch.length == 0:
                 ch.length = string.atoi(ev.data[0:10])
             if len(buf.getvalue()) >= ch.length + 10:
                 all_data = buf.getvalue()
                 data_to_return = all_data[0 : ch.length + 10]
                 buf.truncate(0)
                 buf.write(all_data[ch.length + 10 :])
                 ch.length = 0
                 return ioman_base.event_read(ch, data_to_return, 0, ev.err)
Exemple #2
0
 def next_event(self, t):
     buf = cStringIO.StringIO()
     """
     If multiple clients send data to the same address, we cannot assure the order
     of data. So we have to distinct each client here. ch_list is used to keep the
     order of channel. Here a event is returned only when ev.eof == 1 (which means
     a clint has to be closed after it issues data) and this channel is the first one.
     """
     while True:
         ev = self.iom.next_event(None)
         # non read channels are simple.
         if not isinstance(ev, ioman_base.event_read):
             return ev
         # an event from a read channel.
         # we may receive a part of a message, in which case
         # we should not return
         ch = ev.ch
         buf = ch.buf
         if ev.data is not None:
             buf.write(ev.data)
         # an I/O error or EOF. we return anyway
         if ev.eof:
             return ioman_base.event_read(ch, ch.buf.getvalue(), 1, ev.err)