18 #include <sys/types.h> 19 #include <sys/socket.h> 22 #include <netinet/in.h> 79 memset(pm, 0,
sizeof(*pm));
100 memset (pm, 0,
sizeof (*pm));
120 u16 id = ntohs(*((
u16 *)msg));
124 clib_warning(
"Message ID %d has wrong length: %d\n",
id, l);
137 vl_api_memclnt_keepalive_reply_t *rmp;
148 u16 id = ntohs(*((
u16 *)msg));
150 case VL_API_RX_THREAD_EXIT:
160 case VL_API_MEMCLNT_RX_THREAD_SUSPEND:
170 case VL_API_MEMCLNT_READ_TIMEOUT:
171 clib_warning(
"Received read timeout in async thread\n");
175 case VL_API_MEMCLNT_KEEPALIVE:
178 memset (rmp, 0,
sizeof (*rmp));
179 rmp->_vl_msg_id = ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY);
209 gettimeofday(&tv,
NULL);
210 ts.tv_sec = tv.tv_sec + timeout;
218 ep->_vl_msg_id = ntohs(VL_API_MEMCLNT_READ_TIMEOUT);
237 ep->_vl_msg_id = ntohs(VL_API_MEMCLNT_RX_THREAD_SUSPEND);
241 rx_is_running =
false;
252 if (rx_is_running)
goto unlock;
254 rx_is_running =
true;
281 if (chroot_prefix !=
NULL)
303 rx_is_running =
true;
332 ep->_vl_msg_id = ntohs(VL_API_RX_THREAD_EXIT);
338 gettimeofday(&tv,
NULL);
339 ts.tv_sec = tv.tv_sec + 5;
367 read_timeout = timeout;
388 vl_api_memclnt_keepalive_reply_t *rmp;
398 if (am->
our_pid == 0)
return (-1);
409 u16 msg_id = ntohs(*((
u16 *)msg));
411 case VL_API_RX_THREAD_EXIT:
412 printf(
"Received thread exit\n");
414 case VL_API_MEMCLNT_RX_THREAD_SUSPEND:
415 printf(
"Received thread suspend\n");
417 case VL_API_MEMCLNT_READ_TIMEOUT:
418 printf(
"Received read timeout %ds\n", timeout);
420 case VL_API_MEMCLNT_KEEPALIVE:
424 memset (rmp, 0,
sizeof (*rmp));
425 rmp->_vl_msg_id = ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY);
440 printf(
"Unregistered API message: %d\n", msg_id);
450 printf(
"Read failed with %d\n", rv);
470 vac_client_index (
void)
485 if (!mp)
return (-1);
488 mp->client_index = vac_client_index();
513 if (hp->
value[0] > max)
int vac_get_msg_index(unsigned char *name)
void vl_client_disconnect(void)
pthread_t timeout_thread_handle
unix_shared_memory_queue_t * vl_input_queue
int my_client_index
All VLIB-side message handlers use my_client_index to identify the queue / client.
typedef VL_API_PACKED(struct _vl_api_header{u16 _vl_msg_id;u32 client_index;})
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)
void clib_error_register_handler(clib_error_handler_func_t func, void *arg)
unix_shared_memory_queue_t * vl_input_queue
Peer input queue pointer.
int our_pid
Current process PID.
pthread_cond_t timeout_cancel_cv
int vl_client_connect(const char *name, int ctx_quota, int input_queue_size)
pthread_mutex_t queue_lock
vlib_main_t ** vlib_mains
void vl_client_api_unmap(void)
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
void vac_rx_suspend(void)
void * vl_msg_api_alloc(int nbytes)
u32 vl_api_get_msg_index(u8 *name_and_crc)
vac_callback_t vac_callback
static void unset_timeout(void)
vlib_main_t vlib_global_main
vl_shmem_hdr_t * shmem_hdr
int unix_shared_memory_queue_add(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
int vac_connect(char *name, char *chroot_prefix, vac_callback_t cb, int rx_qlen)
void(* vac_error_callback_t)(void *, unsigned char *, int)
void vl_msg_api_free(void *)
static void cleanup(void)
static void * vac_timeout_thread_fn(void *arg)
API main structure, used by both vpp and binary API clients.
int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
#define clib_warning(format, args...)
pthread_cond_t suspend_cv
static uword * vac_msg_table_get_hash(void)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
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
pthread_cond_t timeout_cv
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
void vac_set_error_handler(vac_error_callback_t cb)
int vac_msg_table_size(void)
void(* vac_callback_t)(unsigned char *data, int len)
pthread_mutex_t timeout_lock
static void vac_api_handler(void *msg)
int vl_client_api_map(const char *region_name)
void vl_set_memory_root_path(const char *root_path)
uword * msg_index_by_name_and_crc
client message index hash table
struct _unix_shared_memory_queue unix_shared_memory_queue_t
static void * vac_rx_thread_fn(void *arg)