Exemplo n.º 1
0
void MSAConnection::doRead(void)
{
  MSBuffer *hb=headBuffer() ;
  MSBuffer *db=readBuffer() ;
  int s,n;
  
  if (isSet(MSProtocolConnection<MSA>::Reset)==MSTrue) return;
  if((s=hb->put()-hb->get())<4)
   {
     if((n=readTheBuffer(hb,4-s))<0) return;
     if((s=hb->put()-hb->get())<4) return;
     _bytesToNextMessage=MSA::longAt(hb->get());
     if (_bytesToNextMessage<=0) 
      {
	hb->reset();
        unset(MSProtocolConnection<MSA>::Read);
	return;
      }
   }
  if((n=readTheBuffer(db,_bytesToNextMessage))<0) return;
  if((_bytesToNextMessage-=n)==0)
   {
     MSA d=MSA::importAObject( (char *) db->get(), db->put()-db->get(), (char *)0);
     hb->reset();
     db->clear();
     unset(MSProtocolConnection<MSA>::Read);
     if(d.isNullMSA()==MSTrue){resetWithError(MSProtocolConnection<MSA>::Read);return;}
     readNotify(d);
   }
  return; 
}
Exemplo n.º 2
0
int MSAConnection::doSyncRead(MSA &result_)
{
  MSBuffer *hb=headBuffer();
  MSBuffer *db=readBuffer();
  int s,n;

  if (isSet(MSProtocolConnection<MSA>::Reset)==MSTrue) return 0;
  if ((s=hb->put()-hb->get())<4)
   {
     if ((n=readTheBuffer(hb,4-s))<0) return 0;
     if((s=hb->put()-hb->get())<4) return 0;
     _bytesToNextMessage=MSA::longAt(hb->get());
   }
  if((n=readTheBuffer(db,_bytesToNextMessage))<0) return 0;
  if((_bytesToNextMessage-=n)==0)
   {
     result_=MSA::importAObject((char *) db->get(), db->put()-db->get(), (char *)0);
     hb->reset();
     db->clear();
     unset(MSProtocolConnection<MSA>::Read);
     if((result_.aStructPtr())==(MSAStruct *)0){resetWithError(MSProtocolConnection<MSA>::Read);return 0;}
   }
  
  return 1;
}
Exemplo n.º 3
0
A pSimple_Connection::readOne(void)
{
  ipcWarn(wrnlvl(),"%t pSimple_Connection::readOne\n");
  MSBuffer *hb=headBuffer();
  MSBuffer *db=readBuffer();
  int slen;
  A d,z=(A)0;

  if(4>(slen=hb->put()-hb->get()))
  {
    if(0>readTheBuffer(hb,4-slen)) return (A)0;
    if(4>(slen=hb->put()-hb->get())) return (A)0;
    
    slen=longAt(hb->get());
    if(0>=slen)
    {
      static char fmt[]="\343 IPC warning: zero-length simple message.  slen=%d [%d]\n";
      Warn(fmt,	slen,handle());
      hb->reset();
      turnInReadOff();
      return (A)0;
    }
    d=gv(Ct,slen);
    db->minofbuffer((C *)d); db->get(db->minofbuffer()); 
    db->put((C *)(d)); db->maxofbuffer(db->put()+slen);
  }
  if(0>readTheBuffer(db,db->maxofbuffer()-db->put())) return (A)0;
  if(db->put()==db->maxofbuffer())
  {
    z=(A)db->minofbuffer();
    z->c=1;
    hb->reset();
    db->minofbuffer(0);
    db->clear();
    return z;
  }
  return (A)0;
}
Exemplo n.º 4
0
void MSRawConnection::doRead(void)
{
  int n;
  MSBuffer *db=headBuffer();
  if (isSet(MSProtocolConnection<MSString>::Reset)==MSTrue)   return;
  if((n=readTheBuffer(db,MaxReadSize))<0) return;

  if((n=db->put()-db->get())>0)
   {
     unset(MSProtocolConnection<MSString>::Read);
     MSString d(db->get(),n);
     db->get(db->get()+n);
     readNotify(d);
   }
}
Exemplo n.º 5
0
int MSRawConnection::doSyncRead(MSString &result_)
{
  MSBuffer *db=headBuffer();
  int n;

  if (isSet(MSProtocolConnection<MSString>::Reset)==MSTrue) return 0;
  if ((n=readTheBuffer(db,MaxReadSize))<0) return 0;

  if((n=db->put()-db->get())>0)
   {
     unset(MSProtocolConnection<MSString>::Read);
     result_=MSString(db->get(),n);
     db->get(db->get()+n);
   }
  return 1;
}
Exemplo n.º 6
0
void MSAConnection::doReadBurst(void)
{
  int burstLength,n;
  if (isSet(MSProtocolConnection<MSA>::Reset)==MSTrue) return;
#ifdef MS_WINSOCK
  if (ioctlsocket(fd(),FIONREAD,(unsigned long*)&burstLength) == -1)
#else
  if (ioctl(fd(),FIONREAD,(caddr_t)&burstLength) == -1)
#endif
   {
     resetWithError(MSProtocolConnection<MSA>::Read);
     return;
   }
  if (burstLength<0) {return;}
  if (burstLength==0) 
   {
     MSMessageLog::infoMessage("MSAConnection: No data to be read on read event\n");
     burstLength=4;
   }
  MSBuffer b(burstLength);
  if (n=readTheBuffer(&b,burstLength)<0)
   {
        return;
   }
  if (n==0&&burstLength==0)
   {
     unset(MSProtocolConnection<MSA>::Read);
     return;
   }
  MSA d(getAobjectFromBuffer(&b));
  if (d.isNullMSA()==MSTrue) {return;}
  int count=1,s=0;
  char *cp;
  for(cp=b.get();cp<b.put();cp+=s) 
   {
     s=MSA::longAt(cp);
     cp+=sizeof(long);
     if(b.put()-cp>=s) ++count;
   }

  MSA z(MSA::gv(MSA::ETYPE,count));
  int i;
  for(i=0;i<count;++i) z.aStructPtr()->p[i]=0;
  int index=0;
  z.aStructPtr()->p[index++]=(long)d.aStructPtr();

  while(index<count)
   {
     d=getAobjectFromBuffer(&b);
     if(d.isNullMSA()==MSTrue) break;
     z.aStructPtr()->p[index++]=(long)d.aStructPtr();
   }

  if (index<count) 
   {
     MSMessageLog::warningMessage("MSAConnection: Burst Mode Aborted. Possible Data Loss.\n");
   }
  if (b.get()==b.put()) unset(MSProtocolConnection<MSA>::Read);
  else 
   {
     d=getAobjectFromBuffer(&b);
     if (d.isNullMSA()==MSFalse || b.get()!=b.put())
      {
        MSMessageLog::warningMessage("MSAConnection: Burst Buffer Not Cleared\n");
      }
   }
  readNotify(d);
}
Exemplo n.º 7
0
A pString_Connection::readBurst(void)
{
  ipcWarn(wrnlvl(),"%t pString_Connection::readBurst\n");
  MSBuffer bbuff;
  A d,z=(A)0;
  I slen=readFileLength(),slen1,n,s,count;
  if(-1==slen)R(A)0;
  if(0==slen)
  {
    static char fmt[]="\343 IPC warning: pA::ReadBurst: read event with no data [%d]\n";
    Warn(fmt, handle());
  }

  /* create buff to hold it.  Fill buffer */
  slen1=slen?slen:4;
  bbuff.minofbuffer(mab(slen1));
  bbuff.maxofbuffer(bbuff.minofbuffer()+slen1);
  bbuff.reset();
  if(0>(n=readTheBuffer(&bbuff,slen1))) {mfbuffer(&bbuff); R(A)0;}
  if(0==n&&0==slen) {turnInReadOff(); mfbuffer(&bbuff); R(A)0;}

  d=getAobjFromBuffer(&bbuff);
  if((A)0==d){mfbuffer(&bbuff); R(A)0;}

  // determine how many more complete A-objects lie in bbuff
  count=1;
  for(C *cp=bbuff.get();cp<bbuff.put();cp+=s)
  {
    s=longAt(cp);
    cp+=sizeof(long);
    if(s<=bbuff.put()-cp)++count;
  }

  // create result
  z=gv(Et,count);
  for(int i=0;i<count;++i)z->p[i]=(I)aplus_nl;
  int idx=0;
  z->p[idx++]=(I)d;

  // retrieve additional A-objects from bbuff, fill in z
  while(idx<count)
  {
    d=getAobjFromBuffer(&bbuff);
    if((A)0==d)break;
    z->p[idx++]=(I)d;
  }
  if(idx<count)
  {
    ipcWarn(wrnlvl(),"%t burst mode aborted.  Possible data loss.\n");
  }

  // run once more to clear out bbuff and move partial object into connection
  // buffers
  if(bbuff.get()==bbuff.put())turnInReadOff();
  else
  {
    d=getAobjFromBuffer(&bbuff);
    if((A)0!=d || bbuff.get()!=bbuff.put())
    {
      ipcWarn(wrnlvl(),"%t burst buffer not cleared: %d %d %d\n",
	    d,bbuff.get(),bbuff.put());
    }
  }

  // free bbuff;
  mfbuffer(&bbuff);

  return z;     
}