Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 351 was 351, checked in by scheusso, 16 years ago

adjustet PacketBufferTestExt (because of changes in PacketBuffer) and Synchronisable.cc (registerAllVariables must be called by the Constructor of Synchronisable)

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