Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/PacketBufferTestExt.cc @ 356

Last change on this file since 356 was 355, checked in by landauf, 17 years ago

changed retos usleep hack to a more generic solution:
#ifdef WIN32
#include <windows.h>
#define usleep(x) Sleep((x)/1000)

File size: 1.2 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  ENetEvent event;
13  ENetPacket *packet;
14  if(test->isEmpty())
15    std::cout << "empty buffer" << std::endl;
16  for(int i=0; i<10; i++){
17    std::string temp = "packet ";
18    packet = enet_packet_create("packet", strlen("packet ")+1,
19ENET_PACKET_FLAG_RELIABLE);
20    std::cout << i << ": pushing " << packet->data << std::endl;
21    event.packet=packet;
22    test->push(&event);
23    if(i==5)
24      usleep(200000);
25  }
26  test->setClosed(true);
27  return;
28}
29
30void read(PacketBuffer *test){
31  //test->print();
32  // exit if the queue is closed and empty
33  while(!test->isClosed() || !test->isEmpty()){
34    // only pop if the queue isn't empty
35    while(!test->isEmpty()){
36      std::cout << "We popped the value " << test->pop()->data << std::endl;
37    }
38  }
39  return;
40}
41
42
43int main(int argc, char **argv[]){
44  PacketBuffer test = PacketBuffer();
45  boost::thread thrd1(boost::bind(&write, &test));
46  boost::thread thrd2(boost::bind(&read, &test));
47
48  thrd1.join();
49  thrd2.join();
50
51  return 0;
52}
53
Note: See TracBrowser for help on using the repository browser.