19 #include <sys/types.h> 20 #include <sys/socket.h> 23 #include <netinet/in.h> 135 clib_warning(
"Message ID %d has wrong length: %d\n",
id, l);
148 vl_api_memclnt_keepalive_reply_t *rmp;
162 case VL_API_RX_THREAD_EXIT:
166 rx_thread_done =
true;
173 case VL_API_MEMCLNT_RX_THREAD_SUSPEND:
183 case VL_API_MEMCLNT_READ_TIMEOUT:
184 clib_warning(
"Received read timeout in async thread\n");
188 case VL_API_MEMCLNT_KEEPALIVE:
192 rmp->_vl_msg_id =
ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY);
219 while (!timeout_in_progress)
223 gettimeofday(&tv, NULL);
227 if (!timeout_cancelled) {
230 if (rv == ETIMEDOUT && !timeout_thread_cancelled) {
232 ep->_vl_msg_id =
ntohs(VL_API_MEMCLNT_READ_TIMEOUT);
254 ep->_vl_msg_id =
ntohs(VL_API_MEMCLNT_RX_THREAD_SUSPEND);
258 rx_is_running =
false;
269 if (rx_is_running)
goto unlock;
271 rx_is_running =
true;
294 rx_thread_done =
false;
300 if (chroot_prefix != NULL)
322 rx_is_running =
true;
343 read_timeout = timeout;
344 timeout_in_progress =
true;
345 timeout_cancelled =
false;
355 timeout_in_progress =
false;
356 timeout_cancelled =
true;
374 ep->_vl_msg_id =
ntohs(VL_API_RX_THREAD_EXIT);
380 gettimeofday(&tv, NULL);
381 ts.tv_sec = tv.tv_sec + 5;
385 if (rx_thread_done ==
false)
398 timeout_thread_cancelled =
true;
419 vl_api_memclnt_keepalive_reply_t *rmp;
431 if (am->
our_pid == 0)
return (-4);
446 case VL_API_RX_THREAD_EXIT:
449 case VL_API_MEMCLNT_RX_THREAD_SUSPEND:
451 case VL_API_MEMCLNT_READ_TIMEOUT:
453 case VL_API_MEMCLNT_KEEPALIVE:
458 rmp->_vl_msg_id =
ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY);
473 fprintf(stderr,
"Unregistered API message: %d\n", msg_id);
481 fprintf(stderr,
"Read failed with %d\n", rv);
507 vac_client_index (
void)
522 if (!mp)
return (-1);
525 mp->client_index = vac_client_index();
529 fprintf(stderr,
"vpe_api_write fails: %d\n", rv);
550 if (hp->
value[0] > max)
576 mem_initialized =
true;
bool timeout_thread_cancelled
int svm_queue_add(svm_queue_t *q, u8 *elem, int nowait)
void vac_mem_init(size_t size)
int vac_get_msg_index(char *name)
void * clib_mem_init(void *base, uword size)
pthread_t timeout_thread_handle
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void set_timeout(unsigned short timeout)
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)
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
vlib_main_t ** vlib_mains
__clib_export void clib_error_register_handler(clib_error_handler_func_t func, void *arg)
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
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 cleanup(void)
static void * vac_timeout_thread_fn(void *arg)
API main structure, used by both vpp and binary API clients.
#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 clib_mem_heap_t * 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 api_main_t * vlibapi_get_main(void)
static void vac_api_handler(void *msg)
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 CLIB_NOSANITIZE_ADDR void VL_MSG_API_UNPOISON(const void *a)
static void * vac_rx_thread_fn(void *arg)