Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 620 was 514, checked in by nicolasc, 17 years ago

added copyright notice

File size: 2.1 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#include "PacketBuffer.h"
33#include "PacketBuffer.cc"
34
35#ifdef WIN32
36#include <windows.h>
37#define usleep(x) Sleep((x)/1000)
38#else
39#include <unistd.h>
40#endif
41
42using namespace network;
43
44
45void write(PacketBuffer *test){
46  ENetEvent event;
47  ENetPacket *packet;
48  if(test->isEmpty())
49    std::cout << "empty buffer" << std::endl;
50  for(int i=0; i<10; i++){
51    std::string temp = "packet ";
52    packet = enet_packet_create("packet", strlen("packet ")+1,
53ENET_PACKET_FLAG_RELIABLE);
54    std::cout << i << ": pushing " << packet->data << std::endl;
55    event.packet=packet;
56    test->push(&event);
57    if(i==5)
58      usleep(200000);
59  }
60  test->setClosed(true);
61  return;
62}
63
64void read(PacketBuffer *test){
65  //test->print();
66  // exit if the queue is closed and empty
67  while(!test->isClosed() || !test->isEmpty()){
68    // only pop if the queue isn't empty
69    while(!test->isEmpty()){
70      std::cout << "We popped the value " << test->pop()->data << std::endl;
71    }
72  }
73  return;
74}
75
76
77int main(int argc, char **argv[]){
78  PacketBuffer test = PacketBuffer();
79  boost::thread thrd1(boost::bind(&write, &test));
80  boost::thread thrd2(boost::bind(&read, &test));
81
82  thrd1.join();
83  thrd2.join();
84
85  return 0;
86}
87
Note: See TracBrowser for help on using the repository browser.