Changeset 1182 in ntrip


Ignore:
Timestamp:
Oct 31, 2008, 3:47:10 PM (15 years ago)
Author:
mervart
Message:

ZL: myWrite

Location:
trunk/BNC
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bnccaster.cpp

    r1179 r1182  
    212212void bncCaster::dumpEpochs(long minTime, long maxTime) {
    213213
    214   const char begEpoch = 'A';
    215   const char begObs   = 'B';
    216   const char endEpoch = 'C';
     214  const char begEpoch[] = "BEGEPOCH";
     215  const char endEpoch[] = "ENDEPOCH";
     216
     217  const int begEpochNBytes = sizeof(begEpoch) - 1;
     218  const int endEpochNBytes = sizeof(endEpoch) - 1;
    217219
    218220  for (long sec = minTime; sec <= maxTime; sec++) {
     
    268270        // ----------------------
    269271        if (_sockets) {
    270           int numBytes = sizeof(obs->_o);
    271272          QMutableListIterator<QTcpSocket*> is(*_sockets);
    272273          while (is.hasNext()) {
    273274            QTcpSocket* sock = is.next();
     275            int myFlag = 0;
    274276            if (sock->state() == QAbstractSocket::ConnectedState) {
    275277              bool ok = true;
    276               int fd = sock->socketDescriptor();
    277278              if (first) {
    278                 if (::write(fd, &begEpoch, 1) != 1) {
     279                if (myWrite(sock, begEpoch, begEpochNBytes) != begEpochNBytes) {
     280                  myFlag = 1;
    279281                  ok = false;
    280282                }
    281283              }
    282               if (::write(fd, &begObs, 1) != 1) {
    283                 ok = false;
    284               }
    285               if (::write(fd, &obs->_o, numBytes) != numBytes) {
     284              int numBytes = sizeof(obs->_o);
     285              if (myWrite(sock, (const char*)(&obs->_o), numBytes) != numBytes) {
     286                myFlag = 2;
    286287                ok = false;
    287288              }
    288289              if (!it.hasNext()) {
    289                 if (::write(fd, &endEpoch, 1) != 1) {
     290                if (myWrite(sock, endEpoch, endEpochNBytes) != endEpochNBytes) {
     291                  myFlag = 3;
    290292                  ok = false;
    291293                }
     
    433435  _confTimer->start(ms);
    434436}
     437
     438//
     439////////////////////////////////////////////////////////////////////////////
     440int bncCaster::myWrite(QTcpSocket* sock, const char* buf, int bufLen) {
     441  int bytesWritten = 0;
     442  for (;;) {
     443    int newBytes = sock->write(buf+bytesWritten, bufLen-bytesWritten);
     444    if (newBytes < 0) {
     445      std::cout << "myWrite " << newBytes << "  "  << sock->state() << std::endl;
     446      return newBytes;
     447    }
     448    else {
     449      bytesWritten += newBytes;
     450    }
     451    if (bytesWritten == bufLen) {
     452      return bytesWritten;
     453    }
     454  }
     455}
  • trunk/BNC/bnccaster.h

    r1179 r1182  
    5858 private:
    5959   void dumpEpochs(long minTime, long maxTime);
     60   static int myWrite(QTcpSocket* sock, const char* buf, int bufLen);
    6061
    6162   QFile*                  _outFile;
Note: See TracChangeset for help on using the changeset viewer.