Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added copyright notice

File size: 2.1 KB
RevLine 
[514]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
[188]28#include <string>
29#include <iostream>
30#include <enet/enet.h>
31#include <boost/thread/thread.hpp>
[285]32#include "PacketBuffer.h"
33#include "PacketBuffer.cc"
[175]34
[514]35#ifdef WIN32
36#include <windows.h>
37#define usleep(x) Sleep((x)/1000)
38#else
39#include <unistd.h>
40#endif
[367]41
[175]42using namespace network;
43
44
45void write(PacketBuffer *test){
[351]46  ENetEvent event;
[188]47  ENetPacket *packet;
[175]48  if(test->isEmpty())
49    std::cout << "empty buffer" << std::endl;
50  for(int i=0; i<10; i++){
[188]51    std::string temp = "packet ";
[285]52    packet = enet_packet_create("packet", strlen("packet ")+1,
[188]53ENET_PACKET_FLAG_RELIABLE);
54    std::cout << i << ": pushing " << packet->data << std::endl;
[351]55    event.packet=packet;
56    test->push(&event);
[175]57    if(i==5)
58      usleep(200000);
59  }
60  test->setClosed(true);
61  return;
62}
63
64void read(PacketBuffer *test){
[187]65  //test->print();
[175]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()){
[188]70      std::cout << "We popped the value " << test->pop()->data << std::endl;
[175]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));
[285]81
[175]82  thrd1.join();
83  thrd2.join();
[285]84
[175]85  return 0;
86}
87
Note: See TracBrowser for help on using the repository browser.