================= idMsgChannel::SendNextFragment Sends one fragment of the current message. ================= */
| 413 | ================= |
| 414 | */ |
| 415 | void idMsgChannel::SendNextFragment( idPort &port, const int time ) { |
| 416 | idBitMsg msg; |
| 417 | byte msgBuf[MAX_PACKETLEN]; |
| 418 | int fragLength; |
| 419 | |
| 420 | if ( remoteAddress.type == NA_BAD ) { |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | if ( !unsentFragments ) { |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | // write the packet |
| 429 | msg.Init( msgBuf, sizeof( msgBuf ) ); |
| 430 | msg.WriteShort( id ); |
| 431 | msg.WriteInt( outgoingSequence | FRAGMENT_BIT ); |
| 432 | |
| 433 | fragLength = FRAGMENT_SIZE; |
| 434 | if ( unsentFragmentStart + fragLength > unsentMsg.GetSize() ) { |
| 435 | fragLength = unsentMsg.GetSize() - unsentFragmentStart; |
| 436 | } |
| 437 | |
| 438 | msg.WriteShort( unsentFragmentStart ); |
| 439 | msg.WriteShort( fragLength ); |
| 440 | msg.WriteData( unsentMsg.GetData() + unsentFragmentStart, fragLength ); |
| 441 | |
| 442 | // send the packet |
| 443 | port.SendPacket( remoteAddress, msg.GetData(), msg.GetSize() ); |
| 444 | |
| 445 | // update rate control variables |
| 446 | UpdateOutgoingRate( time, msg.GetSize() ); |
| 447 | |
| 448 | if ( net_channelShowPackets.GetBool() ) { |
| 449 | common->Printf( "%d send %4i : s = %i fragment = %i,%i\n", id, msg.GetSize(), outgoingSequence - 1, unsentFragmentStart, fragLength ); |
| 450 | } |
| 451 | |
| 452 | unsentFragmentStart += fragLength; |
| 453 | |
| 454 | // this exit condition is a little tricky, because a packet |
| 455 | // that is exactly the fragment length still needs to send |
| 456 | // a second packet of zero length so that the other side |
| 457 | // can tell there aren't more to follow |
| 458 | if ( unsentFragmentStart == unsentMsg.GetSize() && fragLength != FRAGMENT_SIZE ) { |
| 459 | outgoingSequence++; |
| 460 | unsentFragments = false; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | =============== |
no test coverage detected