Browse Source

Merge pull request #75 from programmerTim/develop

Fix bug where buffer was being deleted underneath async_write operation.
cl-refactor
Gav Wood 11 years ago
parent
commit
14d026565f
  1. 26
      libethereum/PeerNetwork.cpp
  2. 15
      windows/bootstrap.sh

26
libethereum/PeerNetwork.cpp

@ -483,19 +483,21 @@ bool PeerSession::checkPacket(bytesConstRef _msg)
void PeerSession::sendDestroy(bytes& _msg)
{
clogS(NetLeft) << RLP(bytesConstRef(&_msg).cropped(8));
std::shared_ptr<bytes> buffer = std::make_shared<bytes>();
swap(*buffer, _msg);
if (!checkPacket(bytesConstRef(&*buffer)))
if (!checkPacket(bytesConstRef(&_msg)))
{
cwarn << "INVALID PACKET CONSTRUCTED!";
}
ba::async_write(m_socket, ba::buffer(*buffer), [=](boost::system::error_code ec, std::size_t length)
auto self(shared_from_this());
bytes* buffer = new bytes(std::move(_msg));
ba::async_write(m_socket, ba::buffer(*buffer), [self,buffer](boost::system::error_code ec, std::size_t length)
{
delete buffer;
if (ec)
{
cwarn << "Error sending: " << ec.message();
dropped();
self->dropped();
}
// cbug << length << " bytes written (EC: " << ec << ")";
});
@ -504,17 +506,21 @@ void PeerSession::sendDestroy(bytes& _msg)
void PeerSession::send(bytesConstRef _msg)
{
clogS(NetLeft) << RLP(_msg.cropped(8));
std::shared_ptr<bytes> buffer = std::make_shared<bytes>(_msg.toBytes());
if (!checkPacket(_msg))
{
cwarn << "INVALID PACKET CONSTRUCTED!";
}
ba::async_write(m_socket, ba::buffer(*buffer), [=](boost::system::error_code ec, std::size_t length)
auto self(shared_from_this());
bytes* buffer = new bytes(_msg.toBytes());
ba::async_write(m_socket, ba::buffer(*buffer), [self,buffer](boost::system::error_code ec, std::size_t length)
{
delete buffer;
if (ec)
{
cwarn << "Error sending: " << ec.message();
dropped();
self->dropped();
}
// cbug << length << " bytes written (EC: " << ec << ")";
});
@ -568,7 +574,7 @@ void PeerSession::start()
void PeerSession::doRead()
{
auto self(shared_from_this());
m_socket.async_read_some(boost::asio::buffer(m_data), [this, self](boost::system::error_code ec, std::size_t length)
m_socket.async_read_some(boost::asio::buffer(m_data), [this,self](boost::system::error_code ec, std::size_t length)
{
if (ec)
{

15
windows/bootstrap.sh

@ -7,12 +7,25 @@
# - Visual Studio Express 2013 for Desktop
# - On PATH: bash, git, git-svn, curl, sed, 7z
error_exit() {
echo $1 1>&2
exit 1
}
for i in python perl curl git sed 7z; do
which $i &>/dev/null || error_exit "Could not find $i on PATH"
done
if [ ! -d "$VS120COMNTOOLS" ]; then
error_exit "Couldn't find Visual Studio 2013"
fi
if [[ ! $@ ]] || [ $1 == "fetch" ]; then
# fetch ethereum (develop branch)
if [ ! -d cpp-ethereum ]; then
(set -x; git clone https://github.com/ethereum/cpp-ethereum.git)
cd cpp-ethereum
(set -x; git checkout origin/develop)
(set -x; git checkout -b develop origin/develop)
cd ..
echo
fi

Loading…
Cancel
Save