blob: 231290088b3c51ebefb22216ed0078e4b1de741e [file] [log] [blame]
Florin Corase86a8ed2018-01-05 03:20:25 -08001/*
2 *------------------------------------------------------------------
3 * Copyright (c) 2018 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
16 */
17
18#ifndef SRC_VLIBMEMORY_SOCKET_CLIENT_H_
19#define SRC_VLIBMEMORY_SOCKET_CLIENT_H_
20
21#include <vppinfra/file.h>
22#include <vppinfra/time.h>
23#include <vlibmemory/memory_shared.h>
24
25typedef struct
26{
27 int socket_fd;
Florin Coras2881dec2018-10-02 18:29:25 -070028 int socket_enable; /**< Can temporarily disable the connection
29 but still can keep it around... */
30 u32 client_index; /**< Client index allocated by VPP */
Florin Corase86a8ed2018-01-05 03:20:25 -080031
32 clib_socket_t client_socket;
33
34 u32 socket_buffer_size;
35 u8 *socket_tx_buffer;
36 u8 *socket_rx_buffer;
37 u32 socket_tx_nbytes;
38 int control_pings_outstanding;
39
40 u8 *name;
41 clib_time_t clib_time;
Florin Corasb384b542018-01-15 01:08:33 -080042 ssvm_private_t memfd_segment;
Tomasz Kulasek97dcf5b2019-01-31 18:26:32 +010043
44 int want_shm_pthread;
Florin Corase86a8ed2018-01-05 03:20:25 -080045} socket_client_main_t;
46
47extern socket_client_main_t socket_client_main;
48
49#define SOCKET_CLIENT_DEFAULT_BUFFER_SIZE 4096
50
51int vl_socket_client_connect (char *socket_path, char *client_name,
52 u32 socket_buffer_size);
53void vl_socket_client_disconnect (void);
Florin Coras59cea1a2019-11-25 13:40:42 -080054void vl_socket_client_enable_disable (int enable);
Florin Corase86a8ed2018-01-05 03:20:25 -080055int vl_socket_client_read (int wait);
56int vl_socket_client_write (void);
Florin Corase86a8ed2018-01-05 03:20:25 -080057void *vl_socket_client_msg_alloc (int nbytes);
Tomasz Kulasek97dcf5b2019-01-31 18:26:32 +010058int vl_socket_client_init_shm (vl_api_shm_elem_config_t * config,
59 int want_pthread);
Florin Coras466f2892018-08-03 02:50:43 -070060clib_error_t *vl_socket_client_recv_fd_msg (int fds[], int n_fds, u32 wait);
Florin Corase86a8ed2018-01-05 03:20:25 -080061
Florin Coras59cea1a2019-11-25 13:40:42 -080062/*
63 * Socket client apis that explicitly pass socket main as an argument
64 */
65
66int vl_socket_client_connect2 (socket_client_main_t * scm, char *socket_path,
67 char *client_name, u32 socket_buffer_size);
68void vl_socket_client_disconnect2 (socket_client_main_t * scm);
69void vl_socket_client_enable_disable2 (socket_client_main_t * scm,
70 int enable);
71int vl_socket_client_read2 (socket_client_main_t * scm, int wait);
72int vl_socket_client_write2 (socket_client_main_t * scm);
73void *vl_socket_client_msg_alloc2 (socket_client_main_t * scm, int nbytes);
74int vl_socket_client_init_shm2 (socket_client_main_t * scm,
75 vl_api_shm_elem_config_t * config,
76 int want_pthread);
77clib_error_t *vl_socket_client_recv_fd_msg2 (socket_client_main_t * scm,
78 int fds[], int n_fds, u32 wait);
79
Florin Corase86a8ed2018-01-05 03:20:25 -080080#endif /* SRC_VLIBMEMORY_SOCKET_CLIENT_H_ */
81
82/*
83 * fd.io coding-style-patch-verification: ON
84 *
85 * Local Variables:
86 * eval: (c-set-style "gnu")
87 * End:
88 */