Last change
on this file since 407 was
367,
checked in by rgrieder, 17 years ago
|
- made certain files windows compatible
- solved conflict with unresolved external symbol registerAllVariables() by commenting call
|
File size:
1.3 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 | |
---|
[367] | 8 | #ifdef WIN32 |
---|
| 9 | #include <windows.h> |
---|
| 10 | #define usleep(x) Sleep((x)/1000) |
---|
| 11 | #else |
---|
| 12 | #include <unistd.h> |
---|
| 13 | #endif |
---|
| 14 | |
---|
[175] | 15 | using namespace network; |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | void write(PacketBuffer *test){ |
---|
[351] | 19 | ENetEvent event; |
---|
[188] | 20 | ENetPacket *packet; |
---|
[175] | 21 | if(test->isEmpty()) |
---|
| 22 | std::cout << "empty buffer" << std::endl; |
---|
| 23 | for(int i=0; i<10; i++){ |
---|
[188] | 24 | std::string temp = "packet "; |
---|
[285] | 25 | packet = enet_packet_create("packet", strlen("packet ")+1, |
---|
[188] | 26 | ENET_PACKET_FLAG_RELIABLE); |
---|
| 27 | std::cout << i << ": pushing " << packet->data << std::endl; |
---|
[351] | 28 | event.packet=packet; |
---|
| 29 | test->push(&event); |
---|
[175] | 30 | if(i==5) |
---|
| 31 | usleep(200000); |
---|
| 32 | } |
---|
| 33 | test->setClosed(true); |
---|
| 34 | return; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void read(PacketBuffer *test){ |
---|
[187] | 38 | //test->print(); |
---|
[175] | 39 | // exit if the queue is closed and empty |
---|
| 40 | while(!test->isClosed() || !test->isEmpty()){ |
---|
| 41 | // only pop if the queue isn't empty |
---|
| 42 | while(!test->isEmpty()){ |
---|
[188] | 43 | std::cout << "We popped the value " << test->pop()->data << std::endl; |
---|
[175] | 44 | } |
---|
| 45 | } |
---|
| 46 | return; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | int main(int argc, char **argv[]){ |
---|
| 51 | PacketBuffer test = PacketBuffer(); |
---|
| 52 | boost::thread thrd1(boost::bind(&write, &test)); |
---|
| 53 | boost::thread thrd2(boost::bind(&read, &test)); |
---|
[285] | 54 | |
---|
[175] | 55 | thrd1.join(); |
---|
| 56 | thrd2.join(); |
---|
[285] | 57 | |
---|
[175] | 58 | return 0; |
---|
| 59 | } |
---|
| 60 | |
---|
Note: See
TracBrowser
for help on using the repository browser.