Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * api.h |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 4 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 5 | * Copyright (c) 2009 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #ifndef included_vlibsocket_api_h |
| 21 | #define included_vlibsocket_api_h |
| 22 | |
| 23 | #include <vlibapi/api.h> |
| 24 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 25 | typedef struct |
| 26 | { |
| 27 | /* Server port number */ |
| 28 | int portno; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 30 | /* By default, localhost... */ |
| 31 | u32 bind_address; |
| 32 | |
| 33 | /* |
| 34 | * (listen, server, client) registrations. Shared memory |
| 35 | * registrations are in shared memory |
| 36 | */ |
| 37 | vl_api_registration_t *registration_pool; |
| 38 | /* |
| 39 | * Chain-drag variables, so message API handlers |
| 40 | * (generally) don't know whether they're talking to a socket |
| 41 | * or to a shared-memory connection. |
| 42 | */ |
| 43 | vl_api_registration_t *current_rp; |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 44 | clib_file_t *current_uf; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 45 | /* One input buffer, shared across all sockets */ |
| 46 | i8 *input_buffer; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | } socket_main_t; |
| 48 | |
Damjan Marion | 6a7acc2 | 2016-12-19 16:28:36 +0100 | [diff] [blame] | 49 | extern socket_main_t socket_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 51 | void socksvr_add_pending_output (clib_file_t * uf, |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 52 | struct vl_api_registration_ *cf, |
| 53 | u8 * buffer, uword buffer_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 55 | #define SOCKSVR_DEFAULT_PORT 32741 /* whatever */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | |
| 57 | void vl_free_socket_registration_index (u32 pool_index); |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 58 | void vl_socket_process_msg (clib_file_t * uf, |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 59 | struct vl_api_registration_ *rp, i8 * input_v); |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 60 | clib_error_t *vl_socket_read_ready (clib_file_t * uf); |
| 61 | void vl_socket_add_pending_output (clib_file_t * uf, |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 62 | struct vl_api_registration_ *rp, |
| 63 | u8 * buffer, uword buffer_bytes); |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 64 | clib_error_t *vl_socket_write_ready (clib_file_t * uf); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 65 | void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem); |
| 66 | void vl_socket_api_send_with_data (vl_api_registration_t * rp, |
| 67 | u8 * elem, u8 * data_vector); |
| 68 | void vl_socket_api_send_with_length (vl_api_registration_t * rp, |
| 69 | u8 * elem, u32 msg_length); |
| 70 | void vl_socket_api_send_with_length_no_free (vl_api_registration_t * rp, |
| 71 | u8 * elem, u32 msg_length); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | u32 sockclnt_open_index (char *client_name, char *hostname, int port); |
| 73 | void sockclnt_close_index (u32 index); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 74 | void vl_client_msg_api_send (vl_api_registration_t * cm, u8 * elem); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | vl_api_registration_t *sockclnt_get_registration (u32 index); |
| 76 | void socksvr_set_port (u16 port); |
| 77 | void socksvr_set_bind_address (u32 bind_address); |
| 78 | |
| 79 | #endif /* included_vlibsocket_api_h */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * fd.io coding-style-patch-verification: ON |
| 83 | * |
| 84 | * Local Variables: |
| 85 | * eval: (c-set-style "gnu") |
| 86 | * End: |
| 87 | */ |