-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a8aab3
commit 747613f
Showing
2 changed files
with
88 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Yojimbo Client/Server Network Library. | ||
Copyright © 2016 - 2024, Mas Bandwidth LLC. | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef YOJIMBO_CONNECTION_H | ||
#define YOJIMBO_CONNECTION_H | ||
|
||
#include "yojimbo_config.h" | ||
|
||
namespace yojimbo | ||
{ | ||
/// Connection error level. | ||
|
||
enum ConnectionErrorLevel | ||
{ | ||
CONNECTION_ERROR_NONE = 0, ///< No error. All is well. | ||
CONNECTION_ERROR_CHANNEL, ///< A channel is in an error state. | ||
CONNECTION_ERROR_ALLOCATOR, ///< The allocator is an error state. | ||
CONNECTION_ERROR_MESSAGE_FACTORY, ///< The message factory is in an error state. | ||
CONNECTION_ERROR_READ_PACKET_FAILED, ///< Failed to read packet. Received an invalid packet? | ||
}; | ||
|
||
/** | ||
Sends and receives messages across a set of user defined channels. | ||
*/ | ||
|
||
class Connection | ||
{ | ||
public: | ||
|
||
Connection( Allocator & allocator, MessageFactory & messageFactory, const ConnectionConfig & connectionConfig, double time ); | ||
|
||
~Connection(); | ||
|
||
void Reset(); | ||
|
||
bool CanSendMessage( int channelIndex ) const; | ||
|
||
bool HasMessagesToSend( int channelIndex ) const; | ||
|
||
void SendMessage( int channelIndex, Message * message, void *context = 0); | ||
|
||
Message * ReceiveMessage( int channelIndex ); | ||
|
||
void ReleaseMessage( Message * message ); | ||
|
||
bool GeneratePacket( void * context, uint16_t packetSequence, uint8_t * packetData, int maxPacketBytes, int & packetBytes ); | ||
|
||
bool ProcessPacket( void * context, uint16_t packetSequence, const uint8_t * packetData, int packetBytes ); | ||
|
||
void ProcessAcks( const uint16_t * acks, int numAcks ); | ||
|
||
void AdvanceTime( double time ); | ||
|
||
ConnectionErrorLevel GetErrorLevel() { return m_errorLevel; } | ||
|
||
private: | ||
|
||
Allocator * m_allocator; ///< Allocator passed in to the connection constructor. | ||
MessageFactory * m_messageFactory; ///< Message factory for creating and destroying messages. | ||
ConnectionConfig m_connectionConfig; ///< Connection configuration. | ||
Channel * m_channel[MaxChannels]; ///< Array of connection channels. Array size corresponds to m_connectionConfig.numChannels | ||
ConnectionErrorLevel m_errorLevel; ///< The connection error level. | ||
}; | ||
} | ||
|
||
#endif // #ifndef YOJIMBO_CONNECTION_H |