Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/audio/src/network/PacketBufferTestExt.cc @ 318

Last change on this file since 318 was 285, checked in by nicolasc, 17 years ago

cleaned up network, builds with CML

File size: 1.1 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
8using namespace network;
9
10
11void write(PacketBuffer *test){
12  ENetPacket *packet;
13  if(test->isEmpty())
14    std::cout << "empty buffer" << std::endl;
15  for(int i=0; i<10; i++){
16    std::string temp = "packet ";
17    packet = enet_packet_create("packet", strlen("packet ")+1,
18ENET_PACKET_FLAG_RELIABLE);
19    std::cout << i << ": pushing " << packet->data << std::endl;
20    test->push(packet);
21    if(i==5)
22      usleep(200000);
23  }
24  test->setClosed(true);
25  return;
26}
27
28void read(PacketBuffer *test){
29  //test->print();
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()){
34      std::cout << "We popped the value " << test->pop()->data << std::endl;
35    }
36  }
37  return;
38}
39
40
41int 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));
45
46  thrd1.join();
47  thrd2.join();
48
49  return 0;
50}
51
Note: See TracBrowser for help on using the repository browser.