/[resiprocate]/main/reTurn/DataBuffer.cxx
ViewVC logotype

Contents of /main/reTurn/DataBuffer.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10137 - (show annotations) (download)
Sun Apr 28 18:43:19 2013 UTC (6 years, 6 months ago) by sgodin
File MIME type: text/plain
File size: 3412 byte(s)
-merge work from b-counterpath-recon-20130424 with some changes
 - upped receive buffer size from 2048 to 4096
 - added setOnBeforeSocketClosedFp to AsyncSocketBase - Provides an opportunity
   for the app to clean up, e.g., QoS-related data or resources just before 
   the socket is closed
 - OS level Udp socket receive buffer size set to 66560
 - TurnAsyncSocketBase - use dispatch instead of post for send API for
   increased efficiency
 - TurnAsyncSocket - new client side APIs
   - setLocalPassword for checking integrity of incoming STUN messages
   - connectivityCheck for ICE connectivity checks 
   - setOnBeforeSocketClosedFp for QOS cleanup (windows)
   - send API now split into send(To)Framed and send(To)Unframed
   - Queue of guards modified to use a weak functor template instead
   - onBindFailure and onBindSuccess now return the Tuple that failed or succeeded
 - DataBuffer improvements
 - StunMessage - added ice attributes

1 #include "DataBuffer.hxx"
2 #include <memory.h>
3 #include <assert.h>
4 #include <rutil/WinLeakCheck.hxx>
5
6 namespace reTurn {
7
8 void ArrayDeallocator(char* data)
9 {
10 delete [] data;
11 }
12
13 DataBuffer::DataBuffer(const char* data, unsigned int size, deallocator dealloc)
14 : mDealloc(dealloc)
15 {
16 mBuffer = 0;
17 mSize = size;
18 if ( mSize > 0 )
19 {
20 mBuffer = new char[mSize];
21 memcpy(mBuffer, data, mSize);
22 }
23 mStart = mBuffer;
24 }
25
26 DataBuffer::DataBuffer(unsigned int size, deallocator dealloc)
27 : mDealloc(dealloc)
28 {
29 mBuffer = 0;
30 mSize = size;
31 if ( mSize > 0 )
32 {
33 mBuffer = new char[mSize];
34 memset(mBuffer, 0, mSize);
35 }
36
37 mStart = mBuffer;
38 }
39
40 DataBuffer::~DataBuffer()
41 {
42 mDealloc(mBuffer);
43 }
44
45 DataBuffer* DataBuffer::own(char* data, unsigned int size, deallocator dealloc)
46 {
47 DataBuffer* buff = new reTurn::DataBuffer(0, dealloc);
48 buff->mBuffer = data;
49 buff->mSize = size;
50 buff->mStart = buff->mBuffer;
51 return buff;
52 }
53
54 const char*
55 DataBuffer::data()
56 {
57 return mStart;
58 }
59
60 unsigned int
61 DataBuffer::size()
62 {
63 return mSize;
64 }
65
66 char*
67 DataBuffer::mutableData()
68 {
69 return mStart;
70 }
71
72 unsigned int&
73 DataBuffer::mutableSize()
74 {
75 return mSize;
76 }
77
78 char&
79 DataBuffer::operator[](unsigned int p)
80 {
81 assert(p < mSize);
82 return mBuffer[p];
83 }
84
85 char
86 DataBuffer::operator[](unsigned int p) const
87 {
88 assert(p < mSize);
89 return mBuffer[p];
90 }
91
92 unsigned int
93 DataBuffer::truncate(unsigned int newSize)
94 {
95 assert(newSize <= mSize);
96 mSize = newSize;
97 return mSize;
98 }
99
100 unsigned int
101 DataBuffer::offset(unsigned int bytes)
102 {
103 assert(bytes < mSize);
104 mStart = mStart+bytes;
105 mSize = mSize-bytes;
106 return mSize;
107 }
108
109 } // namespace
110
111
112 /* ====================================================================
113
114 Copyright (c) 2007-2008, Plantronics, Inc.
115 All rights reserved.
116
117 Redistribution and use in source and binary forms, with or without
118 modification, are permitted provided that the following conditions are
119 met:
120
121 1. Redistributions of source code must retain the above copyright
122 notice, this list of conditions and the following disclaimer.
123
124 2. Redistributions in binary form must reproduce the above copyright
125 notice, this list of conditions and the following disclaimer in the
126 documentation and/or other materials provided with the distribution.
127
128 3. Neither the name of Plantronics nor the names of its contributors
129 may be used to endorse or promote products derived from this
130 software without specific prior written permission.
131
132 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
133 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
134 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
135 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
136 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
137 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
138 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
139 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
140 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
141 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
142 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
143
144 ==================================================================== */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27