Example #1
0
void  xio_buf_free(struct perf_buf *pbuf)
{
	if (pbuf->mr)
		xio_dereg_mr(&pbuf->mr);

	if (pbuf->addr)
		free_mem_buf(pbuf->addr, pbuf->shmid);

	free(pbuf);
}
Example #2
0
/*---------------------------------------------------------------------------*/
inline void msg_pool_free(struct msg_pool *pool)
{
	if (pool) {
		if (pool->mr)
			xio_dereg_mr(&pool->mr);
		if (pool->data)
			free_mem_buf(pool->data, pool->shmid);
		free(pool->header);
		free(pool);
	}
}
Example #3
0
void  xio_buf_free(struct perf_buf *pbuf)
{
	if (pbuf->mr) {
		struct xio_reg_mem	reg_mem;

		reg_mem.mr = pbuf->mr;
		xio_mem_dereg(&reg_mem);
	}

	if (pbuf->addr)
		free_mem_buf((uint8_t *)pbuf->addr, pbuf->shmid);

	free(pbuf);
}
Example #4
0
/*---------------------------------------------------------------------------*/
void msg_api_free(struct msg_params *msg_params)
{
	if (msg_params->g_hdr) {
		free(msg_params->g_hdr);
		msg_params->g_hdr = NULL;
	}
	if (msg_params->g_data_mr) {
		xio_dereg_mr(&msg_params->g_data_mr);
		msg_params->g_data_mr = NULL;
	}
	if (msg_params->g_data) {
		free_mem_buf(msg_params->g_data, msg_params->g_shmid);
		msg_params->g_data = NULL;
	}
}
Example #5
0
/*---------------------------------------------------------------------------*/
int msg_api_init(struct msg_params *msg_params, size_t hdrlen, size_t datalen, int is_server)
{
	int pagesize = sysconf(_SC_PAGESIZE);
	const char	*req_hdr = "hello world request header";
	const char	*req_data = "hello world request data";
	const char	*rsp_hdr =  "hello world response header";
	const char	*rsp_data = "hello world response data";
	const char	*ptr;
	int		len, i;
	unsigned char	c;

	msg_params->g_hdr = NULL;
	msg_params->g_data = NULL;
	if (hdrlen) {
		msg_params->g_hdr = memalign(pagesize, hdrlen);
		if (!msg_params->g_hdr)
			goto cleanup;
		ptr = (is_server) ? rsp_hdr : req_hdr;
		len = strlen(ptr);
		if (hdrlen < len)
			len = hdrlen;
		strncpy((char *)msg_params->g_hdr, ptr, len);
		msg_params->g_hdr[len] = 0;
		len++;

		for (i = len, c = 65;  i < hdrlen; i++) {
			msg_params->g_hdr[i] = c;
			c++;
			if (c > 122)
				c = 65;
		}
	}
	if (datalen) {
		datalen = ALIGNHUGEPAGE(datalen);
		msg_params->g_data = alloc_mem_buf(datalen, &msg_params->g_shmid);
		if (!msg_params->g_data)
			goto cleanup;
		ptr = (is_server) ? rsp_data : req_data;
		len = strlen(ptr);
		if (datalen < len)
			len = datalen;
		strncpy((char *)msg_params->g_data, ptr, len);
		msg_params->g_data[len] = 0;
		len++;

		for (i = len, c = 65;  i < datalen; i++) {
			msg_params->g_data[i] = c;
			c++;
			if (c > 122)
				c = 65;
		}
		msg_params->g_data_mr = xio_reg_mr(msg_params->g_data, datalen);
	}
	return 0;

cleanup:
	if (msg_params->g_hdr) {
		free(msg_params->g_hdr);
		msg_params->g_hdr = NULL;
	}

	if (msg_params->g_data) {
		free_mem_buf(msg_params->g_data, msg_params->g_shmid);
		msg_params->g_data = NULL;
	}

	return -1;
}