int main() {

	int shm_size;

	{
		shm_size = (1 << 20);
		printf("%d read write testing...\n", shm_size);
		writewrap(shm_size);
		readwrap(shm_size);
	}

	{
		shm_size = (1 << 20) * 10;
		printf("%d read write testing...\n", shm_size);
		writewrap(shm_size);
		readwrap(shm_size);
	}

	{
		shm_size = (1 << 20) * 100;
		printf("%d read write testing...\n", shm_size);
		writewrap(shm_size);
		readwrap(shm_size);
	}

	{
		shm_size = (1 << 20) * 300;
		printf("%d read write testing...\n", shm_size);
		writewrap(shm_size);
		readwrap(shm_size);
	}
	{
		shm_size = (1 << 20) * 500;
		printf("%d read write testing...\n", shm_size);
		writewrap(shm_size);
		readwrap(shm_size);
	}

	printf("finished!\n");
	return 0;
}
Example #2
0
int
examsgRngPutVaList(exa_ringbuf_t *rng, va_list ap)
{
  examsg_blktail t;
  struct examsg_blkhead h;
  size_t msgsize = 0, total, avail;
  char *buff;
  va_list ap2;

  /* sanity checks */
  if (!rng || rng->magic != EXAMSG_RNG_MAGIC)
    return -EINVAL;

  examsg_blktail_init(&t);

  /* preserve ap as it is used later in this function */
  va_copy(ap2, ap);

  /* compute size */
  while (va_arg(ap2, void *) != NULL)
    {
      size_t s = va_arg(ap2, size_t);
      msgsize += s;
    }

  /* total size of block, including our overhead */
  total = msgsize + sizeof(h) + sizeof(t);

  /* check free space */
  if (rng->pRd > rng->pWr)
    avail = rng->pRd - rng->pWr;
  else
    avail = rng->size - rng->pWr + rng->pRd;

  if (total >= avail)
    {
      rng->stats.full_count++;
      return -ENOSPC;
    }

  /* Statistics are updated only when putting a message in the ring buffer
   * (and not when removing one) because we're interested in "worst cases" */
  examsgRngStatsUpdate(rng, total);

  /* setup message header */
  h.size = msgsize;
  h.magic = EXAMSG_HEAD_MAGIC;

  writewrap(rng, (const char*)&h, sizeof(h));

  /* store buffers in ringbuf */
  while ((buff = va_arg(ap, char *)) != NULL)
    {
      size_t s = va_arg(ap, size_t);
      writewrap(rng, buff, s);
    }

  writewrap(rng, (const char*)&t, sizeof(t));

  return msgsize;
}