4 responder (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
6 memif_connection_t *c = (memif_connection_t *) private_ctx;
10 /* receive packets from the shared memory */
11 err = memif_rx_burst (conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &c->rx_buf_num);
12 if (err != MEMIF_ERR_SUCCESS)
14 INFO ("memif_rx_burst: %s", memif_strerror (err));
20 /* allocate tx buffers */
21 err = memif_buffer_alloc (conn, qid, c->tx_bufs, c->rx_buf_num,
22 &c->tx_buf_num, c->buffer_size);
23 /* suppress full ring error MEMIF_ERR_NOBUF_RING */
24 if (err != MEMIF_ERR_SUCCESS && err != MEMIF_ERR_NOBUF_RING)
26 INFO ("memif_buffer_alloc: %s", memif_strerror (err));
30 /* Process the packets */
31 if (c->packet_handler == NULL)
33 INFO ("Missing packet handler");
36 err = c->packet_handler (c);
39 INFO ("packet handler error: %d", err);
42 /* Done processing packets */
44 /* refill the queue */
45 err = memif_refill_queue (conn, qid, c->tx_buf_num, c->headroom_size);
46 if (err != MEMIF_ERR_SUCCESS)
48 INFO ("memif_refill_queue: %s", memif_strerror (err));
51 c->rx_buf_num -= c->tx_buf_num;
53 err = memif_tx_burst (conn, qid, c->tx_bufs, c->tx_buf_num, &tx);
54 if (err != MEMIF_ERR_SUCCESS)
56 INFO ("memif_tx_burst: %s", memif_strerror (err));
61 /* This should never happen */
62 if (c->tx_buf_num != 0)
64 INFO ("memif_tx_burst failed to send all allocated buffers.");
68 while (c->rx_buf_num > 0);
73 err = memif_refill_queue (conn, qid, c->rx_buf_num, c->headroom_size);
74 if (err != MEMIF_ERR_SUCCESS)
76 INFO ("memif_refill_queue: %s", memif_strerror (err));
85 responder_zero_copy (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
87 memif_connection_t *c = (memif_connection_t *) private_ctx;
91 /* receive packets from the shared memory */
92 err = memif_rx_burst (conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &c->rx_buf_num);
93 if (err != MEMIF_ERR_SUCCESS)
95 INFO ("memif_rx_burst: %s", memif_strerror (err));
101 /* Note that in zero copy memif_buffer_alloc is not part of respond
103 * instead rx buffers are used directly using memif_buffer_enq_tx.
106 /* Process the packets */
107 if (c->packet_handler == NULL)
109 INFO ("Missing packet handler");
112 err = c->packet_handler (c);
115 INFO ("packet handler error: %d", err);
118 /* Done processing packets */
120 /* Swap rx and tx buffers, swapped tx buffers are considered allocated
121 * and are ready to be transmitted. Notice that the buffers are swapped
122 * only in memif driver and locally remain in rx_bufs queue.
124 err = memif_buffer_enq_tx (conn, qid, c->rx_bufs, c->rx_buf_num, &tx);
125 /* suppress full ring error MEMIF_ERR_NOBUF_RING */
126 if (err != MEMIF_ERR_SUCCESS && err != MEMIF_ERR_NOBUF_RING)
128 INFO ("memif_buffer_alloc: %s", memif_strerror (err));
132 /* refill the queue */
133 err = memif_refill_queue (conn, qid, tx, c->headroom_size);
134 if (err != MEMIF_ERR_SUCCESS)
136 INFO ("memif_refill_queue: %s", memif_strerror (err));
141 /* Notice that we send from rx_bufs as the buffers were only swapped
142 * internally in memif driver */
143 err = memif_tx_burst (conn, qid, c->rx_bufs, tx, &tx2);
144 if (err != MEMIF_ERR_SUCCESS)
146 INFO ("memif_tx_burst: %s", memif_strerror (err));
151 /* This should never happen */
154 INFO ("memif_tx_burst failed to send all allocated buffers.");
158 while (c->rx_buf_num > 0);
163 err = memif_refill_queue (conn, qid, c->rx_buf_num, c->headroom_size);
164 if (err != MEMIF_ERR_SUCCESS)
166 INFO ("memif_refill_queue: %s", memif_strerror (err));