Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
f6aa7d59
Commit
f6aa7d59
authored
Apr 11, 2011
by
chenzhengzhang
Browse files
[trac749] refactor C++ utility library
parent
ea679d6d
Changes
182
Hide whitespace changes
Inline
Side-by-side
configure.ac
View file @
f6aa7d59
...
...
@@ -677,6 +677,8 @@ AC_CONFIG_FILES([Makefile
src/lib/datasrc/Makefile
src/lib/datasrc/tests/Makefile
src/lib/xfr/Makefile
src/lib/util/Makefile
src/lib/util/tests/Makefile
src/lib/log/Makefile
src/lib/log/compiler/Makefile
src/lib/log/tests/Makefile
...
...
src/bin/auth/auth_srv.cc
View file @
f6aa7d59
...
...
@@ -31,7 +31,8 @@
#include <exceptions/exceptions.h>
#include <dns/buffer.h>
#include <util/buffer.h>
#include <dns/edns.h>
#include <dns/exceptions.h>
#include <dns/messagerenderer.h>
...
...
@@ -63,6 +64,7 @@ using namespace isc;
using
namespace
isc
::
cc
;
using
namespace
isc
::
datasrc
;
using
namespace
isc
::
dns
;
using
namespace
isc
::
util
;
using
namespace
isc
::
auth
;
using
namespace
isc
::
dns
::
rdata
;
using
namespace
isc
::
data
;
...
...
src/bin/auth/auth_srv.h
View file @
f6aa7d59
...
...
@@ -109,7 +109,7 @@ public:
/// \throw isc::Unexpected Protocol type of \a message is unexpected
void
processMessage
(
const
asiolink
::
IOMessage
&
io_message
,
isc
::
dns
::
MessagePtr
message
,
isc
::
dns
::
OutputBufferPtr
buffer
,
isc
::
util
::
OutputBufferPtr
buffer
,
asiolink
::
DNSServer
*
server
);
/// \brief Set verbose flag
...
...
src/bin/auth/benchmarks/query_bench.cc
View file @
f6aa7d59
...
...
@@ -22,7 +22,7 @@
#include <bench/benchmark.h>
#include <bench/benchmark_util.h>
#include <
dns
/buffer.h>
#include <
util
/buffer.h>
#include <dns/message.h>
#include <dns/name.h>
#include <dns/question.h>
...
...
@@ -41,6 +41,7 @@ using namespace isc;
using
namespace
isc
::
data
;
using
namespace
isc
::
auth
;
using
namespace
isc
::
dns
;
using
namespace
isc
::
util
;
using
namespace
isc
::
xfr
;
using
namespace
isc
::
bench
;
using
namespace
asiolink
;
...
...
src/bin/auth/main.cc
View file @
f6aa7d59
...
...
@@ -25,7 +25,8 @@
#include <exceptions/exceptions.h>
#include <dns/buffer.h>
#include <util/buffer.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
...
...
@@ -49,6 +50,7 @@ using namespace isc::data;
using
namespace
isc
::
cc
;
using
namespace
isc
::
config
;
using
namespace
isc
::
dns
;
using
namespace
isc
::
util
;
using
namespace
isc
::
xfr
;
using
namespace
asiolink
;
...
...
src/bin/auth/tests/auth_srv_unittest.cc
View file @
f6aa7d59
...
...
@@ -41,6 +41,7 @@
using
namespace
std
;
using
namespace
isc
::
cc
;
using
namespace
isc
::
dns
;
using
namespace
isc
::
util
;
using
namespace
isc
::
dns
::
rdata
;
using
namespace
isc
::
data
;
using
namespace
isc
::
xfr
;
...
...
src/bin/host/host.cc
View file @
f6aa7d59
...
...
@@ -24,7 +24,8 @@
#include <string>
#include <iostream>
#include <dns/buffer.h>
#include <util/buffer.h>
#include <dns/name.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
...
...
@@ -37,6 +38,7 @@
using
namespace
std
;
using
namespace
isc
::
dns
;
using
namespace
isc
::
util
;
namespace
{
char
*
dns_type
=
NULL
;
// not set, so A, AAAA, MX
...
...
src/bin/resolver/main.cc
View file @
f6aa7d59
...
...
@@ -29,7 +29,7 @@
#include <exceptions/exceptions.h>
#include <
dns
/buffer.h>
#include <
util
/buffer.h>
#include <dns/rcode.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
...
...
src/bin/resolver/resolver.cc
View file @
f6aa7d59
...
...
@@ -29,9 +29,10 @@
#include <exceptions/exceptions.h>
#include <util/buffer.h>
#include <dns/opcode.h>
#include <dns/rcode.h>
#include <dns/buffer.h>
#include <dns/exceptions.h>
#include <dns/name.h>
#include <dns/question.h>
...
...
@@ -50,6 +51,7 @@
using
namespace
std
;
using
namespace
isc
;
using
namespace
isc
::
util
;
using
namespace
isc
::
dns
;
using
namespace
isc
::
data
;
using
namespace
isc
::
config
;
...
...
src/bin/resolver/resolver.h
View file @
f6aa7d59
...
...
@@ -77,7 +77,7 @@ public:
void
processMessage
(
const
asiolink
::
IOMessage
&
io_message
,
isc
::
dns
::
MessagePtr
query_message
,
isc
::
dns
::
MessagePtr
answer_message
,
isc
::
dns
::
OutputBufferPtr
buffer
,
isc
::
util
::
OutputBufferPtr
buffer
,
asiolink
::
DNSServer
*
server
);
/// \brief Set and get the config session
...
...
src/lib/Makefile.am
View file @
f6aa7d59
SUBDIRS
=
exceptions dns cc config python xfr bench log
asiolink
\
nsas cache resolve testutils datasrc server_common
SUBDIRS
=
exceptions
util
dns cc config python xfr bench log
\
asiolink
nsas cache resolve testutils datasrc server_common
src/lib/asiolink/Makefile.am
View file @
f6aa7d59
...
...
@@ -13,7 +13,6 @@ CLEANFILES = *.gcno *.gcda
# which would make the build fail with -Werror (our default setting).
lib_LTLIBRARIES
=
libasiolink.la
libasiolink_la_SOURCES
=
asiolink.h
libasiolink_la_SOURCES
+=
asiolink_utilities.h
libasiolink_la_SOURCES
+=
asiodef.cc asiodef.h
libasiolink_la_SOURCES
+=
dns_answer.h
libasiolink_la_SOURCES
+=
dns_lookup.h
...
...
@@ -27,7 +26,6 @@ libasiolink_la_SOURCES += io_endpoint.cc io_endpoint.h
libasiolink_la_SOURCES
+=
io_error.h
libasiolink_la_SOURCES
+=
io_fetch.cc io_fetch.h
libasiolink_la_SOURCES
+=
io_message.h
libasiolink_la_SOURCES
+=
qid_gen.cc qid_gen.h
libasiolink_la_SOURCES
+=
io_service.h io_service.cc
libasiolink_la_SOURCES
+=
io_socket.h io_socket.cc
libasiolink_la_SOURCES
+=
simple_callback.h
...
...
src/lib/asiolink/asiolink_utilities.h
deleted
100644 → 0
View file @
ea679d6d
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __ASIOLINK_UTILITIES_H
#define __ASIOLINK_UTILITIES_H
#include <cstddef>
namespace
asiolink
{
/// \brief Read Unsigned 16-Bit Integer from Buffer
///
/// This is essentially a copy of the isc::dns::InputBuffer::readUint16. It
/// should really be moved into a separate library.
///
/// \param buffer Data buffer at least two bytes long of which the first two
/// bytes are assumed to represent a 16-bit integer in network-byte
/// order.
///
/// \return Value of 16-bit integer
inline
uint16_t
readUint16
(
const
void
*
buffer
)
{
const
uint8_t
*
byte_buffer
=
static_cast
<
const
uint8_t
*>
(
buffer
);
uint16_t
result
=
(
static_cast
<
uint16_t
>
(
byte_buffer
[
0
]))
<<
8
;
result
|=
static_cast
<
uint16_t
>
(
byte_buffer
[
1
]);
return
(
result
);
}
/// \brief Write Unisgned 16-Bit Integer to Buffer
///
/// This is essentially a copy of isc::dns::OutputBuffer::writeUint16. It
/// should really be moved into a separate library.
///
/// \param value 16-bit value to convert
/// \param buffer Data buffer at least two bytes long into which the 16-bit
/// value is written in network-byte order.
inline
void
writeUint16
(
uint16_t
value
,
void
*
buffer
)
{
uint8_t
*
byte_buffer
=
static_cast
<
uint8_t
*>
(
buffer
);
byte_buffer
[
0
]
=
static_cast
<
uint8_t
>
((
value
&
0xff00U
)
>>
8
);
byte_buffer
[
1
]
=
static_cast
<
uint8_t
>
(
value
&
0x00ffU
);
}
}
// namespace asiolink
#endif // __ASIOLINK_UTILITIES_H
src/lib/asiolink/dns_answer.h
View file @
f6aa7d59
...
...
@@ -66,7 +66,7 @@ public:
virtual
void
operator
()(
const
IOMessage
&
io_message
,
isc
::
dns
::
MessagePtr
query_message
,
isc
::
dns
::
MessagePtr
answer_message
,
isc
::
dns
::
OutputBufferPtr
buffer
)
const
=
0
;
isc
::
util
::
OutputBufferPtr
buffer
)
const
=
0
;
};
}
// namespace asiolink
...
...
src/lib/asiolink/dns_lookup.h
View file @
f6aa7d59
...
...
@@ -17,7 +17,7 @@
#include <asiolink/io_message.h>
#include <asiolink/dns_server.h>
#include <
dns
/buffer.h>
#include <
util
/buffer.h>
#include <dns/message.h>
namespace
asiolink
{
...
...
@@ -70,7 +70,7 @@ public:
virtual
void
operator
()(
const
IOMessage
&
io_message
,
isc
::
dns
::
MessagePtr
message
,
isc
::
dns
::
MessagePtr
answer_message
,
isc
::
dns
::
OutputBufferPtr
buffer
,
isc
::
util
::
OutputBufferPtr
buffer
,
DNSServer
*
server
)
const
{
(
*
self_
)(
io_message
,
message
,
answer_message
,
buffer
,
server
);
...
...
src/lib/asiolink/io_asio_socket.h
View file @
f6aa7d59
...
...
@@ -26,7 +26,7 @@
#include <exceptions/exceptions.h>
#include <coroutine.h>
#include <
dns
/buffer.h>
#include <
util
/buffer.h>
#include <asiolink/io_error.h>
#include <asiolink/io_socket.h>
...
...
@@ -270,7 +270,7 @@ public:
virtual
bool
processReceivedData
(
const
void
*
staging
,
size_t
length
,
size_t
&
cumulative
,
size_t
&
offset
,
size_t
&
expected
,
isc
::
dns
::
OutputBufferPtr
&
outbuff
)
=
0
;
isc
::
util
::
OutputBufferPtr
&
outbuff
)
=
0
;
/// \brief Cancel I/O On AsioSocket
virtual
void
cancel
()
=
0
;
...
...
@@ -372,7 +372,7 @@ public:
virtual
bool
receiveComplete
(
const
void
*
staging
,
size_t
length
,
size_t
&
cumulative
,
size_t
&
offset
,
size_t
&
expected
,
isc
::
dns
::
OutputBufferPtr
&
outbuff
)
isc
::
util
::
OutputBufferPtr
&
outbuff
)
{
return
(
true
);
}
...
...
src/lib/asiolink/io_fetch.cc
View file @
f6aa7d59
...
...
@@ -22,13 +22,16 @@
#include <boost/scoped_ptr.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <util/buffer.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
#include <dns/opcode.h>
#include <dns/rcode.h>
#include <log/logger.h>
#include <asiolink/qid_gen.h>
#include <util/qid_gen.h>
#include <util/qid_gen.h>
#include <asio.hpp>
#include <asio/deadline_timer.hpp>
...
...
@@ -43,12 +46,12 @@
#include <asiolink/tcp_socket.h>
#include <asiolink/udp_endpoint.h>
#include <asiolink/udp_socket.h>
#include <asiolink/qid_gen.h>
#include <stdint.h>
using
namespace
asio
;
using
namespace
isc
::
dns
;
using
namespace
isc
::
util
;
using
namespace
isc
::
log
;
using
namespace
std
;
...
...
@@ -76,8 +79,8 @@ struct IOFetchData {
boost
::
scoped_ptr
<
IOEndpoint
>
remote_snd
;
///< Where the fetch is sent
boost
::
scoped_ptr
<
IOEndpoint
>
remote_rcv
;
///< Where the response came from
isc
::
dns
::
Question
question
;
///< Question to be asked
isc
::
dns
::
OutputBufferPtr
msgbuf
;
///< Wire buffer for question
isc
::
dns
::
OutputBufferPtr
received
;
///< Received data put here
OutputBufferPtr
msgbuf
;
///< Wire buffer for question
OutputBufferPtr
received
;
///< Received data put here
IOFetch
::
Callback
*
callback
;
///< Called on I/O Completion
asio
::
deadline_timer
timer
;
///< Timer to measure timeouts
IOFetch
::
Protocol
protocol
;
///< Protocol being used
...
...
@@ -117,8 +120,7 @@ struct IOFetchData {
/// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
IOFetchData
(
IOFetch
::
Protocol
proto
,
IOService
&
service
,
const
isc
::
dns
::
Question
&
query
,
const
IOAddress
&
address
,
uint16_t
port
,
isc
::
dns
::
OutputBufferPtr
&
buff
,
IOFetch
::
Callback
*
cb
,
int
wait
)
uint16_t
port
,
OutputBufferPtr
&
buff
,
IOFetch
::
Callback
*
cb
,
int
wait
)
:
socket
((
proto
==
IOFetch
::
UDP
)
?
static_cast
<
IOAsioSocket
<
IOFetch
>*>
(
...
...
@@ -135,7 +137,7 @@ struct IOFetchData {
static_cast
<
IOEndpoint
*>
(
new
TCPEndpoint
(
address
,
port
))
),
question
(
query
),
msgbuf
(
new
isc
::
dns
::
OutputBuffer
(
512
)),
msgbuf
(
new
OutputBuffer
(
512
)),
received
(
buff
),
callback
(
cb
),
...
...
src/lib/asiolink/io_fetch.h
View file @
f6aa7d59
...
...
@@ -25,7 +25,7 @@
#include <asio/error_code.hpp>
#include <
dns
/buffer.h>
#include <
util
/buffer.h>
#include <dns/question.h>
namespace
asiolink
{
...
...
@@ -134,7 +134,7 @@ public:
/// -1 indicates no timeout.
IOFetch
(
Protocol
protocol
,
IOService
&
service
,
const
isc
::
dns
::
Question
&
question
,
const
IOAddress
&
address
,
uint16_t
port
,
isc
::
dns
::
OutputBufferPtr
&
buff
,
Callback
*
cb
,
uint16_t
port
,
isc
::
util
::
OutputBufferPtr
&
buff
,
Callback
*
cb
,
int
wait
=
-
1
);
/// \brief Return Current Protocol
...
...
src/lib/asiolink/qid_gen.cc
deleted
100644 → 0
View file @
ea679d6d
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// qid_gen defines a generator for query id's
//
// We probably want to merge this with the weighted random in the nsas
// (and other parts where we need randomness, perhaps another thing
// for a general libutil?)
#include <asiolink/qid_gen.h>
#include <sys/time.h>
namespace
{
asiolink
::
QidGenerator
qid_generator_instance
;
}
namespace
asiolink
{
QidGenerator
&
QidGenerator
::
getInstance
()
{
return
(
qid_generator_instance
);
}
QidGenerator
::
QidGenerator
()
:
dist_
(
0
,
65535
),
vgen_
(
generator_
,
dist_
)
{
seed
();
}
void
QidGenerator
::
seed
()
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
0
);
generator_
.
seed
((
tv
.
tv_sec
*
1000000
)
+
tv
.
tv_usec
);
}
isc
::
dns
::
qid_t
QidGenerator
::
generateQid
()
{
return
(
vgen_
());
}
}
// namespace asiolink
src/lib/asiolink/qid_gen.h
deleted
100644 → 0
View file @
ea679d6d
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// qid_gen defines a generator for query id's
//
// We probably want to merge this with the weighted random in the nsas
// (and other parts where we need randomness, perhaps another thing
// for a general libutil?)
#ifndef __QID_GEN_H
#define __QID_GEN_H
#include <dns/message.h>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
namespace
asiolink
{
/// This class generates Qids for outgoing queries
///
/// It is implemented as a singleton; the public way to access it
/// is to call getInstance()->generateQid().
///
/// It automatically seeds it with the current time when it is first
/// used.
class
QidGenerator
{
public:
/// \brief Returns the singleton instance of the QidGenerator
///
/// Returns a reference to the singleton instance of the generator
static
QidGenerator
&
getInstance
();
/// \brief Default constructor
///
/// It is recommended that getInstance is used rather than creating
/// separate instances of this class.
///
/// The constructor automatically seeds the generator with the
/// current time.
QidGenerator
();
/// Generate a Qid
///
/// \return A random Qid
isc
::
dns
::
qid_t
generateQid
();
/// \brief Seeds the QidGenerator (based on the current time)
///
/// This is automatically called by the constructor
void
seed
();
private:
// "Mersenne Twister: A 623-dimensionally equidistributed
// uniform pseudo-random number generator", Makoto Matsumoto and
// Takuji Nishimura, ACM Transactions on Modeling and Computer
// Simulation: Special Issue on Uniform Random Number Generation,
// Vol. 8, No. 1, January 1998, pp. 3-30.
//
// mt19937 is an implementation of one of the pseudo random
// generators described in this paper.
boost
::
mt19937
generator_
;
// For qid's we want a uniform distribution
boost
::
uniform_int
<>
dist_
;
boost
::
variate_generator
<
boost
::
mt19937
&
,
boost
::
uniform_int
<>
>
vgen_
;
};
}
// namespace asiolink
#endif // __QID_GEN_H
Prev
1
2
3
4
5
…
10
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment