Browse Source

Fixes and avoid sending on closed socket.

cl-refactor
Gav Wood 11 years ago
parent
commit
f5950073d2
  1. 38
      libethereum/PeerSession.cpp
  2. 5
      walleth/MainWin.cpp
  3. 4
      walleth/MainWin.h

38
libethereum/PeerSession.cpp

@ -430,16 +430,17 @@ void PeerSession::sendDestroy(bytes& _msg)
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)
if (m_socket.is_open())
ba::async_write(m_socket, ba::buffer(*buffer), [self, buffer](boost::system::error_code ec, std::size_t length)
{
cwarn << "Error sending: " << ec.message();
self->dropped();
}
// cbug << length << " bytes written (EC: " << ec << ")";
});
delete buffer;
if (ec)
{
cwarn << "Error sending: " << ec.message();
self->dropped();
}
// cbug << length << " bytes written (EC: " << ec << ")";
});
}
void PeerSession::send(bytesConstRef _msg)
@ -453,16 +454,17 @@ void PeerSession::send(bytesConstRef _msg)
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)
if (m_socket.is_open())
ba::async_write(m_socket, ba::buffer(*buffer), [self, buffer](boost::system::error_code ec, std::size_t length)
{
cwarn << "Error sending: " << ec.message();
self->dropped();
}
// cbug << length << " bytes written (EC: " << ec << ")";
});
delete buffer;
if (ec)
{
cwarn << "Error sending: " << ec.message();
self->dropped();
}
// cbug << length << " bytes written (EC: " << ec << ")";
});
}
void PeerSession::dropped()

5
walleth/MainWin.cpp

@ -11,6 +11,7 @@
#include <libethereum/Client.h>
#include <libethereum/Instruction.h>
#include <libethereum/FileSystem.h>
#include <libethereum/PeerServer.h>
#include "BuildInfo.h"
#include "MainWin.h"
#include "ui_Main.h"
@ -35,12 +36,12 @@ using eth::Secret;
using eth::Transaction;
// functions
using eth::asHex;
using eth::toHex;
using eth::assemble;
using eth::compileLisp;
using eth::disassemble;
using eth::formatBalance;
using eth::fromUserHex;
using eth::fromHex;
using eth::right160;
using eth::simpleDebugOut;
using eth::toLog2;

4
walleth/MainWin.h

@ -5,7 +5,7 @@
#include <QtCore/QAbstractListModel>
#include <QtCore/QMutex>
#include <QtWidgets/QMainWindow>
#include <libethereum/Common.h>
#include <libethereum/CommonEth.h>
namespace Ui {
class Main;
@ -76,7 +76,7 @@ public:
Q_INVOKABLE bool isNull(eth::Address _a) const { return !_a; }
Q_INVOKABLE eth::Address addressOf(QString _s) const { return eth::Address(_s.toStdString()); }
Q_INVOKABLE QString stringOf(eth::Address _a) const { return QString::fromStdString(eth::asHex(_a.asArray())); }
Q_INVOKABLE QString stringOf(eth::Address _a) const { return QString::fromStdString(eth::toHex(_a.asArray())); }
Q_INVOKABLE QString toAbridged(eth::Address _a) const { return QString::fromStdString(_a.abridged()); }
};

Loading…
Cancel
Save