Last change
on this file since 319 was
285,
checked in by nicolasc, 17 years ago
|
cleaned up network, builds with CML
|
File size:
1.1 KB
|
Rev | Line | |
---|
[188] | 1 | #include <string> |
---|
| 2 | #include <iostream> |
---|
| 3 | #include <enet/enet.h> |
---|
| 4 | #include <boost/thread/thread.hpp> |
---|
[285] | 5 | #include "PacketBuffer.h" |
---|
| 6 | #include "PacketBuffer.cc" |
---|
[175] | 7 | |
---|
| 8 | using namespace network; |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | void write(PacketBuffer *test){ |
---|
[188] | 12 | ENetPacket *packet; |
---|
[175] | 13 | if(test->isEmpty()) |
---|
| 14 | std::cout << "empty buffer" << std::endl; |
---|
| 15 | for(int i=0; i<10; i++){ |
---|
[188] | 16 | std::string temp = "packet "; |
---|
[285] | 17 | packet = enet_packet_create("packet", strlen("packet ")+1, |
---|
[188] | 18 | ENET_PACKET_FLAG_RELIABLE); |
---|
| 19 | std::cout << i << ": pushing " << packet->data << std::endl; |
---|
| 20 | test->push(packet); |
---|
[175] | 21 | if(i==5) |
---|
| 22 | usleep(200000); |
---|
| 23 | } |
---|
| 24 | test->setClosed(true); |
---|
| 25 | return; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | void read(PacketBuffer *test){ |
---|
[187] | 29 | //test->print(); |
---|
[175] | 30 | // exit if the queue is closed and empty |
---|
| 31 | while(!test->isClosed() || !test->isEmpty()){ |
---|
| 32 | // only pop if the queue isn't empty |
---|
| 33 | while(!test->isEmpty()){ |
---|
[188] | 34 | std::cout << "We popped the value " << test->pop()->data << std::endl; |
---|
[175] | 35 | } |
---|
| 36 | } |
---|
| 37 | return; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | int main(int argc, char **argv[]){ |
---|
| 42 | PacketBuffer test = PacketBuffer(); |
---|
| 43 | boost::thread thrd1(boost::bind(&write, &test)); |
---|
| 44 | boost::thread thrd2(boost::bind(&read, &test)); |
---|
[285] | 45 | |
---|
[175] | 46 | thrd1.join(); |
---|
| 47 | thrd2.join(); |
---|
[285] | 48 | |
---|
[175] | 49 | return 0; |
---|
| 50 | } |
---|
| 51 | |
---|
Note: See
TracBrowser
for help on using the repository browser.