-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor some stuff out of Client into Connection
so it can be shared with Server at some point also do some error handling on startup message
- Loading branch information
Showing
6 changed files
with
104 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2013 - Cody Cutrer | ||
|
||
#include <mordor/predef.h> | ||
|
||
#include "pghottub/connection.h" | ||
|
||
#include <mordor/assert.h> | ||
#include <mordor/streams/buffered.h> | ||
#include <mordor/endian.h> | ||
|
||
using namespace Mordor; | ||
|
||
namespace PgHotTub { | ||
|
||
Connection::Connection(Stream::ptr stream) | ||
{ | ||
MORDOR_ASSERT(stream->supportsRead()); | ||
MORDOR_ASSERT(stream->supportsWrite()); | ||
MORDOR_ASSERT(!stream->supportsSeek()); | ||
m_stream.reset(new BufferedStream(stream)); | ||
} | ||
|
||
void | ||
Connection::readV2Message(V2MessageType &type, Buffer &message) | ||
{ | ||
unsigned int length; | ||
m_stream->read(&length, 4u); | ||
length = byteswap(length); | ||
if (length < 8) | ||
MORDOR_THROW_EXCEPTION(MessageTooShort()); | ||
|
||
m_stream->read(&type, 4u); | ||
type = byteswap(type); | ||
|
||
if (length > 8) | ||
m_stream->read(message, length - 8); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2013 - Cody Cutrer | ||
|
||
#include <boost/noncopyable.hpp> | ||
|
||
#include <mordor/exception.h> | ||
|
||
namespace Mordor { | ||
struct Buffer; | ||
class Stream; | ||
} | ||
|
||
namespace PgHotTub { | ||
|
||
class Connection : boost::noncopyable | ||
{ | ||
public: | ||
struct MessageTooShort : virtual Mordor::Exception {}; | ||
|
||
protected: | ||
enum V2MessageType | ||
{ | ||
SSL_REQUEST = 80877103, | ||
STARTUP_REQUEST_V2 = 0x00020000, | ||
STARTUP_REQUEST_V3 = 0x00030000 | ||
}; | ||
|
||
enum V3MessageType | ||
{ | ||
}; | ||
|
||
protected: | ||
Connection(boost::shared_ptr<Mordor::Stream> stream); | ||
|
||
void readV2Message(V2MessageType &type, Mordor::Buffer &message); | ||
void readV3Message(V3MessageType &type, Mordor::Buffer &message); | ||
|
||
protected: | ||
boost::shared_ptr<Mordor::Stream> m_stream; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.