X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlibapi%2Fapi_shared.c;h=28e9f481650e903a34123d522df0d4ab4f33dfc8;hb=54582663ab7d7105bc2407036a311d68707e5ab9;hp=a553a5b5b957304119853cf4d84946d757880e99;hpb=39d69112fcec114fde34955ceb41555221d3ba11;p=vpp.git diff --git a/src/vlibapi/api_shared.c b/src/vlibapi/api_shared.c index a553a5b5b95..28e9f481650 100644 --- a/src/vlibapi/api_shared.c +++ b/src/vlibapi/api_shared.c @@ -1063,31 +1063,47 @@ vl_msg_api_get_msg_index (u8 * name_and_crc) return ~0; } +void * +vl_msg_push_heap_w_region (svm_region_t * vlib_rp) +{ + pthread_mutex_lock (&vlib_rp->mutex); + return svm_push_data_heap (vlib_rp); +} + void * vl_msg_push_heap (void) { api_main_t *am = vlibapi_get_main (); - pthread_mutex_lock (&am->vlib_rp->mutex); - return svm_push_data_heap (am->vlib_rp); + return vl_msg_push_heap_w_region (am->vlib_rp); +} + +void +vl_msg_pop_heap_w_region (svm_region_t * vlib_rp, void *oldheap) +{ + svm_pop_heap (oldheap); + pthread_mutex_unlock (&vlib_rp->mutex); } void vl_msg_pop_heap (void *oldheap) { api_main_t *am = vlibapi_get_main (); - svm_pop_heap (oldheap); - pthread_mutex_unlock (&am->vlib_rp->mutex); + vl_msg_pop_heap_w_region (am->vlib_rp, oldheap); } +/* Must be nul terminated */ int -vl_api_to_api_string (u32 len, const char *buf, vl_api_string_t * str) +vl_api_c_string_to_api_string (const char *buf, vl_api_string_t * str) { - if (len) + /* copy without nul terminator */ + u32 len = strlen (buf); + if (len > 0) clib_memcpy_fast (str->buf, buf, len); str->length = htonl (len); return len + sizeof (u32); } +/* Must NOT be nul terminated */ int vl_api_vec_to_api_string (const u8 * vec, vl_api_string_t * str) { @@ -1097,13 +1113,6 @@ vl_api_vec_to_api_string (const u8 * vec, vl_api_string_t * str) return len + sizeof (u32); } -/* Return a pointer to the API string (not nul terminated */ -u8 * -vl_api_from_api_string (vl_api_string_t * astr) -{ - return astr->buf; -} - u32 vl_api_string_len (vl_api_string_t * astr) { @@ -1120,15 +1129,32 @@ vl_api_format_string (u8 * s, va_list * args) /* * Returns a new vector. Remember to free it after use. + * NOT nul terminated. */ u8 * -vl_api_from_api_to_vec (vl_api_string_t * astr) +vl_api_from_api_to_new_vec (vl_api_string_t * astr) { u8 *v = 0; vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length)); return v; } +/* + * Returns a new vector. Remember to free it after use. + * Nul terminated. + */ +char * +vl_api_from_api_to_new_c_string (vl_api_string_t * astr) +{ + char *v = 0; + if (clib_net_to_host_u32 (astr->length) > 0) + { + vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length)); + vec_add1 (v, 0); + } + return v; +} + void vl_api_set_elog_main (elog_main_t * m) {