[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <loom.20130515T144941-798@post.gmane.org>
Date: Wed, 15 May 2013 12:53:55 +0000 (UTC)
From: Ricardo TubĂo <rtpardavila@...il.com>
To: netdev@...r.kernel.org
Subject: Single socket with TX_RING and RX_RING
Once I tell kernel to export the TX_RING through setsockopt() (see code
below) I always get an error (EBUSY) if i try to tell kernel to export the
RX_RING with the same socket descriptor. Therefore, I have to open an
additional socket for the RX_RING and I require of two sockets when I though
that I would only require of one socket for both TX and RX using mmap()ed
memory.
Do I need both sockets or am I doing something wrong?
Code:
/* init_ring; type = {PACKET_TX_RING, PACKET_RX_RING} */
void *init_ring(const int socket_fd, const int type)
{
void *ring = NULL;
int ring_access_flags = PROT_READ | PROT_WRITE;
tpacket_req_t *p = init_tpacket_req(FRAMES_PER_RING);
int ring_len = ( p->tp_block_size ) * ( p->tp_block_nr );
if ( setsockopt(socket_fd, SOL_PACKET, type,
p, LEN__TPACKET_REQ) < 0 )
{
log_sys_error("Setting socket options for this ring");
}
// 2) open ring
if ( ( ring = mmap(NULL, ring_len, ring_access_flags, MAP_SHARED,
socket_fd, 0) ) == NULL )
{
log_sys_error("mmap()ing error");
}
return(ring);
}
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists