fd-io-styleify pass

Change-Id: I72d0dff064162d11321257c858f68da1ba79ea48
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Dave Barach
2016-07-08 09:38:52 -04:00
committed by Damjan Marion
parent 9b8ffd99fb
commit 371e4e19d1
17 changed files with 4012 additions and 3426 deletions

View File

@ -26,7 +26,8 @@
#include <vlibmemory/unix_shared_memory_queue.h>
#include <vlib/unix/unix.h>
typedef enum {
typedef enum
{
REGISTRATION_TYPE_FREE = 0,
REGISTRATION_TYPE_SHMEM,
REGISTRATION_TYPE_SOCKET_LISTEN,
@ -34,7 +35,8 @@ typedef enum {
REGISTRATION_TYPE_SOCKET_CLIENT,
} vl_registration_type_t;
typedef struct vl_api_registration_ {
typedef struct vl_api_registration_
{
vl_registration_type_t registration_type;
/* Index in VLIB's brain (not shared memory). */
@ -64,7 +66,8 @@ typedef struct vl_api_registration_ {
/* Trace configuration for a single message */
typedef struct {
typedef struct
{
int size;
int trace_enable;
int replay_enable;
@ -73,7 +76,8 @@ typedef struct {
/*
* API recording
*/
typedef struct {
typedef struct
{
u8 endian;
u8 enabled;
u8 wrapped;
@ -83,13 +87,14 @@ typedef struct {
u8 **traces;
} vl_api_trace_t;
typedef CLIB_PACKED (struct {
u8 endian;
u8 wrapped;
typedef CLIB_PACKED (struct
{
u8 endian; u8 wrapped;
u32 nitems;
}) vl_api_trace_file_header_t;
typedef enum {
typedef enum
{
VL_API_TRACE_TX,
VL_API_TRACE_RX,
} vl_api_trace_which_t;
@ -97,13 +102,15 @@ typedef enum {
#define VL_API_LITTLE_ENDIAN 0x00
#define VL_API_BIG_ENDIAN 0x01
typedef struct {
typedef struct
{
u8 *name;
u16 first_msg_id;
u16 last_msg_id;
} vl_api_msg_range_t;
typedef struct {
typedef struct
{
void (**msg_handlers) (void *);
int (**pd_msg_handlers) (void *, int);
void (**msg_cleanup_handlers) (void *);
@ -161,7 +168,8 @@ typedef struct {
api_main_t api_main;
typedef struct {
typedef struct
{
int id;
char *name;
void *handler;
@ -200,8 +208,7 @@ void vl_msg_api_set_handlers(int msg_id, char *msg_name,
void *handler,
void *cleanup,
void *endian,
void *print,
int msg_size, int traced);
void *print, int msg_size, int traced);
void vl_msg_api_config (vl_msg_api_msg_config_t *);
void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q);
@ -213,7 +220,8 @@ void vl_noop_handler (void *mp);
clib_error_t *vl_api_init (vlib_main_t * vm);
void vl_msg_api_increment_missing_client_counter (void);
void vl_msg_api_post_mortem_dump (void);
void vl_msg_api_register_pd_handler (void *handler, u16 msg_id_host_byte_order);
void vl_msg_api_register_pd_handler (void *handler,
u16 msg_id_host_byte_order);
int vl_msg_api_pd_handler (void *mp, int rv);
void vl_msg_api_set_first_available_msg_id (u16 first_avail);
@ -228,3 +236,11 @@ vlib_node_t ** vlib_node_unserialize (u8 * vector);
#define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
#endif /* included_api_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -31,14 +31,14 @@ _(STATE_POLLING, "polling") \
_(STATE_INTERRUPT_WAIT, "interrupt wait") \
_(STATE_INTERNAL, "internal")
typedef enum {
typedef enum
{
#define _(a,b) a,
foreach_state_string_code
#undef _
} state_string_enum_t;
static char *state_strings[] =
{
static char *state_strings[] = {
#define _(a,b) b,
foreach_state_string_code
#undef _
@ -51,9 +51,9 @@ static char *state_strings[] =
* Switch heaps before/after to serialize into API client shared memory.
*/
u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
u32 max_threads, int include_nexts,
int include_stats)
u8 *
vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
u32 max_threads, int include_nexts, int include_stats)
{
serialize_main_t _sm, *sm = &_sm;
vlib_main_t *vm = vlib_get_main ();
@ -132,8 +132,7 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
l = n->stats_total.clocks - n->stats_last_clear.clocks;
v = n->stats_total.vectors - n->stats_last_clear.vectors;
c = n->stats_total.calls - n->stats_last_clear.calls;
d = n->stats_total.suspends
- n->stats_last_clear.suspends;
d = n->stats_total.suspends - n->stats_last_clear.suspends;
state_code = STATE_INTERNAL;
@ -158,9 +157,9 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
state_code = STATE_EVENT_WAIT;
break;
case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT
| VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK):
state_code = STATE_ANY_WAIT;
case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK):
state_code =
STATE_ANY_WAIT;
break;
}
}
@ -187,7 +186,8 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
serialize_likely_small_unsigned_integer
(sm, vec_len (n->next_nodes));
for (k = 0; k < vec_len (n->next_nodes); k++)
serialize_likely_small_unsigned_integer (sm, n->next_nodes[k]);
serialize_likely_small_unsigned_integer (sm,
n->next_nodes[k]);
}
else
serialize_likely_small_unsigned_integer (sm, 0);
@ -213,7 +213,8 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
return (serialize_close_vector (sm));
}
vlib_node_t *** vlib_node_unserialize (u8 * vector)
vlib_node_t ***
vlib_node_unserialize (u8 * vector)
{
serialize_main_t _sm, *sm = &_sm;
u32 nnodes, nnexts;
@ -251,8 +252,7 @@ vlib_node_t *** vlib_node_unserialize (u8 * vector)
state_code = unserialize_likely_small_unsigned_integer (sm);
node->state_string = (u8 *) state_strings[state_code];
node->type =
unserialize_likely_small_unsigned_integer (sm);
node->type = unserialize_likely_small_unsigned_integer (sm);
nnexts = unserialize_likely_small_unsigned_integer (sm);
if (nnexts > 0)
vec_validate (node->next_nodes, nnexts - 1);
@ -351,8 +351,7 @@ test_node_serialize_command_fn (vlib_main_t * vm,
" %lld vectors %lld",
node->stats_total.clocks,
node->stats_total.calls,
node->stats_total.suspends,
node->stats_total.vectors);
node->stats_total.suspends, node->stats_total.vectors);
for (k = 0; k < vec_len (node->next_nodes); k++)
{
@ -380,9 +379,19 @@ test_node_serialize_command_fn (vlib_main_t * vm,
return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (test_node_serialize_node, static) = {
.path = "test node serialize",
.short_help = "test node serialize [max-threads NN] nexts stats",
.function = test_node_serialize_command_fn,
};
/* *INDENT-ON* */
#endif
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -38,7 +38,8 @@
*
* No locks, no hits, no errors...
*/
typedef struct ring_alloc_ {
typedef struct ring_alloc_
{
unix_shared_memory_queue_t *rp;
u16 size;
u16 nitems;
@ -61,7 +62,8 @@ _(1024+8, 1024) \
_(2048+8, 128) \
_(4096+8, 8)
typedef struct vl_shmem_hdr_ {
typedef struct vl_shmem_hdr_
{
int version;
/* getpid () for the VLIB client process */
@ -87,7 +89,8 @@ typedef struct vl_shmem_hdr_ {
} vl_shmem_hdr_t;
/* Note that the size of the structure is 16 bytes, with 4 bytes of padding after data[0]. */
typedef struct msgbuf_ {
typedef struct msgbuf_
{
unix_shared_memory_queue_t *q;
u32 data_len;
u8 data[0];
@ -98,16 +101,20 @@ typedef struct msgbuf_ {
#define VL_API_EPOCH_MASK 0xFF
#define VL_API_EPOCH_SHIFT 8
static inline u32 vl_msg_api_handle_get_epoch (u32 index)
static inline u32
vl_msg_api_handle_get_epoch (u32 index)
{
return (index & VL_API_EPOCH_MASK);
}
static inline u32 vl_msg_api_handle_get_index (u32 index)
static inline u32
vl_msg_api_handle_get_index (u32 index)
{
return (index >> VL_API_EPOCH_SHIFT);
}
static inline u32 vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch)
static inline u32
vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch)
{
u32 handle;
ASSERT (index < 0x00FFFFFF);
@ -139,10 +146,19 @@ void vl_enable_disable_memory_api (vlib_main_t *vm, int yesno);
void vl_client_disconnect_from_vlib (void);
int vl_client_connect_to_vlib (char *svm_name, char *client_name,
int rx_queue_size);
int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name,
int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name,
char *client_name,
int rx_queue_size);
u16 vl_client_get_first_plugin_msg_id (char *plugin_name);
void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
#endif /* included_vlibmemory_api_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -61,7 +61,8 @@
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_printfun
typedef struct {
typedef struct
{
u8 rx_thread_jmpbuf_valid;
u8 connected_to_vlib;
jmp_buf rx_thread_jmpbuf;
@ -73,7 +74,8 @@ typedef struct {
memory_client_main_t memory_client_main;
static void *rx_thread_fn(void *arg)
static void *
rx_thread_fn (void *arg)
{
unix_shared_memory_queue_t *q;
memory_client_main_t *mm = &memory_client_main;
@ -82,37 +84,42 @@ static void *rx_thread_fn(void *arg)
q = am->vl_input_queue;
/* So we can make the rx thread terminate cleanly */
if (setjmp(mm->rx_thread_jmpbuf) == 0) {
if (setjmp (mm->rx_thread_jmpbuf) == 0)
{
mm->rx_thread_jmpbuf_valid = 1;
while (1) {
while (1)
{
vl_msg_api_queue_handler (q);
}
}
pthread_exit (0);
}
static void vl_api_rx_thread_exit_t_handler (
vl_api_rx_thread_exit_t *mp)
static void
vl_api_rx_thread_exit_t_handler (vl_api_rx_thread_exit_t * mp)
{
memory_client_main_t *mm = &memory_client_main;
vl_msg_api_free (mp);
longjmp (mm->rx_thread_jmpbuf, 1);
}
static void noop_handler (void *notused)
static void
noop_handler (void *notused)
{
}
#define foreach_api_msg \
_(RX_THREAD_EXIT, rx_thread_exit)
static int connect_to_vlib_internal (char *svm_name, char *client_name,
static int
connect_to_vlib_internal (char *svm_name, char *client_name,
int rx_queue_size, int want_pthread)
{
int rv = 0;
memory_client_main_t *mm = &memory_client_main;
if ((rv = vl_client_api_map(svm_name))) {
if ((rv = vl_client_api_map (svm_name)))
{
clib_warning ("vl_client_api map rv %d", rv);
return rv;
}
@ -128,14 +135,16 @@ static int connect_to_vlib_internal (char *svm_name, char *client_name,
#undef _
if (vl_client_connect (client_name, 0 /* punt quota */ ,
rx_queue_size /* input queue */) < 0) {
rx_queue_size /* input queue */ ) < 0)
{
vl_client_api_unmap ();
return -1;
}
/* Start the rx queue thread */
if (want_pthread) {
if (want_pthread)
{
rv = pthread_create (&mm->rx_thread_handle,
NULL /*attr */ , rx_thread_fn, 0);
if (rv)
@ -146,34 +155,39 @@ static int connect_to_vlib_internal (char *svm_name, char *client_name,
return 0;
}
int vl_client_connect_to_vlib(char *svm_name, char *client_name,
int
vl_client_connect_to_vlib (char *svm_name, char *client_name,
int rx_queue_size)
{
return connect_to_vlib_internal (svm_name, client_name, rx_queue_size,
1 /* want pthread */ );
}
int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name,
int
vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name,
int rx_queue_size)
{
return connect_to_vlib_internal (svm_name, client_name, rx_queue_size,
0 /* want pthread */ );
}
void vl_client_disconnect_from_vlib (void)
void
vl_client_disconnect_from_vlib (void)
{
memory_client_main_t *mm = &memory_client_main;
api_main_t *am = &api_main;
uword junk;
if (mm->rx_thread_jmpbuf_valid) {
if (mm->rx_thread_jmpbuf_valid)
{
vl_api_rx_thread_exit_t *ep;
ep = vl_msg_api_alloc (sizeof (*ep));
ep->_vl_msg_id = ntohs (VL_API_RX_THREAD_EXIT);
vl_msg_api_send_shmem (am->vl_input_queue, (u8 *) & ep);
pthread_join (mm->rx_thread_handle, (void **) &junk);
}
if (mm->connected_to_vlib) {
if (mm->connected_to_vlib)
{
vl_client_disconnect ();
vl_client_api_unmap ();
}
@ -190,7 +204,8 @@ static void vl_api_get_first_msg_id_reply_t_handler
mm->first_msg_id_reply_ready = 1;
}
u16 vl_client_get_first_plugin_msg_id (char * plugin_name)
u16
vl_client_get_first_plugin_msg_id (char *plugin_name)
{
vl_api_get_first_msg_id_t *mp;
api_main_t *am = &api_main;
@ -223,11 +238,14 @@ u16 vl_client_get_first_plugin_msg_id (char * plugin_name)
vl_msg_api_send_shmem (am->shmem_hdr->vl_input_queue, (u8 *) & mp);
/* Synchronously wait for the answer */
do {
do
{
timeout = clib_time_now (&clib_time) + 1.0;
while (clib_time_now (&clib_time) < timeout) {
if (mm->first_msg_id_reply_ready == 1) {
while (clib_time_now (&clib_time) < timeout)
{
if (mm->first_msg_id_reply_ready == 1)
{
rv = mm->first_msg_id_reply;
goto result;
}
@ -236,7 +254,8 @@ u16 vl_client_get_first_plugin_msg_id (char * plugin_name)
am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler;
return rv;
} while(0);
}
while (0);
result:
@ -249,5 +268,16 @@ result:
return rv;
}
void vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n)
{ clib_warning ("STUB called..."); }
void
vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n)
{
clib_warning ("STUB called...");
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -96,24 +96,28 @@ unix_shared_memory_queue_init(int nels,
/*
* unix_shared_memory_queue_free
*/
void unix_shared_memory_queue_free(unix_shared_memory_queue_t *q)
void
unix_shared_memory_queue_free (unix_shared_memory_queue_t * q)
{
(void) pthread_mutex_destroy (&q->mutex);
(void) pthread_cond_destroy (&q->condvar);
clib_mem_free (q);
}
void unix_shared_memory_queue_lock (unix_shared_memory_queue_t *q)
void
unix_shared_memory_queue_lock (unix_shared_memory_queue_t * q)
{
pthread_mutex_lock (&q->mutex);
}
void unix_shared_memory_queue_unlock (unix_shared_memory_queue_t *q)
void
unix_shared_memory_queue_unlock (unix_shared_memory_queue_t * q)
{
pthread_mutex_unlock (&q->mutex);
}
int unix_shared_memory_queue_is_full (unix_shared_memory_queue_t *q)
int
unix_shared_memory_queue_is_full (unix_shared_memory_queue_t * q)
{
return q->cursize == q->maxsize;
}
@ -121,14 +125,17 @@ int unix_shared_memory_queue_is_full (unix_shared_memory_queue_t *q)
/*
* unix_shared_memory_queue_add_nolock
*/
int unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t *q,
int
unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t * q,
u8 * elem)
{
i8 *tailp;
int need_broadcast = 0;
if (PREDICT_FALSE(q->cursize == q->maxsize)) {
while(q->cursize == q->maxsize) {
if (PREDICT_FALSE (q->cursize == q->maxsize))
{
while (q->cursize == q->maxsize)
{
(void) pthread_cond_wait (&q->condvar, &q->mutex);
}
}
@ -144,7 +151,8 @@ int unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t *q,
if (q->tail == q->maxsize)
q->tail = 0;
if (need_broadcast) {
if (need_broadcast)
{
(void) pthread_cond_broadcast (&q->condvar);
if (q->signal_when_queue_non_empty)
kill (q->consumer_pid, q->signal_when_queue_non_empty);
@ -152,12 +160,13 @@ int unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t *q,
return 0;
}
int unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t *q,
u8 *elem)
int
unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t * q, u8 * elem)
{
i8 *tailp;
if (PREDICT_FALSE(q->cursize == q->maxsize)) {
if (PREDICT_FALSE (q->cursize == q->maxsize))
{
while (q->cursize == q->maxsize)
;
}
@ -177,26 +186,33 @@ int unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t *q,
/*
* unix_shared_memory_queue_add
*/
int unix_shared_memory_queue_add (unix_shared_memory_queue_t *q,
int
unix_shared_memory_queue_add (unix_shared_memory_queue_t * q,
u8 * elem, int nowait)
{
i8 *tailp;
int need_broadcast = 0;
if (nowait) {
if (nowait)
{
/* zero on success */
if (pthread_mutex_trylock (&q->mutex)) {
if (pthread_mutex_trylock (&q->mutex))
{
return (-1);
}
} else
}
else
pthread_mutex_lock (&q->mutex);
if (PREDICT_FALSE(q->cursize == q->maxsize)) {
if (nowait) {
if (PREDICT_FALSE (q->cursize == q->maxsize))
{
if (nowait)
{
pthread_mutex_unlock (&q->mutex);
return (-2);
}
while(q->cursize == q->maxsize) {
while (q->cursize == q->maxsize)
{
(void) pthread_cond_wait (&q->condvar, &q->mutex);
}
}
@ -212,7 +228,8 @@ int unix_shared_memory_queue_add (unix_shared_memory_queue_t *q,
if (q->tail == q->maxsize)
q->tail = 0;
if (need_broadcast) {
if (need_broadcast)
{
(void) pthread_cond_broadcast (&q->condvar);
if (q->signal_when_queue_non_empty)
kill (q->consumer_pid, q->signal_when_queue_non_empty);
@ -225,26 +242,33 @@ int unix_shared_memory_queue_add (unix_shared_memory_queue_t *q,
/*
* unix_shared_memory_queue_sub
*/
int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q,
int
unix_shared_memory_queue_sub (unix_shared_memory_queue_t * q,
u8 * elem, int nowait)
{
i8 *headp;
int need_broadcast = 0;
if (nowait) {
if (nowait)
{
/* zero on success */
if (pthread_mutex_trylock (&q->mutex)) {
if (pthread_mutex_trylock (&q->mutex))
{
return (-1);
}
} else
}
else
pthread_mutex_lock (&q->mutex);
if (PREDICT_FALSE(q->cursize == 0)) {
if (nowait) {
if (PREDICT_FALSE (q->cursize == 0))
{
if (nowait)
{
pthread_mutex_unlock (&q->mutex);
return (-2);
}
while (q->cursize == 0) {
while (q->cursize == 0)
{
(void) pthread_cond_wait (&q->condvar, &q->mutex);
}
}
@ -269,12 +293,13 @@ int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q,
return 0;
}
int unix_shared_memory_queue_sub_raw (unix_shared_memory_queue_t *q,
u8 *elem)
int
unix_shared_memory_queue_sub_raw (unix_shared_memory_queue_t * q, u8 * elem)
{
i8 *headp;
if (PREDICT_FALSE(q->cursize == 0)) {
if (PREDICT_FALSE (q->cursize == 0))
{
while (q->cursize == 0)
;
}
@ -289,3 +314,11 @@ int unix_shared_memory_queue_sub_raw (unix_shared_memory_queue_t *q,
q->head = 0;
return 0;
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -23,7 +23,8 @@
#include <pthread.h>
#include <vppinfra/mem.h>
typedef struct _unix_shared_memory_queue {
typedef struct _unix_shared_memory_queue
{
pthread_mutex_t mutex; /* 8 bytes */
pthread_cond_t condvar; /* 8 bytes */
int head;
@ -36,11 +37,11 @@ typedef struct _unix_shared_memory_queue {
char data[0];
} unix_shared_memory_queue_t;
unix_shared_memory_queue_t *
unix_shared_memory_queue_init(int nels,
unix_shared_memory_queue_t *unix_shared_memory_queue_init (int nels,
int elsize,
int consumer_pid,
int signal_when_queue_non_empty);
int
signal_when_queue_non_empty);
void unix_shared_memory_queue_free (unix_shared_memory_queue_t * q);
int unix_shared_memory_queue_add (unix_shared_memory_queue_t * q,
u8 * elem, int nowait);
@ -58,3 +59,11 @@ int unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t *q,
u8 * elem);
#endif /* included_unix_shared_memory_queue_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -23,3 +23,11 @@
*/
#include <vlibmemory/memclnt.api.h>
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -24,10 +24,19 @@
#include <vppinfra/byte_order.h>
#define vl_msg_id(n,h) n,
typedef enum {
typedef enum
{
VL_ILLEGAL_MESSAGE_ID = 0,
#include <vlibmemory/vl_memory_api_h.h>
} vl_msg_id_t;
#undef vl_msg_id
#endif /* __VL_MSG_ENUM_H__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -22,7 +22,8 @@
#include <vlibapi/api.h>
typedef struct {
typedef struct
{
/* Server port number */
int portno;
@ -59,8 +60,7 @@ void vl_socket_process_msg (struct unix_file *uf,
clib_error_t *vl_socket_read_ready (struct unix_file *uf);
void vl_socket_add_pending_output (struct unix_file *uf,
struct vl_api_registration_ *rp,
u8 * buffer,
uword buffer_bytes);
u8 * buffer, uword buffer_bytes);
clib_error_t *vl_socket_write_ready (struct unix_file *uf);
void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem);
void vl_socket_api_send_with_data (vl_api_registration_t * rp,
@ -77,3 +77,11 @@ void socksvr_set_port (u16 port);
void socksvr_set_bind_address (u32 bind_address);
#endif /* included_vlibsocket_api_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -36,39 +36,38 @@ typedef unsigned long uword;
#define VL_API_PACKED(x) x __attribute__ ((packed))
typedef VL_API_PACKED(struct _vl_api_sockclnt_create {
u16 _vl_msg_id;
u8 name[64];
typedef VL_API_PACKED (struct _vl_api_sockclnt_create
{
u16 _vl_msg_id; u8 name[64];
u32 context;
}) vl_api_sockclnt_create_t;
typedef VL_API_PACKED(struct _vl_api_sockclnt_create_reply {
typedef VL_API_PACKED (struct _vl_api_sockclnt_create_reply
{
u16 _vl_msg_id;
i32 response;
u64 handle;
u32 index;
u32 context;
i32 response; u64 handle; u32 index; u32 context;
}) vl_api_sockclnt_create_reply_t;
typedef VL_API_PACKED(struct _vl_api_sockclnt_delete {
u16 _vl_msg_id;
u32 index;
typedef VL_API_PACKED (struct _vl_api_sockclnt_delete
{
u16 _vl_msg_id; u32 index;
u64 handle;
}) vl_api_sockclnt_delete_t;
typedef VL_API_PACKED(struct _vl_api_sockclnt_delete_reply {
u16 _vl_msg_id;
i32 response;
u64 handle;
typedef VL_API_PACKED (struct _vl_api_sockclnt_delete_reply
{
u16 _vl_msg_id; i32 response; u64 handle;
}) vl_api_sockclnt_delete_reply_t;
void error(char *msg)
void
error (char *msg)
{
perror (msg);
exit (0);
}
int main(int argc, char *argv[])
int
main (int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
@ -81,21 +80,22 @@ int main(int argc, char *argv[])
char *rdptr;
int total_bytes;
for (i = 0; i < 1; i++) {
for (i = 0; i < 1; i++)
{
portno = SOCKCLNT_SERVER_PORT;
sockfd = socket (AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error ("ERROR opening socket");
server = gethostbyname ("localhost");
if (server == NULL) {
if (server == NULL)
{
fprintf (stderr, "ERROR, no such host\n");
exit (0);
}
bzero ((char *) &serv_addr, sizeof (serv_addr));
serv_addr.sin_family = AF_INET;
bcopy ((char *) server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
(char *) &serv_addr.sin_addr.s_addr, server->h_length);
serv_addr.sin_port = htons (portno);
if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
error ("ERROR connecting");
@ -121,18 +121,21 @@ int main(int argc, char *argv[])
total_bytes = 0;
rdptr = buffer;
do {
do
{
n = read (sockfd, rdptr, sizeof (buffer) - (rdptr - buffer));
if (n < 0)
error ("ERROR reading from socket");
printf ("read %d bytes\n", n);
total_bytes += n;
rdptr += n;
} while (total_bytes < sizeof (vl_api_sockclnt_create_reply_t) + 4);
}
while (total_bytes < sizeof (vl_api_sockclnt_create_reply_t) + 4);
rp = (vl_api_sockclnt_create_reply_t *) (buffer + 4);
/* VL_API_SOCKCLNT_CREATE_REPLY */
if (ntohs(rp->_vl_msg_id) != 9) {
if (ntohs (rp->_vl_msg_id) != 9)
{
printf ("WARNING: msg id %d\n", ntohs (rp->_vl_msg_id));
}
@ -142,3 +145,11 @@ int main(int argc, char *argv[])
}
return 0;
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -48,8 +48,8 @@
#include <vlibsocket/vl_socket_api_h.h>
#undef vl_endianfun
static void vl_api_sockclnt_create_reply_t_handler (
vl_api_sockclnt_create_reply_t *mp)
static void
vl_api_sockclnt_create_reply_t_handler (vl_api_sockclnt_create_reply_t * mp)
{
vl_api_registration_t *rp = socket_main.current_rp;
@ -57,8 +57,8 @@ static void vl_api_sockclnt_create_reply_t_handler (
rp->server_index = mp->index;
}
static void vl_api_sockclnt_delete_reply_t_handler (
vl_api_sockclnt_delete_reply_t *mp)
static void
vl_api_sockclnt_delete_reply_t_handler (vl_api_sockclnt_delete_reply_t * mp)
{
unix_main_t *um = &unix_main;
unix_file_t *uf = socket_main.current_uf;
@ -68,7 +68,8 @@ static void vl_api_sockclnt_delete_reply_t_handler (
vl_free_socket_registration_index (rp->vl_api_registration_pool_index);
}
u32 sockclnt_open_index (char *client_name, char *hostname, int port)
u32
sockclnt_open_index (char *client_name, char *hostname, int port)
{
vl_api_registration_t *rp;
unix_main_t *um = &unix_main;
@ -82,7 +83,8 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
char my_hostname[64];
server = gethostbyname (hostname);
if (server == NULL) {
if (server == NULL)
{
clib_warning ("Couldn't translate server name %s", hostname);
return ~0;
}
@ -90,7 +92,8 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
/* Set up non-blocking server socket on CLIENT_API_SERVER_PORT */
sockfd = socket (AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
if (sockfd < 0)
{
clib_unix_warning ("socket");
return ~0;
}
@ -98,18 +101,18 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
bzero ((char *) &serv_addr, sizeof (serv_addr));
serv_addr.sin_family = AF_INET;
bcopy ((char *) server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
(char *) &serv_addr.sin_addr.s_addr, server->h_length);
serv_addr.sin_port = htons (port);
if (connect(sockfd,(const void *)&serv_addr,sizeof(serv_addr)) < 0) {
clib_unix_warning("Connect failure to (%s, %d)",
hostname, port);
if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
{
clib_unix_warning ("Connect failure to (%s, %d)", hostname, port);
return ~0;
}
rv = ioctl (sockfd, FIONBIO, &one);
if (rv < 0) {
if (rv < 0)
{
clib_unix_warning ("FIONBIO");
return ~0;
}
@ -131,7 +134,8 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
mp->_vl_msg_id = ntohs (VL_API_SOCKCLNT_CREATE);
mp->context = rp - socket_main.registration_pool;
if (gethostname(my_hostname, sizeof (my_hostname)) < 0) {
if (gethostname (my_hostname, sizeof (my_hostname)) < 0)
{
clib_unix_warning ("gethostname");
strncpy (my_hostname, "unknown!", sizeof (my_hostname) - 1);
}
@ -141,13 +145,15 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
return rp - socket_main.registration_pool;
}
void sockclnt_close_index (u32 index)
void
sockclnt_close_index (u32 index)
{
vl_api_sockclnt_delete_t *mp;
vl_api_registration_t *rp;
/* Don't crash / assert if fed garbage */
if (pool_is_free_index (socket_main.registration_pool, index)) {
if (pool_is_free_index (socket_main.registration_pool, index))
{
clib_warning ("registration_pool index %d already free", index);
return;
}
@ -160,7 +166,8 @@ void sockclnt_close_index (u32 index)
vl_msg_api_send (rp, (u8 *) mp);
}
vl_api_registration_t *sockclnt_get_registration (u32 index)
vl_api_registration_t *
sockclnt_get_registration (u32 index)
{
return pool_elt_at_index (socket_main.registration_pool, index);
}
@ -190,3 +197,11 @@ sockclnt_vlib_api_init (vlib_main_t *vm)
}
VLIB_API_INIT_FUNCTION (sockclnt_vlib_api_init);
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -23,3 +23,11 @@
*/
#include <vlibmemory/vl_memory_api_h.h>
#include <vlibsocket/sockclnt.api.h>
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -24,10 +24,19 @@
#include <vppinfra/byte_order.h>
#define vl_msg_id(n,h) n,
typedef enum {
typedef enum
{
VL_ILLEGAL_MESSAGE_ID = 0,
#include <vlibsocket/vl_socket_api_h.h>
} vl_msg_id_t;
#undef vl_msg_id
#endif /* __VL_MSG_ENUM_H__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/