Changeset 5809 in orxonox.OLD for branches/network/src/lib/network/network_stream.cc
- Timestamp:
- Nov 28, 2005, 10:14:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_stream.cc
r5805 r5809 78 78 /* set the class id for the base object */ 79 79 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 80 this->state = NET_REC_HEADER; 80 81 } 81 82 … … 95 96 void NetworkStream::processData() 96 97 { 97 int ret= 0;98 int dataLength = 0; 98 99 99 100 /* DOWNSTREAM */ … … 101 102 PRINT(0)("============= DOWNSTREAM:===============\n"); 102 103 /* first of all read the synchronizeable's data: */ 103 ret= this->synchronizeables->readBytes((byte*)downBuffer);104 dataLength = this->synchronizeables->readBytes((byte*)downBuffer); 104 105 105 106 /* send the received data to connectionMonitor */ 106 this->connectionMonitor->processPacket((byte*)downBuffer, ret);107 this->connectionMonitor->processPacket((byte*)downBuffer, dataLength); 107 108 108 ret = this->networkProtocol->createHeader((byte*)downBuffer, ret, DATA_STREAM_BUFFER_SIZE,109 *(this->synchronizeables), 12);109 dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, 110 *(this->synchronizeables), 12/* some random number (no real id)*/); 110 111 111 112 /* pass the data to the network socket */ 112 ret = this->networkSocket->writeBytes((byte*)downBuffer, ret);113 dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength); 113 114 /* check if there was an error */ 114 if( ret== -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}115 if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");} 115 116 116 117 117 118 118 119 /* UPSTREAM */ 119 ret= 0;120 dataLength = 0; 120 121 PRINT(0)("============== UPSTREAM:================\n"); 121 /* first of all read data from networkSocket*/ 122 ret = this->networkSocket->readBlock((byte*)upBuffer, 11/* this is very bad: hard coded packet sizes! */); 123 /* error checking: data read? */ 124 if( ret != 11 /*PACKAGE_SIZE + sizeof(Header)*/) { PRINTF(0)("Error while reading data from the NetworkSocket. Skipping further work\n");} 125 else 122 /* first of all read the next Orxonox Network Header */ 123 124 switch( this->state) 126 125 { 127 /* send the received data to connectionMonitor */128 this->connectionMonitor->processPacket((byte*)upBuffer, ret);129 126 130 /* extract Header */ 131 Header header = this->networkProtocol->extractHeader((byte*) upBuffer , ret); 127 case NET_REC_HEADER: 128 dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header)); 129 if( dataLength == sizeof(Header)) 130 { 131 this->packetHeader = this->networkProtocol->extractHeader((byte*) upBuffer , dataLength); 132 printf("NetworkStream::processData() - Got Header: Protocol %u, Version: %u, Sender: %u, Receiver: %u, Length: %u\n", 133 this->packetHeader.protocol, this->packetHeader.version, this->packetHeader.senderID, 134 this->packetHeader.receiverID, this->packetHeader.length); 135 /* FIXME: what if it was no this->packetHeader? catch? eg: the protocol identifier, receiver id*/ 132 136 133 /* now pass the data to the sync object */ 134 this->synchronizeables->writeBytes((byte*)upBuffer, header.length); 137 this->state = NET_REC_DATA; 138 } 139 break; 140 141 case NET_REC_DATA: 142 /* now read the data */ 143 dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length); 144 /* check if the data is available and process it if so */ 145 if( dataLength == this->packetHeader.length) 146 { 147 printf("NetworkStream::processData() - Got Data: \n"); 148 /* send the received data to connectionMonitor */ 149 this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length); 150 /* now pass the data to the sync object */ 151 this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length); 152 153 this->state = NET_REC_HEADER; 154 } 155 break; 156 157 default: 158 break; 135 159 } 136 160 161 137 162 }
Note: See TracChangeset
for help on using the changeset viewer.