Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/asylum/network/PacketBufferTestExt.cc @ 2117

Last change on this file since 2117 was 1505, checked in by rgrieder, 16 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1/*
2*   ORXONOX - the hottest 3D action shooter ever to exist
3*
4*
5*   License notice:
6*
7*   This program is free software; you can redistribute it and/or
8*   modify it under the terms of the GNU General Public License
9*   as published by the Free Software Foundation; either version 2
10*   of the License, or (at your option) any later version.
11*
12*   This program is distributed in the hope that it will be useful,
13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*   GNU General Public License for more details.
16*
17*   You should have received a copy of the GNU General Public License
18*   along with this program; if not, write to the Free Software
19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20*
21*   Author:
22*      ...
23*   Co-authors:
24*      ...
25*
26*/
27
28#include <string>
29#include <iostream>
30#include <enet/enet.h>
31#include <boost/thread/thread.hpp>
32
33#include "util/Sleep.h"
34#include "PacketBuffer.h"
35#include "PacketBuffer.cc"
36
37using namespace network;
38
39void write(PacketBuffer *test){
40  ENetEvent event;
41  ENetPacket *packet;
42  if(test->isEmpty())
43    std::cout << "empty buffer" << std::endl;
44  for(int i=0; i<10; i++){
45    std::string temp = "packet ";
46    packet = enet_packet_create("packet", strlen("packet ")+1,
47      ENET_PACKET_FLAG_RELIABLE);
48    std::cout << i << ": pushing " << packet->data << std::endl;
49    event.packet=packet;
50    test->push(&event);
51    if(i==5)
52      usleep(200000);
53  }
54  test->setClosed(true);
55  return;
56}
57
58void read(PacketBuffer *test){
59  //test->print();
60  // exit if the queue is closed and empty
61  while(!test->isClosed() || !test->isEmpty()){
62    // only pop if the queue isn't empty
63    while(!test->isEmpty()){
64      std::cout << "We popped the value " << test->pop()->data << std::endl;
65    }
66  }
67  return;
68}
69
70
71int main(int argc, char **argv[]){
72  PacketBuffer test = PacketBuffer();
73  boost::thread thrd1(boost::bind(&write, &test));
74  boost::thread thrd2(boost::bind(&read, &test));
75
76  thrd1.join();
77  thrd2.join();
78
79  return 0;
80}
81
Note: See TracBrowser for help on using the repository browser.