Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 188 for code


Ignore:
Timestamp:
Nov 7, 2007, 8:38:47 PM (16 years ago)
Author:
scheusso
Message:

adapted PacketBuffer to work with ENetPacket *

Location:
code/branches/network/src/network
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/PacketBuffer.cc

    r174 r188  
    1313}
    1414
    15 bool PacketBuffer::push(PacketEnvelope pck){
     15bool PacketBuffer::push(ENetPacket *pck){
    1616  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     17//   if(closed)
     18//     return false;
    1719  // also works if fifo is null (queue empty)
    1820  // just to be sure last is really the last element
    19   while(last!=NULL && last->next!=NULL)
    20     last=last->next;
     21  /*if(last!=NULL)
     22    while(last->next!=NULL)
     23      last=last->next;*/
    2124  // first element?
    2225  if(first==NULL){
     
    2528    last->next=NULL;
    2629    // change this!!!!!!!
    27     last->packet = new PacketEnvelope;
    28     last->packet->data = pck.data;
    29     last->packet->length = pck.length;
    30   } else {
     30    last->packet = pck;
     31    } else {
    3132    //insert a new element at the bottom
    3233    last->next = new QueueItem;
     
    3536    last->next=NULL;
    3637    // save the packet to the new element
    37     // change this!!!!!!!!
    38     last->packet = new PacketEnvelope;
    39     last->packet->data = pck.data;
    40     last->packet->length = pck.length;
     38    last->packet = pck;
    4139  }
    4240  return true;
    4341}
    4442
    45 PacketEnvelope PacketBuffer::pop(){
     43ENetPacket *PacketBuffer::pop(){
    4644  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
    47   if(first!=NULL){
     45  if(first!=NULL /*&& !closed*/){
    4846    QueueItem *temp = first;
    4947    // get packet
    50     PacketEnvelope *p = first->packet;
     48    ENetPacket *pck=first->packet;
    5149    // remove first element
    5250    first = first->next;
    5351    delete temp;
    54     return *p;
     52    return pck;
    5553  } else{
    56     PacketEnvelope p = {0,0};
    57     return p;
     54    return NULL;
    5855  }
    5956}
  • code/branches/network/src/network/PacketBuffer.h

    r174 r188  
    1616#include <queue>
    1717#include <string>
     18#include <enet/enet.h>
    1819#include <boost/bind.hpp>
    1920#include <boost/thread/mutex.hpp>
     
    3132
    3233struct QueueItem{
    33   PacketEnvelope *packet;
     34  ENetPacket *packet;
    3435  QueueItem *next;
    3536};
     
    4344  void print();
    4445  // pops a packet from the queue
    45   PacketEnvelope pop();
     46  ENetPacket *pop();
    4647  // pushs a packet to the queue
    47   bool push(PacketEnvelope pck);
     48  bool push(ENetPacket *pck);
    4849private:
    4950  QueueItem *first;
  • code/branches/network/src/network/PacketBufferTestExt.cc

    r187 r188  
     1#include <string>
     2#include <iostream>
     3#include <enet/enet.h>
     4#include <boost/thread/thread.hpp>
    15#include "network/PacketBuffer.h"
    26#include "network/PacketBuffer.cc"
    3 #include <boost/thread/thread.hpp>
    4 #include <iostream>
    5 #include <string>
    67
    78using namespace network;
     
    910
    1011void write(PacketBuffer *test){
    11   PacketEnvelope p;
     12  ENetPacket *packet;
    1213  if(test->isEmpty())
    1314    std::cout << "empty buffer" << std::endl;
    1415  for(int i=0; i<10; i++){
    15     p.data=i*i;
    16     std::cout << i << ": pushing " << p.data << std::endl;
    17     test->push(p);
     16    std::string temp = "packet ";
     17    packet = enet_packet_create("packet", strlen("packet ")+1,
     18ENET_PACKET_FLAG_RELIABLE);
     19    std::cout << i << ": pushing " << packet->data << std::endl;
     20    test->push(packet);
    1821    if(i==5)
    1922      usleep(200000);
     
    2932    // only pop if the queue isn't empty
    3033    while(!test->isEmpty()){
    31       int i=test->pop().data;
    32       std::cout << "We popped the value " << i << std::endl;
     34      std::cout << "We popped the value " << test->pop()->data << std::endl;
    3335    }
    3436  }
Note: See TracChangeset for help on using the changeset viewer.