Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 346 was 346, checked in by rgrieder, 17 years ago
  • adjusted the entire source to compile under windows visual studio too:
  • added some ugly conversions
  • changed some illegal code pieces (gcc however accepted it)
  • added a few files from reto's framework to evade linker errors (no more dynamic linking)
  • inserted some 'return true' to justify the return type
  • excluded the levelLoader in the orxonox.cc (couldn't make it work, parsing error)
  • wrote about 5 code #branches to compensate for missing usleep() under windows
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
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  ENetPacket *packet;
18  if(test->isEmpty())
19    std::cout << "empty buffer" << std::endl;
20  for(int i=0; i<10; i++){
21    std::string temp = "packet ";
22    packet = enet_packet_create("packet", strlen("packet ")+1,
23ENET_PACKET_FLAG_RELIABLE);
24    std::cout << i << ": pushing " << packet->data << std::endl;
25    test->push((ENetEvent*)packet);
26    if(i==5)
27// under windows, use Sleep(milliseconds) instead of usleep(microseconds)
28#ifdef WIN32
29      Sleep(200);
30#else
31      usleep(200000);
32#endif
33  }
34  test->setClosed(true);
35  return;
36}
37
38void read(PacketBuffer *test){
39  //test->print();
40  // exit if the queue is closed and empty
41  while(!test->isClosed() || !test->isEmpty()){
42    // only pop if the queue isn't empty
43    while(!test->isEmpty()){
44      std::cout << "We popped the value " << test->pop()->data << std::endl;
45    }
46  }
47  return;
48}
49
50
51int main(int argc, char **argv[]){
52  PacketBuffer test = PacketBuffer();
53  boost::thread thrd1(boost::bind(&write, &test));
54  boost::thread thrd2(boost::bind(&read, &test));
55
56  thrd1.join();
57  thrd2.join();
58
59  return 0;
60}
61
Note: See TracBrowser for help on using the repository browser.