1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2014 Couchbase, Inc.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #ifndef MC_IOVCURSOR_H
19 #define MC_IOVCURSOR_H
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /** Minimal cursor */
25 typedef struct {
26     /**The IOV array containing the buffer offsets. This is initialized to the
27      * first element of the array on input. As data is consumed by the
28      * library, this pointer value will increment.*/
29     nb_IOV *iov;
30 
31     /**Number of elements in the IOV array. This is decremented as the `iov`
32      * field is incremented.*/
33     unsigned niov;
34 
35     /**Offset into first IOV structure which contains data. This is used
36      * if the IOV contains partially consumed data. The library sets this
37      * field if a packet ends in the middle of an IOV buffer*/
38     unsigned offset;
39 } mc_IOVCURSOR;
40 
41 typedef struct {
42     /** Cursor element */
43     mc_IOVCURSOR c;
44 
45     /**The total number of bytes used by the library in the last packet
46      * successfuly processed.*/
47     unsigned consumed;
48 
49     /**Number of bytes wanted for next operation (OUT). This contains the
50      * total number of bytes (including any within the buffer already).
51      * The library does not read from this value. */
52     unsigned wanted;
53 
54     /**The total amount of data within the IOV buffers. This is initialized
55      * in the mc_iovinfo_init() function by traversing through all the elements
56      * and adding their `iov_len` fields. If using the `IOVINFO` structure
57      * in a read loop, you will want to increment this whenever new data has
58      * been placed into buffers*/
59     unsigned total;
60 } mc_IOVINFO;
61 
62 #ifdef __cplusplus
63 }
64 #endif
65 
66 #endif
67