Transition into ready state.

This commit is contained in:
Ian Gulliver
2015-02-07 13:32:49 -08:00
parent 55ca78194c
commit 36bdebe5e0
2 changed files with 22 additions and 2 deletions

View File

@@ -182,7 +182,16 @@ void CryptoPubServerConnection::OnReadable_(struct bufferevent* bev, void* this_
void CryptoPubServerConnection::OnReadable() { void CryptoPubServerConnection::OnReadable() {
char buf[UINT16_MAX]; char buf[UINT16_MAX];
int bytes = bufferevent_read(bev_, buf, UINT16_MAX); int bytes = bufferevent_read(bev_, buf, UINT16_MAX);
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(std::string(buf, bytes))); const std::string input(buf, bytes);
if (state_ == AWAITING_HANDSHAKE) {
OnHandshake(input);
return;
}
}
void CryptoPubServerConnection::OnHandshake(const std::string& input) {
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(input));
if (!decoded.get()) { if (!decoded.get()) {
// TODO: re-buffer? // TODO: re-buffer?
return; return;
@@ -288,7 +297,16 @@ void CryptoPubClient::OnReadable_(struct bufferevent* bev, void* this__) {
void CryptoPubClient::OnReadable() { void CryptoPubClient::OnReadable() {
char buf[UINT16_MAX]; char buf[UINT16_MAX];
int bytes = bufferevent_read(bev_, buf, UINT16_MAX); int bytes = bufferevent_read(bev_, buf, UINT16_MAX);
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(std::string(buf, bytes))); const std::string input(buf, bytes);
if (state_ == AWAITING_HANDSHAKE) {
OnHandshake(input);
return;
}
}
void CryptoPubClient::OnHandshake(const std::string& input) {
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(input));
if (!decoded.get()) { if (!decoded.get()) {
// TODO: re-buffer? // TODO: re-buffer?
return; return;

View File

@@ -49,6 +49,7 @@ class CryptoPubServerConnection : public CryptoBase {
private: private:
static void OnReadable_(struct bufferevent* bev, void* this__); static void OnReadable_(struct bufferevent* bev, void* this__);
void OnReadable(); void OnReadable();
void OnHandshake(const std::string& input);
static void OnError_(struct bufferevent* bev, const short what, void* this__); static void OnError_(struct bufferevent* bev, const short what, void* this__);
void OnError(const short what); void OnError(const short what);
@@ -79,6 +80,7 @@ class CryptoPubClient : public CryptoBase {
private: private:
static void OnReadable_(struct bufferevent* bev, void* this__); static void OnReadable_(struct bufferevent* bev, void* this__);
void OnReadable(); void OnReadable();
void OnHandshake(const std::string& input);
static void OnConnectOrError_(struct bufferevent* bev, const short what, void* this__); static void OnConnectOrError_(struct bufferevent* bev, const short what, void* this__);
void OnConnect(); void OnConnect();
void OnError(); void OnError();