Changeset 11422 for trunk/FACT++


Ignore:
Timestamp:
07/15/11 15:25:32 (13 years ago)
Author:
tbretz
Message:
Don't use just a single buffer for writing, it might become overwritten if a new event is added to the queue before the olf one was sent.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/fad.cc

    r11380 r11422  
    101101    {
    102102        cout << "Data sent: (transmitted=" << bytes_transferred << ") rc=" << error.message() << " (" << error << ")" << endl;
     103        fOutQueue.pop_front();
    103104    }
    104105
    105106    vector<uint16_t> fBufCommand;
    106     vector<uint16_t> fBuffer;
    107107
    108108    vector<uint16_t> fCommand;
     
    120120
    121121    int fSocket;
     122
     123    deque<vector<uint16_t>> fOutQueue;
    122124
    123125    void SendData()
     
    132134            fHeader.fTempDrs[i] = (42.+fBoardId/40.+float(rand())/RAND_MAX*5)*16;
    133135
    134         fBuffer.resize(0);
     136        vector<uint16_t> evtbuf;
    135137
    136138        for (int i=0; i<kNumChannels; i++)
     
    140142            const vector<uint16_t> buf = fChHeader[i].HtoN();
    141143
    142             fBuffer.insert(fBuffer.end(), buf.begin(), buf.end());
    143             fBuffer.insert(fBuffer.end(), fChHeader[i].fRegionOfInterest, 0x42+fHeader.fEventCounter*100);
     144            evtbuf.insert(evtbuf.end(), buf.begin(), buf.end());
     145            evtbuf.insert(evtbuf.end(), fChHeader[i].fRegionOfInterest, 0x42+fHeader.fEventCounter*100);
    144146
    145147            fHeader.fPackageLength += sizeof(ChannelHeader)/2;
     
    147149        }
    148150
    149         fBuffer.push_back(htons(FAD::kDelimiterEnd));
     151        evtbuf.push_back(htons(FAD::kDelimiterEnd));
    150152
    151153        const vector<uint16_t> h = fHeader.HtoN();
    152154
    153         fBuffer.insert(fBuffer.begin(), h.begin(), h.end());
     155        evtbuf.insert(evtbuf.begin(), h.begin(), h.end());
     156
     157        fOutQueue.push_back(evtbuf);
    154158
    155159        if (fCommandSocket)
    156             AsyncWrite(this, ba::buffer(ba::const_buffer(fBuffer.data(), fBuffer.size()*2)));
     160            AsyncWrite(this, ba::buffer(ba::const_buffer(fOutQueue.back().data(), fOutQueue.back().size()*2)));
    157161        else
    158162        {
     
    163167            fSocket %= fSockets.size();
    164168
    165             AsyncWrite(fSockets[fSocket].get(), ba::buffer(ba::const_buffer(fBuffer.data(), fBuffer.size()*2)));
     169            AsyncWrite(fSockets[fSocket].get(), ba::buffer(ba::const_buffer(fOutQueue.back().data(), fOutQueue.back().size()*2)));
    166170        }
    167171    }
Note: See TracChangeset for help on using the changeset viewer.