1 | /****************************************************************************** |
---|
2 | * QUANTA - A toolkit for High Performance Data Sharing |
---|
3 | * Copyright (C) 2003 Electronic Visualization Laboratory, |
---|
4 | * University of Illinois at Chicago |
---|
5 | * |
---|
6 | * All rights reserved. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions are met: |
---|
10 | * |
---|
11 | * * Redistributions of source code must retain the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer. |
---|
13 | * * Redistributions in binary form must reproduce the above |
---|
14 | * copyright notice, this list of conditions and the following disclaimer |
---|
15 | * in the documentation and/or other materials provided with the distribution. |
---|
16 | * * Neither the name of the University of Illinois at Chicago nor |
---|
17 | * the names of its contributors may be used to endorse or promote |
---|
18 | * products derived from this software without specific prior written permission. |
---|
19 | * |
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | * Direct questions, comments etc about Quanta to cavern@evl.uic.edu |
---|
33 | *****************************************************************************/ |
---|
34 | |
---|
35 | /* |
---|
36 | * File name: QUANTAnet_iovec.hxx |
---|
37 | * |
---|
38 | * Description: This class is a container class for the iovec structure |
---|
39 | * |
---|
40 | * Usasge: 1) readv(), writev() Methods in QUANTAnet_tcp_c class |
---|
41 | * 2) recvmsg(), sendmsg() Methods in QUANRTAnet_udp_c class |
---|
42 | * |
---|
43 | * Comments: QUANTAnet_iovec_c is a dynamic array of Iovec structures |
---|
44 | * Each Iovec strucure contains two values |
---|
45 | * 1) base pointer 2) its length |
---|
46 | * You can add diffrenet type of objects to the QUANTAnet_iovec_c |
---|
47 | * |
---|
48 | * How to use -> See: /QUANTA/demos/network/tcp/ioservertcp.cxx |
---|
49 | * ioclienttcp.cxx |
---|
50 | * |
---|
51 | * Change Log: |
---|
52 | */ |
---|
53 | |
---|
54 | |
---|
55 | #ifndef _QUANTANET_IOVEC |
---|
56 | #define _QUANTANET_IOVEC |
---|
57 | |
---|
58 | #ifndef __HAVE_STDIO_H |
---|
59 | #include <stdio.h> |
---|
60 | #define __HAVE_STDIO_H |
---|
61 | #endif |
---|
62 | #include <stdlib.h> |
---|
63 | |
---|
64 | |
---|
65 | #include "QUANTAglobals.hxx" |
---|
66 | |
---|
67 | #ifdef WIN32 |
---|
68 | #ifndef __HAVE_WINSOCK2_H |
---|
69 | #include <winsock2.h> |
---|
70 | #define __HAVE_WINSOCK2_H |
---|
71 | #endif /* __HAVE_WINSOCK2_H */ |
---|
72 | #else |
---|
73 | #include <sys/uio.h> |
---|
74 | #endif |
---|
75 | |
---|
76 | class QUANTAnet_iovec_c |
---|
77 | { |
---|
78 | private: |
---|
79 | |
---|
80 | //keeps the number of elements in the iovec array |
---|
81 | int num_of_elements; |
---|
82 | |
---|
83 | //keeps the number of elements dynamically allocated |
---|
84 | int nalloc; |
---|
85 | |
---|
86 | //base pointer of the iovec dynamic array |
---|
87 | #ifdef WIN32 |
---|
88 | WSABUF* bufList; |
---|
89 | #else |
---|
90 | struct iovec* bufList; |
---|
91 | #endif |
---|
92 | |
---|
93 | public: |
---|
94 | |
---|
95 | //constructor |
---|
96 | //By default bufList is allocated 512 entries because |
---|
97 | //512*sizeof(iovec) = 4K(Page Size) to avoid page fault |
---|
98 | QUANTAnet_iovec_c(int size = 512); |
---|
99 | |
---|
100 | //destructor |
---|
101 | ~QUANTAnet_iovec_c(); |
---|
102 | |
---|
103 | /** |
---|
104 | @desc add the pointer and its length to the iovec array |
---|
105 | @param buff void* |
---|
106 | @param length int |
---|
107 | @return true or false |
---|
108 | **/ |
---|
109 | bool add(void* buff, int length); |
---|
110 | |
---|
111 | /** |
---|
112 | @desc remove the specific iovec entry |
---|
113 | @param index int |
---|
114 | @return true or false |
---|
115 | **/ |
---|
116 | bool removeAt(int index); |
---|
117 | |
---|
118 | /** |
---|
119 | @desc clear all entry in iovec array |
---|
120 | @return void |
---|
121 | **/ |
---|
122 | void removeAll(); |
---|
123 | |
---|
124 | /** |
---|
125 | @desc returns size of the iovec array |
---|
126 | @return size int |
---|
127 | **/ |
---|
128 | int size(); |
---|
129 | |
---|
130 | /** |
---|
131 | @desc used in readv(), writev() methods (internal use only) |
---|
132 | @return base pointer of the dynamic array of iovec structures |
---|
133 | **/ |
---|
134 | |
---|
135 | #ifdef WIN32 |
---|
136 | WSABUF* getBuffer() {return bufList;} |
---|
137 | #else |
---|
138 | const iovec* getBuffer() {return bufList;} |
---|
139 | #endif |
---|
140 | |
---|
141 | }; |
---|
142 | |
---|
143 | #endif |
---|
144 | |
---|