Line data Source code
1 : /* 2 : * Copyright (c) 2022 Cisco and/or its affiliates. 3 : * Licensed under the Apache License, Version 2.0 (the "License"); 4 : * you may not use this file except in compliance with the License. 5 : * You may obtain a copy of the License at: 6 : * 7 : * http://www.apache.org/licenses/LICENSE-2.0 8 : * 9 : * Unless required by applicable law or agreed to in writing, software 10 : * distributed under the License is distributed on an "AS IS" BASIS, 11 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : * See the License for the specific language governing permissions and 13 : * limitations under the License. 14 : */ 15 : 16 : #ifndef SRC_PLUGINS_HTTP_HTTP_BUFFER_H_ 17 : #define SRC_PLUGINS_HTTP_HTTP_BUFFER_H_ 18 : 19 : #include <svm/svm_fifo.h> 20 : 21 : #define HTTP_BUFFER_DATA_SZ 32 22 : 23 : typedef enum http_buffer_type_ 24 : { 25 : HTTP_BUFFER_FIFO, 26 : HTTP_BUFFER_PTR, 27 : } http_buffer_type_t; 28 : 29 : typedef struct http_buffer_vft_ http_buffer_vft_t; 30 : 31 : typedef struct http_buffer_ 32 : { 33 : http_buffer_vft_t *vft; 34 : u8 data[HTTP_BUFFER_DATA_SZ]; 35 : } http_buffer_t; 36 : 37 : struct http_buffer_vft_ 38 : { 39 : void (*init) (http_buffer_t *, void *data, u64 len); 40 : void (*free) (http_buffer_t *); 41 : svm_fifo_seg_t *(*get_segs) (http_buffer_t *, u32 max_len, u32 *n_segs); 42 : u32 (*drain) (http_buffer_t *, u32 len); 43 : u8 (*is_drained) (http_buffer_t *); 44 : }; 45 : 46 : void http_buffer_init (http_buffer_t *hb, http_buffer_type_t type, 47 : svm_fifo_t *f, u64 data_len); 48 : 49 : static inline void 50 0 : http_buffer_free (http_buffer_t *hb) 51 : { 52 0 : if (hb->vft) 53 0 : hb->vft->free (hb); 54 0 : } 55 : 56 : static inline svm_fifo_seg_t * 57 0 : http_buffer_get_segs (http_buffer_t *hb, u32 max_len, u32 *n_segs) 58 : { 59 0 : return hb->vft->get_segs (hb, max_len, n_segs); 60 : } 61 : 62 : static inline u32 63 0 : http_buffer_drain (http_buffer_t *hb, u32 len) 64 : { 65 0 : return hb->vft->drain (hb, len); 66 : } 67 : 68 : static inline u8 69 0 : http_buffer_is_drained (http_buffer_t *hb) 70 : { 71 0 : return hb->vft->is_drained (hb); 72 : } 73 : 74 : #endif /* SRC_PLUGINS_HTTP_HTTP_BUFFER_H_ */ 75 : 76 : /* 77 : * fd.io coding-style-patch-verification: ON 78 : * 79 : * Local Variables: 80 : * eval: (c-set-style "gnu") 81 : * End: 82 : */