Changeset 7851 in orxonox.OLD for branches/network/src/lib/network/network_stream.cc
- Timestamp:
- May 25, 2006, 1:27:00 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_stream.cc
r7809 r7851 30 30 #include "shared_network_data.h" 31 31 #include "message_manager.h" 32 #include "preferences.h" 33 #include "zip.h" 34 35 #include "src/lib/util/loading/resource_manager.h" 32 36 33 37 #include "network_log.h" … … 88 92 myHostId = 0; 89 93 currentState = 0; 94 95 remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 ); 96 97 assert( Zip::getInstance()->loadDictionary( "testdict" ) ); 90 98 } 91 99 … … 365 373 void NetworkStream::handleUpstream( ) 366 374 { 367 byte buf[UDP_PACKET_SIZE];368 375 int offset; 369 376 int n; … … 430 437 assert( Converter::intToByteArray( offset, buf, INTSIZE ) == INTSIZE ); 431 438 432 assert( peer->second.socket->writePacket( buf, offset ) ); 439 int compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE ); 440 441 if ( compLength < 0 ) 442 { 443 PRINTF(1)("compression failed!\n"); 444 continue; 445 } 446 447 assert( peer->second.socket->writePacket( compBuf, compLength ) ); 448 449 if ( this->remainingBytesToWriteToDict > 0 ) 450 writeToNewDict( buf, offset ); 433 451 434 452 peer->second.connectionMonitor->processUnzippedOutgoingPacket( buf, offset, currentState ); 453 peer->second.connectionMonitor->processZippedOutgoingPacket( compBuf, compLength, currentState ); 435 454 436 455 NETPRINTF(n)("send packet: %d userId = %d\n", offset, peer->second.userId); … … 443 462 void NetworkStream::handleDownstream( ) 444 463 { 445 byte buf[UDP_PACKET_SIZE];446 464 int offset = 0; 447 465 448 466 int length = 0; 449 467 int packetLength = 0; 468 int compLength = 0; 450 469 int uniqueId = 0; 451 470 int state = 0; … … 460 479 continue; 461 480 462 while ( 0 < (packetLength = peer->second.socket->readPacket( buf, UDP_PACKET_SIZE )) ) 463 { 481 while ( 0 < (compLength = peer->second.socket->readPacket( compBuf, UDP_PACKET_SIZE )) ) 482 { 483 packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE ); 484 464 485 if ( packetLength < 4*INTSIZE ) 465 486 { … … 468 489 continue; 469 490 } 491 492 if ( this->remainingBytesToWriteToDict > 0 ) 493 writeToNewDict( buf, packetLength ); 470 494 471 495 assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE ); … … 586 610 } 587 611 612 peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, currentState, ackedState ); 588 613 peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, currentState, ackedState ); 589 614 … … 629 654 } 630 655 631 632 633 634 635 656 /** 657 * writes data to DATA/dicts/newdict 658 * @param data pointer to data 659 * @param length length 660 */ 661 void NetworkStream::writeToNewDict( byte * data, int length ) 662 { 663 if ( remainingBytesToWriteToDict <= 0 ) 664 return; 665 666 if ( length > remainingBytesToWriteToDict ) 667 length = remainingBytesToWriteToDict; 668 669 std::string fileName = ResourceManager::getInstance()->getDataDir(); 670 fileName += "/dicts/newdict"; 671 672 FILE * f = fopen( fileName.c_str(), "a" ); 673 674 if ( !f ) 675 { 676 PRINTF(2)("could not open %s\n", fileName.c_str()); 677 remainingBytesToWriteToDict = 0; 678 return; 679 } 680 681 if ( fwrite( data, 1, length, f ) != length ) 682 { 683 PRINTF(2)("could not write to file\n"); 684 fclose( f ); 685 return; 686 } 687 688 fclose( f ); 689 690 remainingBytesToWriteToDict -= length; 691 } 692 693 694 695 696 697
Note: See TracChangeset
for help on using the changeset viewer.