}
static inline int
-vcl_test_read_ds (int fd, vppcom_data_segments_t ds, vcl_test_stats_t * stats)
+vcl_test_read_ds (int fd, vppcom_data_segment_t * ds,
+ vcl_test_stats_t * stats)
{
int rx_bytes;
{
if (stats)
stats->rx_xacts++;
- rx_bytes = vppcom_session_read_segments (fd, ds);
+ rx_bytes = vppcom_session_read_segments (fd, ds, 2, ~0);
if (rx_bytes < 0)
{
vcl_test_stats_t stats;
vppcom_endpt_t endpt;
uint8_t ip[16];
- vppcom_data_segments_t ds;
+ vppcom_data_segment_t ds[2];
} vcl_test_server_conn_t;
typedef struct
}
if (vsm->use_ds)
- vppcom_session_free_segments (conn->fd, conn->ds);
+ vppcom_session_free_segments (conn->fd, rx_bytes);
if (conn->stats.rx_bytes >= conn->cfg.total_bytes)
clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
}
+static void
+vts_copy_ds (void *buf, vppcom_data_segment_t * ds, u32 max_bytes)
+{
+ uint32_t n_bytes = 0, ds_idx = 0;
+
+ while (n_bytes < max_bytes)
+ {
+ clib_memcpy_fast (buf + n_bytes, ds[ds_idx].data,
+ clib_min (ds[ds_idx].len, max_bytes - n_bytes));
+ ds_idx += 1;
+ }
+}
+
static void
vts_server_echo (vcl_test_server_conn_t * conn, int rx_bytes)
{
int tx_bytes, nbytes, pos;
if (vsm->use_ds)
- vppcom_data_segment_copy (conn->buf, conn->ds, rx_bytes);
+ vts_copy_ds (conn->buf, conn->ds, rx_bytes);
/* If it looks vaguely like a string, make sure it's terminated */
pos = rx_bytes < conn->buf_size ? rx_bytes : conn->buf_size - 1;
{
/* We could avoid the copy if the first segment is big enough but this
* just simplifies things */
- vppcom_data_segment_copy (conn->buf, conn->ds, sizeof (vcl_test_cfg_t));
+ vts_copy_ds (conn->buf, conn->ds, sizeof (vcl_test_cfg_t));
}
return (vcl_test_cfg_t *) conn->buf;
}
if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
{
if (vsm->use_ds)
- vppcom_session_free_segments (conn->fd, conn->ds);
+ vppcom_session_free_segments (conn->fd, rx_bytes);
vts_handle_cfg (wrk, rx_cfg, conn, rx_bytes);
if (!wrk->nfds)
{
}
int
-svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs)
+svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs, u32 n_segs,
+ u32 max_bytes)
{
- u32 cursize, head, tail, head_idx;
+ u32 cursize, to_read, head, tail, fs_index = 1, n_bytes, head_pos, len;
+ svm_fifo_chunk_t *c;
f_load_head_tail_cons (f, &head, &tail);
if (PREDICT_FALSE (cursize == 0))
return SVM_FIFO_EEMPTY;
- head_idx = head;
+ to_read = clib_min (cursize, max_bytes);
- if (tail < head)
- {
- fs[0].len = f->size - head_idx;
- fs[0].data = f->head_chunk->data + head_idx;
- fs[1].len = cursize - fs[0].len;
- fs[1].data = f->head_chunk->data;
- }
- else
+ c = f->head_chunk;
+ head_pos = head - c->start_byte;
+ fs[0].data = c->data + head_pos;
+ fs[0].len = c->length - head_pos;
+ n_bytes = fs[0].len;
+ c = c->next;
+
+ while (n_bytes < to_read && fs_index < n_segs)
{
- fs[0].len = cursize;
- fs[0].data = f->head_chunk->data + head_idx;
- fs[1].len = 0;
- fs[1].data = 0;
+ len = clib_min (c->length, to_read - n_bytes);
+ fs[fs_index].data = c->data;
+ fs[fs_index].len = len;
+ n_bytes += len;
+ c = c->next;
+ fs_index += 1;
}
- return cursize;
-}
-
-void
-svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs)
-{
- u32 head;
- /* consumer owned index */
- head = f->head;
-
- ASSERT (fs[0].data == f->head_chunk->data + head);
- head = (head + fs[0].len + fs[1].len);
- /* store-rel: consumer owned index (paired with load-acq in producer) */
- clib_atomic_store_rel_n (&f->head, head);
+ return n_bytes;
}
/**
* @param f fifo
*/
void svm_fifo_dequeue_drop_all (svm_fifo_t * f);
-int svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs);
-void svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs);
+/**
+ * Get pointers to fifo chunks data in @ref svm_fifo_seg_t array
+ *
+ * Populates fifo segment array with pointers to fifo chunk data and lengths.
+ * Because this returns pointers to data, it must be paired with
+ * @ref svm_fifo_dequeue_drop to actually release the fifo chunks after the
+ * data is consumed.
+ *
+ * @param f fifo
+ * @param fs array of fifo segments allocated by caller
+ * @param n_segs number of fifo segments in array
+ * @param max_bytes max bytes to be mapped to fifo segments
+ * @return number of bytes in fifo segments or SVM_FIFO_EEMPTY
+ */
+int svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs, u32 n_segs,
+ u32 max_bytes);
/**
* Add io events subscriber to list
*
int
vppcom_session_read_segments (uint32_t session_handle,
- vppcom_data_segments_t ds)
+ vppcom_data_segment_t * ds, uint32_t n_segments,
+ uint32_t max_bytes)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
int n_read = 0, is_nonblocking;
}
}
- n_read = svm_fifo_segments (rx_fifo, (svm_fifo_seg_t *) ds);
- svm_fifo_unset_event (rx_fifo);
-
+ n_read = svm_fifo_segments (rx_fifo, (svm_fifo_seg_t *) ds, n_segments,
+ max_bytes);
return n_read;
}
void
-vppcom_session_free_segments (uint32_t session_handle,
- vppcom_data_segments_t ds)
+vppcom_session_free_segments (uint32_t session_handle, uint32_t n_bytes)
{
vcl_worker_t *wrk = vcl_worker_get_current ();
vcl_session_t *s;
if (PREDICT_FALSE (!s || s->is_vep))
return;
- svm_fifo_segments_free (s->rx_fifo, (svm_fifo_seg_t *) ds);
-}
-
-int
-vppcom_data_segment_copy (void *buf, vppcom_data_segments_t ds, u32 max_bytes)
-{
- u32 first_copy = clib_min (ds[0].len, max_bytes);
- clib_memcpy_fast (buf, ds[0].data, first_copy);
- if (first_copy < max_bytes)
+ svm_fifo_dequeue_drop (s->rx_fifo, n_bytes);
+ if (svm_fifo_is_empty_cons (s->rx_fifo))
{
- clib_memcpy_fast (buf + first_copy, ds[1].data,
- clib_min (ds[1].len, max_bytes - first_copy));
+ svm_fifo_unset_event (s->rx_fifo);
+ if (!svm_fifo_is_empty_cons (s->rx_fifo)
+ && svm_fifo_set_event (s->rx_fifo)
+ && VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK))
+ {
+ session_event_t *e;
+ vec_add2 (wrk->unhandled_evts_vector, e, 1);
+ e->event_type = SESSION_IO_EVT_RX;
+ e->session_index = s->session_index;
+ }
}
- return 0;
}
static u8
extern int vppcom_session_worker (vcl_session_handle_t session_handle);
extern int vppcom_session_read_segments (uint32_t session_handle,
- vppcom_data_segments_t ds);
+ vppcom_data_segment_t * ds,
+ uint32_t n_segments,
+ uint32_t max_bytes);
extern void vppcom_session_free_segments (uint32_t session_handle,
- vppcom_data_segments_t ds);
+ uint32_t n_bytes);
extern int vppcom_session_tls_add_cert (uint32_t session_handle, char *cert,
uint32_t cert_len);
extern int vppcom_session_tls_add_key (uint32_t session_handle, char *key,
uint32_t key_len);
-extern int vppcom_data_segment_copy (void *buf, vppcom_data_segments_t ds,
- uint32_t max_bytes);
extern int vppcom_unformat_proto (uint8_t * proto, char *proto_str);
extern int vppcom_session_is_connectable_listener (uint32_t session_handle);
extern int vppcom_session_listener (uint32_t session_handle);