An internal function used by send/sendp to actually send the packets, implement the send logic... It will take care of iterating through the different packets
(s, # type: SuperSocket
x, # type: _PacketIterable
inter=0, # type: int
loop=0, # type: int
count=None, # type: Optional[int]
verbose=None, # type: Optional[int]
realtime=False, # type: bool
return_packets=False, # type: bool
*args, # type: Any
**kargs # type: Any
)
| 370 | |
| 371 | |
| 372 | def __gen_send(s, # type: SuperSocket |
| 373 | x, # type: _PacketIterable |
| 374 | inter=0, # type: int |
| 375 | loop=0, # type: int |
| 376 | count=None, # type: Optional[int] |
| 377 | verbose=None, # type: Optional[int] |
| 378 | realtime=False, # type: bool |
| 379 | return_packets=False, # type: bool |
| 380 | *args, # type: Any |
| 381 | **kargs # type: Any |
| 382 | ): |
| 383 | # type: (...) -> Optional[PacketList] |
| 384 | """ |
| 385 | An internal function used by send/sendp to actually send the packets, |
| 386 | implement the send logic... |
| 387 | |
| 388 | It will take care of iterating through the different packets |
| 389 | """ |
| 390 | if isinstance(x, str): |
| 391 | x = conf.raw_layer(load=x) |
| 392 | if not isinstance(x, Gen): |
| 393 | x = SetGen(x) |
| 394 | if verbose is None: |
| 395 | verbose = conf.verb |
| 396 | n = 0 |
| 397 | if count is not None: |
| 398 | loop = -count |
| 399 | elif not loop: |
| 400 | loop = -1 |
| 401 | sent_packets = PacketList() if return_packets else None |
| 402 | p = None |
| 403 | try: |
| 404 | while loop: |
| 405 | dt0 = None |
| 406 | for p in x: |
| 407 | if realtime: |
| 408 | ct = time.time() |
| 409 | if dt0: |
| 410 | st = dt0 + float(p.time) - ct |
| 411 | if st > 0: |
| 412 | time.sleep(st) |
| 413 | else: |
| 414 | dt0 = ct - float(p.time) |
| 415 | s.send(p) |
| 416 | if sent_packets is not None: |
| 417 | sent_packets.append(p) |
| 418 | n += 1 |
| 419 | if verbose: |
| 420 | os.write(1, b".") |
| 421 | time.sleep(inter) |
| 422 | if loop < 0: |
| 423 | loop += 1 |
| 424 | except KeyboardInterrupt: |
| 425 | pass |
| 426 | finally: |
| 427 | try: |
| 428 | cast(Packet, x).sent_time = cast(Packet, p).sent_time |
| 429 | except AttributeError: |