Esempio n. 1
0
static int
xferResultBuffer(NativeResult * nr, int to, int more, int rc, unsigned long length)
{
  long            l =
      sizeof(BinResponseHdr) + ((nr->sNext - 1) * sizeof(MsgSegment));
  unsigned int    i;
  int             dmy = -1,
                  s1 = l;

  _SFCB_ENTER(TRACE_PROVIDERDRV, "xferResultBuffer");

  if (nr->data == NULL)
    prepResultBuffer(nr, length);

  for (i = 0; i < nr->sMax; i++) {
    nr->resp->object[i].data = (void *) l;
    l += nr->resp->object[i].length;
  }

  nr->resp->moreChunks = more;
  nr->resp->rc = rc;
  nr->resp->count = nr->sNext;

  rc = spSendResult2(&to, &dmy, nr->resp, s1, nr->data, nr->dNext);
  if (more)
    spRcvAck(to);

  _SFCB_RETURN(rc);
}
Esempio n. 2
0
/*
 * find the next position where we can stick the next object of type that
 * is 'length' long in 'nr'. If necessary, send what's in the buffer
 * already. 
 */
static void    *
nextResultBufferPos(NativeResult * nr, int type, int length)
{
  long            pos,
                  npos;

  _SFCB_ENTER(TRACE_PROVIDERDRV, "nextResultBufferPos");
  if (nr->data == NULL)
    prepResultBuffer(nr, length);

  /*
   * if there won't be enough room, send it off or make nr->data bigger 
   */
  if (nr->dNext + length >= nr->dMax) {
    /*
     * either we aren't chunking or length > buffer size 
     */
    if (!nr->requestor || length >= nr->dMax) {
      while (nr->dNext + length >= nr->dMax)
        nr->dMax *= 2;
      nr->data = (char *) realloc(nr->data, nr->dMax);
    }
    /*
     * xfering current contents to make enough room 
     */
    else {
      xferResultBuffer(nr, nr->requestor, 1, 1, length);
      nr->dNext = 0;
      nr->sNext = 0;
    }
  }

  if (nr->sNext == nr->sMax) {
    nr->sMax *= 2;
    nr->resp =
        (BinResponseHdr *) realloc(nr->resp,
                                   sizeof(BinResponseHdr) +
                                   ((nr->sMax - 1) * sizeof(MsgSegment)));
  }

  /*
   * store the pointer to the location within nr->data where this object
   * will be 
   */
  nr->resp->object[nr->sNext].data = (void *) nr->dNext;
  nr->resp->object[nr->sNext].length = length;
  nr->resp->object[nr->sNext++].type = type;
  pos = nr->dNext;
  nr->dNext += length;          /* set the position for next object after
                                 * this one. ready for memcpy */

  npos = (long) (nr->data + pos);
  _SFCB_RETURN((void *) npos);
}