18 #include <sys/types.h> 19 #include <sys/socket.h> 22 #include <netinet/in.h> 84 __attribute__((constructor))
104 __attribute__((destructor))
161 u16 id = ntohs(*((
u16 *)msg));
165 clib_warning(
"Message ID %d has wrong length: %d\n",
id, l);
178 vl_api_memclnt_keepalive_reply_t *rmp;
189 u16 id = ntohs(*((
u16 *)msg));
191 case VL_API_RX_THREAD_EXIT:
195 rx_thread_done =
true;
202 case VL_API_MEMCLNT_RX_THREAD_SUSPEND:
212 case VL_API_MEMCLNT_READ_TIMEOUT:
213 clib_warning(
"Received read timeout in async thread\n");
217 case VL_API_MEMCLNT_KEEPALIVE:
221 rmp->_vl_msg_id = ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY);
248 while (!timeout_in_progress)
252 gettimeofday(&tv, NULL);
256 if (!timeout_cancelled) {
259 if (rv == ETIMEDOUT && !timeout_thread_cancelled) {
261 ep->_vl_msg_id = ntohs(VL_API_MEMCLNT_READ_TIMEOUT);
283 ep->_vl_msg_id = ntohs(VL_API_MEMCLNT_RX_THREAD_SUSPEND);
287 rx_is_running =
false;
298 if (rx_is_running)
goto unlock;
300 rx_is_running =
true;
323 rx_thread_done =
false;
328 if (chroot_prefix != NULL)
350 rx_is_running =
true;
371 read_timeout = timeout;
372 timeout_in_progress =
true;
373 timeout_cancelled =
false;
383 timeout_in_progress =
false;
384 timeout_cancelled =
true;
402 ep->_vl_msg_id = ntohs(VL_API_RX_THREAD_EXIT);
408 gettimeofday(&tv, NULL);
409 ts.tv_sec = tv.tv_sec + 5;
413 if (rx_thread_done ==
false)
426 timeout_thread_cancelled =
true;
447 vl_api_memclnt_keepalive_reply_t *rmp;
459 if (am->
our_pid == 0)
return (-4);
471 u16 msg_id = ntohs(*((
u16 *)msg));
473 case VL_API_RX_THREAD_EXIT:
476 case VL_API_MEMCLNT_RX_THREAD_SUSPEND:
478 case VL_API_MEMCLNT_READ_TIMEOUT:
480 case VL_API_MEMCLNT_KEEPALIVE:
485 rmp->_vl_msg_id = ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY);
500 fprintf(stderr,
"Unregistered API message: %d\n", msg_id);
508 fprintf(stderr,
"Read failed with %d\n", rv);
534 vac_client_index (
void)
549 if (!mp)
return (-1);
552 mp->client_index = vac_client_index();
556 fprintf(stderr,
"vpe_api_write fails: %d\n", rv);
577 if (hp->
value[0] > max)
bool timeout_thread_cancelled
int vac_get_msg_index(unsigned char *name)
int svm_queue_add(svm_queue_t *q, u8 *elem, int nowait)
pthread_t timeout_thread_handle
int my_client_index
All VLIB-side message handlers use my_client_index to identify the queue / client.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void set_timeout(unsigned short timeout)
static mheap_t * mheap_header(u8 *v)
pthread_t rx_thread_handle
int vac_msg_table_max_index(void)
void vlib_cli_output(struct vlib_main_t *vm, char *fmt,...)
int vac_write(char *p, int l)
void clib_error_register_handler(clib_error_handler_func_t func, void *arg)
#define MHEAP_FLAG_THREAD_SAFE
svm_queue_t * vl_input_queue
Peer input queue pointer.
void * vl_msg_api_alloc(int nbytes)
void vl_client_api_unmap(void)
int our_pid
Current process PID.
pthread_cond_t timeout_cancel_cv
int svm_queue_sub(svm_queue_t *q, u8 *elem, svm_q_conditional_wait_t cond, u32 time)
pthread_mutex_t queue_lock
static void vac_client_constructor(void)
vlib_main_t ** vlib_mains
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
void vac_rx_suspend(void)
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
vac_callback_t vac_callback
static void unset_timeout(void)
vlib_main_t vlib_global_main
u8 * format_mheap(u8 *s, va_list *va)
int vac_connect(char *name, char *chroot_prefix, vac_callback_t cb, int rx_qlen)
void vl_set_memory_root_path(const char *name)
void(* vac_error_callback_t)(void *, unsigned char *, int)
int vl_client_connect(const char *name, int ctx_quota, int input_queue_size)
static void vac_client_destructor(void)
static void * clib_mem_get_per_cpu_heap(void)
static void cleanup(void)
static void * vac_timeout_thread_fn(void *arg)
API main structure, used by both vpp and binary API clients.
void * clib_mem_init(void *heap, uword size)
#define clib_warning(format, args...)
u32 vl_msg_api_get_msg_index(u8 *name_and_crc)
int vl_client_api_map(const char *region_name)
pthread_cond_t suspend_cv
static uword * vac_msg_table_get_hash(void)
blocking call - best used in combination with condvars, for eventfds we don't yield the cpu ...
svm_queue_t * vl_input_queue
static void * clib_mem_get_heap(void)
static uword hash_elts(void *v)
u32 data_len
message length not including header
Message header structure.
int vac_read(char **p, int *l, u16 timeout)
pthread_cond_t terminate_cv
void vl_msg_api_free(void *)
pthread_cond_t timeout_cv
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
int vl_client_disconnect(void)
void vac_set_error_handler(vac_error_callback_t cb)
int vac_msg_table_size(void)
struct _svm_queue svm_queue_t
void(* vac_callback_t)(unsigned char *data, int len)
pthread_mutex_t timeout_lock
static void vac_api_handler(void *msg)
void clib_mem_trace(int enable)
uword * msg_index_by_name_and_crc
client message index hash table
typedef VL_API_PACKED(struct _vl_api_header { u16 _vl_msg_id;u32 client_index;})
static void * vac_rx_thread_fn(void *arg)