Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1 | /* |
| 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> |
Damjan Marion | b704971 | 2022-05-20 13:05:38 +0200 | [diff] [blame] | 23 | #include <vlibapi/memory_shared.h> |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 24 | |
| 25 | typedef struct |
| 26 | { |
| 27 | int socket_fd; |
Florin Coras | 2881dec | 2018-10-02 18:29:25 -0700 | [diff] [blame] | 28 | 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 Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 31 | |
| 32 | clib_socket_t client_socket; |
| 33 | |
| 34 | u32 socket_buffer_size; |
| 35 | u8 *socket_tx_buffer; |
| 36 | u8 *socket_rx_buffer; |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 37 | int control_pings_outstanding; |
| 38 | |
| 39 | u8 *name; |
| 40 | clib_time_t clib_time; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 41 | ssvm_private_t memfd_segment; |
Tomasz Kulasek | 97dcf5b | 2019-01-31 18:26:32 +0100 | [diff] [blame] | 42 | |
| 43 | int want_shm_pthread; |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 44 | } socket_client_main_t; |
| 45 | |
| 46 | extern socket_client_main_t socket_client_main; |
| 47 | |
| 48 | #define SOCKET_CLIENT_DEFAULT_BUFFER_SIZE 4096 |
| 49 | |
| 50 | int vl_socket_client_connect (char *socket_path, char *client_name, |
| 51 | u32 socket_buffer_size); |
| 52 | void vl_socket_client_disconnect (void); |
Florin Coras | 59cea1a | 2019-11-25 13:40:42 -0800 | [diff] [blame] | 53 | void vl_socket_client_enable_disable (int enable); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 54 | int vl_socket_client_read (int wait); |
| 55 | int vl_socket_client_write (void); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 56 | void *vl_socket_client_msg_alloc (int nbytes); |
Tomasz Kulasek | 97dcf5b | 2019-01-31 18:26:32 +0100 | [diff] [blame] | 57 | int vl_socket_client_init_shm (vl_api_shm_elem_config_t * config, |
| 58 | int want_pthread); |
Florin Coras | 466f289 | 2018-08-03 02:50:43 -0700 | [diff] [blame] | 59 | clib_error_t *vl_socket_client_recv_fd_msg (int fds[], int n_fds, u32 wait); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 60 | |
Florin Coras | 59cea1a | 2019-11-25 13:40:42 -0800 | [diff] [blame] | 61 | /* |
| 62 | * Socket client apis that explicitly pass socket main as an argument |
| 63 | */ |
| 64 | |
| 65 | int vl_socket_client_connect2 (socket_client_main_t * scm, char *socket_path, |
| 66 | char *client_name, u32 socket_buffer_size); |
| 67 | void vl_socket_client_disconnect2 (socket_client_main_t * scm); |
| 68 | void vl_socket_client_enable_disable2 (socket_client_main_t * scm, |
| 69 | int enable); |
| 70 | int vl_socket_client_read2 (socket_client_main_t * scm, int wait); |
| 71 | int vl_socket_client_write2 (socket_client_main_t * scm); |
| 72 | void *vl_socket_client_msg_alloc2 (socket_client_main_t * scm, int nbytes); |
| 73 | int vl_socket_client_init_shm2 (socket_client_main_t * scm, |
| 74 | vl_api_shm_elem_config_t * config, |
| 75 | int want_pthread); |
| 76 | clib_error_t *vl_socket_client_recv_fd_msg2 (socket_client_main_t * scm, |
| 77 | int fds[], int n_fds, u32 wait); |
| 78 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 79 | #endif /* SRC_VLIBMEMORY_SOCKET_CLIENT_H_ */ |
| 80 | |
| 81 | /* |
| 82 | * fd.io coding-style-patch-verification: ON |
| 83 | * |
| 84 | * Local Variables: |
| 85 | * eval: (c-set-style "gnu") |
| 86 | * End: |
| 87 | */ |