Changeset 204
- Timestamp:
- Nov 14, 2007, 2:58:23 PM (17 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/ConnectionManager.cc
r196 r204 35 35 36 36 37 ENetPacket *ConnectionManager::getPacket( ){37 ENetPacket *ConnectionManager::getPacket(ENetAddress &address){ 38 38 if(!buffer.isEmpty()) 39 return buffer.pop( );39 return buffer.pop(address); 40 40 else 41 41 return NULL; … … 127 127 break; 128 128 case ENET_EVENT_TYPE_RECEIVE: 129 std::cout << event.packet->data << std::endl;130 129 processData(&event); 131 130 break; … … 143 142 // just add packet to the buffer 144 143 // this can be extended with some preprocessing 145 return buffer.push(event ->packet);144 return buffer.push(event); 146 145 } 147 146 -
code/branches/network/src/network/ConnectionManager.h
r196 r204 45 45 ConnectionManager(); 46 46 ConnectionManager(int port, int address); 47 ENetPacket *getPacket( ); // thread147 ENetPacket *getPacket(ENetAddress &address); // thread1 48 48 // check wheter the packet queue is empty 49 49 bool queueEmpty(); -
code/branches/network/src/network/Makefile
r196 r204 2 2 3 3 # Link command: 4 server: clean PacketBuffer.o ConnectionManager.o dummyserver.o 5 g++ ConnectionManager.o dummyserver.o PacketBuffer.o -o server -lenet -lboost_thread -g4 server: clean PacketBuffer.o ConnectionManager.o dummyserver.o PacketDecoder.o PacketGenerator.o 5 g++ PacketDecoder.o PacketGenerator.o ConnectionManager.o dummyserver.o PacketBuffer.o -o server -lenet -lboost_thread -g 6 6 7 7 dummyserver.o: … … 13 13 PacketBuffer.o: 14 14 g++ -c PacketBuffer.cc -o PacketBuffer.o -g 15 PacketGenerator.o: 16 g++ -c PacketGenerator.cc -o PacketGenerator.o -g 17 PacketDecoder.o: 18 g++ -c PacketDecoder.cc -o PacketDecoder.o -g 19 15 20 16 21 clean: 17 22 rm -rf *.o 18 23 19 client: 20 g++ dummyclient.cc -o client -lenet24 client: PacketGenerator.o 25 g++ dummyclient.cc PacketGenerator.o -o client -lenet -g -
code/branches/network/src/network/PacketBuffer.cc
r196 r204 21 21 22 22 23 bool PacketBuffer::push(ENet Packet *pck){23 bool PacketBuffer::push(ENetEvent *ev){ 24 24 boost::mutex::scoped_lock lock(networkPacketBufferMutex); 25 25 // if(closed) 26 26 // return false; 27 // also works if fifo is null (queue empty)28 // just to be sure last is really the last element29 /*if(last!=NULL)30 while(last->next!=NULL)31 last=last->next;*/32 27 // first element? 33 28 if(first==NULL){ … … 36 31 last->next=NULL; 37 32 // change this!!!!!!! 38 last->packet = pck; 33 last->packet = ev->packet; 34 last->address = ev->peer->address; 39 35 } else { 40 36 //insert a new element at the bottom … … 44 40 last->next=NULL; 45 41 // save the packet to the new element 46 last->packet = pck; 42 last->packet = ev->packet; 43 last->address = ev->peer->address; 47 44 } 48 45 return true; … … 64 61 } 65 62 63 ENetPacket *PacketBuffer::pop(ENetAddress &address){ 64 boost::mutex::scoped_lock lock(networkPacketBufferMutex); 65 if(first!=NULL /*&& !closed*/){ 66 QueueItem *temp = first; 67 // get packet 68 ENetPacket *pck=first->packet; 69 address = first->address; 70 // remove first element 71 first = first->next; 72 delete temp; 73 return pck; 74 } else{ 75 return NULL; 76 } 77 } 78 66 79 bool PacketBuffer::isEmpty(){ 67 80 return (first==NULL); … … 71 84 QueueItem *temp=first; 72 85 while(temp!=NULL){ 73 std::cout << temp->packet->data << std::endl;86 // std::cout << temp->packet->data << std::endl; 74 87 temp=temp->next; 75 88 } -
code/branches/network/src/network/PacketBuffer.h
r196 r204 31 31 struct QueueItem{ 32 32 ENetPacket *packet; 33 ENetAddress address; 33 34 QueueItem *next; 34 35 }; … … 43 44 // pops a packet from the queue 44 45 ENetPacket *pop(); 46 ENetPacket *pop(ENetAddress &address); 45 47 // pushs a packet to the queue 46 bool push(ENet Packet *pck);48 bool push(ENetEvent *ev); 47 49 48 50 private: -
code/branches/network/src/network/dummyclient.cc
r200 r204 6 6 #include <iostream> 7 7 #include <enet/enet.h> 8 #include "network/PacketManager.h" 8 9 9 10 using namespace std; … … 14 15 ENetEvent event; 15 16 ENetPeer *peer; 17 network::PacketGenerator pck; 16 18 17 19 enet_initialize(); … … 44 46 for(int i=0; i<10; i++){ 45 47 // weihnachtsmann bringt packete 46 ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);48 //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE); 47 49 // extend the packet and append the string foo to it 48 50 // send packet to peer on channel id 0 49 enet_peer_send(peer, 1, p acket);51 enet_peer_send(peer, 1, pck.chatMessage("test")); 50 52 // keep the timeout very small for low delay 51 53 if(enet_host_service(client, &event, 1)==0){ -
code/branches/network/src/network/dummyserver.cc
r196 r204 8 8 #include "enet/enet.h" 9 9 #include "network/ConnectionManager.h" 10 #include "network/PacketManager.h" 10 11 11 12 using namespace network; … … 15 16 bool quit=false; 16 17 ENetPacket *packet; 18 ENetEvent event; 17 19 server.createListener(); 20 21 PacketDecoder dec; 22 18 23 while(!quit){ 19 24 if(server.queueEmpty()) 20 25 usleep(100); 21 26 else{ 22 packet=server.getPacket(); 27 ENetAddress addr; 28 packet=server.getPacket(addr); 23 29 if(packet==NULL){ 24 30 // there was some error … … 26 32 quit=true; 27 33 } 28 else 29 std::cout << "We received: " << packet->data << std::endl; 34 else{ 35 //std::cout << "We received: " << packet->data << std::endl; 36 dec.elaborate(packet, 1); 37 } 30 38 } 31 39 }
Note: See TracChangeset
for help on using the changeset viewer.