Last change
on this file since 413 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
|
Line | |
---|
1 | #include <string> |
---|
2 | #include <iostream> |
---|
3 | #include <enet/enet.h> |
---|
4 | #include <boost/thread/thread.hpp> |
---|
5 | #include "PacketBuffer.h" |
---|
6 | #include "PacketBuffer.cc" |
---|
7 | |
---|
8 | #ifdef WIN32 |
---|
9 | #include <windows.h> |
---|
10 | #define usleep(x) Sleep((x)/1000) |
---|
11 | #else |
---|
12 | #include <unistd.h> |
---|
13 | #endif |
---|
14 | |
---|
15 | using namespace network; |
---|
16 | |
---|
17 | |
---|
18 | void write(PacketBuffer *test){ |
---|
19 | ENetEvent event; |
---|
20 | ENetPacket *packet; |
---|
21 | if(test->isEmpty()) |
---|
22 | std::cout << "empty buffer" << std::endl; |
---|
23 | for(int i=0; i<10; i++){ |
---|
24 | std::string temp = "packet "; |
---|
25 | packet = enet_packet_create("packet", strlen("packet ")+1, |
---|
26 | ENET_PACKET_FLAG_RELIABLE); |
---|
27 | std::cout << i << ": pushing " << packet->data << std::endl; |
---|
28 | event.packet=packet; |
---|
29 | test->push(&event); |
---|
30 | if(i==5) |
---|
31 | usleep(200000); |
---|
32 | } |
---|
33 | test->setClosed(true); |
---|
34 | return; |
---|
35 | } |
---|
36 | |
---|
37 | void read(PacketBuffer *test){ |
---|
38 | //test->print(); |
---|
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()){ |
---|
43 | std::cout << "We popped the value " << test->pop()->data << std::endl; |
---|
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)); |
---|
54 | |
---|
55 | thrd1.join(); |
---|
56 | thrd2.join(); |
---|
57 | |
---|
58 | return 0; |
---|
59 | } |
---|
60 | |
---|
Note: See
TracBrowser
for help on using the repository browser.