From 347f038c20550a4e5e2a4747c339d36991bb5214 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 24 Nov 2008 15:58:21 +0000 Subject: fixes for boost 1.35 and higher --- src/anytun.cpp | 10 ++++------ src/packetSource.cpp | 26 +++++++++++++------------- src/packetSource.h | 6 +++--- src/syncClient.cpp | 24 ++++++++++++------------ src/syncClient.h | 2 +- src/syncServer.cpp | 41 ++++++++++++++++++++--------------------- src/syncServer.h | 8 ++++---- src/syncTcpConnection.cpp | 20 ++++++++++---------- src/syncTcpConnection.h | 12 ++++++------ 9 files changed, 73 insertions(+), 76 deletions(-) diff --git a/src/anytun.cpp b/src/anytun.cpp index 8504d90..aec1f6d 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -40,7 +40,6 @@ #include #include -#include #include #include // for ENOMEM @@ -215,8 +214,8 @@ void syncListener(SyncQueue * queue ) try { - asio::io_service io_service; - SyncServer server(io_service,asio::ip::tcp::endpoint(asio::ip::tcp::v4(), gOpt.getLocalSyncPort())); + boost::asio::io_service io_service; + SyncServer server(io_service,boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), gOpt.getLocalSyncPort())); server.onConnect=boost::bind(syncOnConnect,_1); queue->setSyncServerPtr(&server); io_service.run(); @@ -330,7 +329,6 @@ void receiver(void* p) // boost thread callbacks for libgcrypt #if defined(BOOST_HAS_PTHREADS) -typedef boost::detail::thread::lock_ops mutex_ops; static int boost_mutex_init(void **priv) { @@ -349,13 +347,13 @@ static int boost_mutex_destroy(void **lock) static int boost_mutex_lock(void **lock) { - mutex_ops::lock(*reinterpret_cast(*lock)); + reinterpret_cast(*lock)->lock(); return 0; } static int boost_mutex_unlock(void **lock) { - mutex_ops::unlock(*reinterpret_cast(*lock)); + reinterpret_cast(*lock)->unlock(); return 0; } diff --git a/src/packetSource.cpp b/src/packetSource.cpp index 7d06814..b144e8c 100644 --- a/src/packetSource.cpp +++ b/src/packetSource.cpp @@ -29,7 +29,7 @@ * along with anytun. If not, see . */ -#include +#include #include #include "datatypes.h" @@ -42,9 +42,9 @@ UDPPacketSource::UDPPacketSource(u_int16_t port) : sock_(io_service_) std::stringstream ps; ps << port; - asio::ip::udp::resolver resolver(io_service_); - asio::ip::udp::resolver::query query(ps.str()); - asio::ip::udp::endpoint e = *resolver.resolve(query); + boost::asio::ip::udp::resolver resolver(io_service_); + boost::asio::ip::udp::resolver::query query(ps.str()); + boost::asio::ip::udp::endpoint e = *resolver.resolve(query); sock_.open(e.protocol()); sock_.bind(e); } @@ -54,17 +54,17 @@ UDPPacketSource::UDPPacketSource(std::string localaddr, u_int16_t port) : sock_( std::stringstream ps; ps << port; - asio::ip::udp::resolver resolver(io_service_); - asio::ip::udp::resolver::query query(localaddr, ps.str()); - asio::ip::udp::endpoint e = *resolver.resolve(query); + boost::asio::ip::udp::resolver resolver(io_service_); + boost::asio::ip::udp::resolver::query query(localaddr, ps.str()); + boost::asio::ip::udp::endpoint e = *resolver.resolve(query); sock_.open(e.protocol()); sock_.bind(e); } u_int32_t UDPPacketSource::recv(u_int8_t* buf, u_int32_t len, std::string& addr, u_int16_t &port) { - asio::ip::udp::endpoint e; - u_int32_t rtn = sock_.receive_from(asio::buffer(buf, len), e); + boost::asio::ip::udp::endpoint e; + u_int32_t rtn = sock_.receive_from(boost::asio::buffer(buf, len), e); addr = e.address().to_string(); port = e.port(); @@ -77,9 +77,9 @@ void UDPPacketSource::send(u_int8_t* buf, u_int32_t len, std::string addr, u_int std::stringstream ps; ps << port; - asio::ip::udp::resolver resolver(io_service_); - asio::ip::udp::resolver::query query(addr, ps.str()); - asio::ip::udp::endpoint e = *resolver.resolve(query); + boost::asio::ip::udp::resolver resolver(io_service_); + boost::asio::ip::udp::resolver::query query(addr, ps.str()); + boost::asio::ip::udp::endpoint e = *resolver.resolve(query); - sock_.send_to(asio::buffer(buf, len), e); + sock_.send_to(boost::asio::buffer(buf, len), e); } diff --git a/src/packetSource.h b/src/packetSource.h index 4fe6125..2b08cf8 100644 --- a/src/packetSource.h +++ b/src/packetSource.h @@ -29,7 +29,7 @@ * along with anytun. If not, see . */ -#include +#include #include "datatypes.h" #include "buffer.h" @@ -53,7 +53,7 @@ public: void send(u_int8_t* buf, u_int32_t len, std::string addr, u_int16_t port); private: - asio::io_service io_service_; - asio::ip::udp::socket sock_; + boost::asio::io_service io_service_; + boost::asio::ip::udp::socket sock_; }; diff --git a/src/syncClient.cpp b/src/syncClient.cpp index d6ede4a..48f8d27 100644 --- a/src/syncClient.cpp +++ b/src/syncClient.cpp @@ -52,37 +52,37 @@ void SyncClient::run() { try { - asio::io_service io_service; + boost::asio::io_service io_service; for(;;) { std::stringstream portsrt; portsrt << port_; - asio::ip::tcp::resolver resolver(io_service); - asio::ip::tcp::resolver::query query( hostname_, portsrt.str()); - asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); - asio::ip::tcp::resolver::iterator end; + boost::asio::ip::tcp::resolver resolver(io_service); + boost::asio::ip::tcp::resolver::query query( hostname_, portsrt.str()); + boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); + boost::asio::ip::tcp::resolver::iterator end; - asio::ip::tcp::socket socket(io_service); - asio::error_code error = asio::error::host_not_found; + boost::asio::ip::tcp::socket socket(io_service); + boost::system::error_code error = boost::asio::error::host_not_found; while (error && endpoint_iterator != end) { socket.close(); socket.connect(*endpoint_iterator++, error); } if (error) - throw asio::system_error(error); + throw boost::system::system_error(error); for (;;) { boost::array buf; - asio::error_code error; + boost::system::error_code error; - size_t len = socket.read_some(asio::buffer(buf), error); + size_t len = socket.read_some(boost::asio::buffer(buf), error); - if (error == asio::error::eof) + if (error == boost::asio::error::eof) break; // Connection closed cleanly by peer. else if (error) - throw asio::system_error(error); // Some other error. + throw boost::system::system_error(error); // Some other error. OnRawData(buf.data(), len); } diff --git a/src/syncClient.h b/src/syncClient.h index d1b020a..f36b869 100644 --- a/src/syncClient.h +++ b/src/syncClient.h @@ -36,7 +36,7 @@ #include #include #include -#include +#include class SyncClient { diff --git a/src/syncServer.cpp b/src/syncServer.cpp index b2e4cf8..62b2cff 100644 --- a/src/syncServer.cpp +++ b/src/syncServer.cpp @@ -2,40 +2,39 @@ //using asio::ip::tcp; -SyncServer::SyncServer(asio::io_service& io_service, asio::ip::tcp::endpoint tcp_endpoint ) +SyncServer::SyncServer(boost::asio::io_service& io_service, boost::asio::ip::tcp::endpoint tcp_endpoint ) : acceptor_(io_service, tcp_endpoint) { - start_accept(); + start_accept(); } void SyncServer::start_accept() { - Lock lock(mutex_); - SyncTcpConnection::pointer new_connection = - SyncTcpConnection::create(acceptor_.io_service()); + Lock lock(mutex_); + SyncTcpConnection::pointer new_connection = + SyncTcpConnection::create(acceptor_.io_service()); conns_.push_back(new_connection); - - acceptor_.async_accept(new_connection->socket(), - boost::bind(&SyncServer::handle_accept, this, new_connection, - asio::placeholders::error)); + + acceptor_.async_accept(new_connection->socket(), + boost::bind(&SyncServer::handle_accept, this, new_connection, + boost::asio::placeholders::error)); } void SyncServer::send(std::string message) { - Lock lock(mutex_); -for(std::list::iterator it = conns_.begin() ;it != conns_.end(); ++it) { - (*it)->Send(message); - } - + Lock lock(mutex_); + for(std::list::iterator it = conns_.begin() ;it != conns_.end(); ++it) { + (*it)->Send(message); + } } void SyncServer::handle_accept(SyncTcpConnection::pointer new_connection, - const asio::error_code& error) + const boost::system::error_code& error) { - if (!error) - { - new_connection->onConnect=onConnect; - new_connection->start(); - start_accept(); - } + if (!error) + { + new_connection->onConnect=onConnect; + new_connection->start(); + start_accept(); + } } diff --git a/src/syncServer.h b/src/syncServer.h index d7317db..ed0d4fd 100644 --- a/src/syncServer.h +++ b/src/syncServer.h @@ -9,7 +9,7 @@ #include "threadUtils.hpp" -#include +#include #include #include "syncTcpConnection.h" @@ -18,15 +18,15 @@ class SyncServer { public: - SyncServer(asio::io_service& io_service, asio::ip::tcp::endpoint tcp_endpoint ); + SyncServer(boost::asio::io_service& io_service, boost::asio::ip::tcp::endpoint tcp_endpoint ); boost::function onConnect; std::list conns_; void send(std::string message); private: void start_accept(); void handle_accept(SyncTcpConnection::pointer new_connection, - const asio::error_code& error); + const boost::system::error_code& error); Mutex mutex_; //Mutex for list conns_ - asio::ip::tcp::acceptor acceptor_; + boost::asio::ip::tcp::acceptor acceptor_; }; #endif diff --git a/src/syncTcpConnection.cpp b/src/syncTcpConnection.cpp index dbd9ac0..5287468 100644 --- a/src/syncTcpConnection.cpp +++ b/src/syncTcpConnection.cpp @@ -1,6 +1,6 @@ #include "syncTcpConnection.h" #include -#include +#include #include #include @@ -14,10 +14,10 @@ #include "syncCommand.h" #include "buffer.h" - asio::ip::tcp::socket& SyncTcpConnection::socket() - { - return socket_; - } +boost::asio::ip::tcp::socket& SyncTcpConnection::socket() +{ + return socket_; +} void SyncTcpConnection::start() { @@ -26,17 +26,17 @@ void SyncTcpConnection::start() void SyncTcpConnection::Send(std::string message) { - asio::async_write(socket_, asio::buffer(message), + boost::asio::async_write(socket_, boost::asio::buffer(message), boost::bind(&SyncTcpConnection::handle_write, shared_from_this(), - asio::placeholders::error, - asio::placeholders::bytes_transferred)); + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); } -SyncTcpConnection::SyncTcpConnection(asio::io_service& io_service) +SyncTcpConnection::SyncTcpConnection(boost::asio::io_service& io_service) : socket_(io_service) { } -void SyncTcpConnection::handle_write(const asio::error_code& /*error*/, +void SyncTcpConnection::handle_write(const boost::system::error_code& /*error*/, size_t /*bytes_transferred*/) { } diff --git a/src/syncTcpConnection.h b/src/syncTcpConnection.h index 1ef9bb7..5af5276 100644 --- a/src/syncTcpConnection.h +++ b/src/syncTcpConnection.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include @@ -12,19 +12,19 @@ class SyncTcpConnection { public: typedef boost::shared_ptr pointer; - static pointer create(asio::io_service& io_service) + static pointer create(boost::asio::io_service& io_service) { return pointer(new SyncTcpConnection(io_service)); }; boost::function onConnect; - asio::ip::tcp::socket& socket(); + boost::asio::ip::tcp::socket& socket(); void start(); void Send(std::string message); private: - SyncTcpConnection(asio::io_service& io_service); + SyncTcpConnection(boost::asio::io_service& io_service); - void handle_write(const asio::error_code& /*error*/, + void handle_write(const boost::system::error_code & /*error*/, size_t /*bytes_transferred*/); - asio::ip::tcp::socket socket_; + boost::asio::ip::tcp::socket socket_; }; #endif -- cgit v1.2.3