SolarCapture C Bindings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
iovec.h
Go to the documentation of this file.
1 
8 #ifndef __SOLAR_CAPTURE_IOVEC_H__
9 #define __SOLAR_CAPTURE_IOVEC_H__
10 
11 #include <string.h>
12 
13 
18 struct sc_iovec_ptr {
19  const struct iovec* iov;
20  int iovlen;
21  struct iovec io;
22 };
23 
35 static inline void __sc_iovec_ptr_init(struct sc_iovec_ptr* iovp,
36  const struct iovec* iov, int iovlen)
37 {
38  iovp->iovlen = iovlen;
39  iovp->iov = iov;
40  iovp->io = iov[0];
41 }
52 static inline void sc_iovec_ptr_init(struct sc_iovec_ptr* iovp,
53  const struct iovec* iov, int iovlen)
54 {
55  iovp->iovlen = iovlen;
56  iovp->iov = iov;
57  if( iovlen )
58  iovp->io = iov[0];
59 }
60 
61 
69 static inline void sc_iovec_ptr_init_buf(struct sc_iovec_ptr* iovp,
70  void* buf, int len)
71 {
72  iovp->iovlen = 1;
73  iovp->iov = NULL;
74  iovp->io.iov_base = buf;
75  iovp->io.iov_len = len;
76 }
77 
78 
85 static inline void sc_iovec_ptr_init_packet(struct sc_iovec_ptr* iovp,
86  const struct sc_packet* packet)
87 {
88  __sc_iovec_ptr_init(iovp, packet->iov, packet->iovlen);
89 }
90 
91 
97 static inline int sc_iovec_ptr_bytes(const struct sc_iovec_ptr* iovp)
98 {
99  int i, bytes = 0;
100  if( iovp->iovlen ) {
101  bytes += iovp->io.iov_len;
102  for( i = 1; i < iovp->iovlen; ++i )
103  bytes += iovp->iov[i].iov_len;
104  }
105  return bytes;
106 }
107 
108 
119 #if SC_API_VER >= 1
120 extern int sc_iovec_ptr_skip(struct sc_iovec_ptr* iovp, int bytes_to_skip);
121 #endif
122 
123 
133 #if SC_API_VER >= 1
134 extern int sc_iovec_ptr_find_chr(const struct sc_iovec_ptr* iovp, int c);
135 #endif
136 
137 
147 #if SC_API_VER >= 1
148 extern int sc_iovec_ptr_copy_out(void* dest, struct sc_iovec_ptr* iovp,
149  int max_bytes);
150 #endif
151 
152 
164 static inline void sc_iovec_copy_from_end(void* dest_buf,
165  const struct iovec* iov,
166  int iovlen, int bytes)
167 {
168  iov += iovlen - 1;
169  while( 1 ) {
170  unsigned n = bytes;
171  if( n > iov->iov_len )
172  n = iov->iov_len;
173  memcpy((char*) dest_buf + bytes - n,
174  (const char*) iov->iov_base + iov->iov_len - n, n);
175  if( (bytes -= n) == 0 )
176  break;
177  --iov;
178  --iovlen;
179  assert(iovlen > 0);
180  }
181 }
182 
192 static inline void sc_iovec_trim_end(struct iovec* iov, uint8_t* iovlen,
193  int bytes)
194 {
195  iov += *iovlen - 1;
196  while( 1 ) {
197  if( bytes < (int) iov->iov_len ) {
198  iov->iov_len -= bytes;
199  return;
200  }
201  bytes -= iov->iov_len;
202  --iov;
203  --(*iovlen);
204  if( bytes == 0 )
205  break;
206  assert(*iovlen > 0);
207  }
208 }
209 
210 
211 #endif /* __SOLAR_CAPTURE_IOVEC_H__ */
212 
static int sc_iovec_ptr_bytes(const struct sc_iovec_ptr *iovp)
Returns the number of bytes represented by an sc_iovec_ptr.
Definition: iovec.h:97
static void sc_iovec_ptr_init_buf(struct sc_iovec_ptr *iovp, void *buf, int len)
Initialise a struct sc_iovec_ptr with a contiguous buffer.
Definition: iovec.h:69
static void sc_iovec_copy_from_end(void *dest_buf, const struct iovec *iov, int iovlen, int bytes)
Copy data out of the end of a sc_iovec_ptr.
Definition: iovec.h:164
static void sc_iovec_trim_end(struct iovec *iov, uint8_t *iovlen, int bytes)
Remove data from the end of an iovec.
Definition: iovec.h:192
static void sc_iovec_ptr_init_packet(struct sc_iovec_ptr *iovp, const struct sc_packet *packet)
Initialise a struct sc_iovec_ptr to point at packet data.
Definition: iovec.h:85
int sc_iovec_ptr_skip(struct sc_iovec_ptr *iovp, int bytes_to_skip)
Skip forward over an iovec.
static void sc_iovec_ptr_init(struct sc_iovec_ptr *iovp, const struct iovec *iov, int iovlen)
Initialise a struct sc_iovec_ptr.
Definition: iovec.h:52
struct iovec * iov
Definition: ext_packet.h:68
Representation of a packet.
Definition: ext_packet.h:56
int sc_iovec_ptr_find_chr(const struct sc_iovec_ptr *iovp, int c)
Find offset of character in iovec.
int sc_iovec_ptr_copy_out(void *dest, struct sc_iovec_ptr *iovp, int max_bytes)
Copy data out of an sc_iovec_ptr.
Definition: iovec.h:18
uint8_t iovlen
Definition: ext_packet.h:63