Spinning Topp Logo BlackTopp Studios
inc
tcpsocket.h
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _networktcpsocket_h
42 #define _networktcpsocket_h
43 
44 #include "Network/socket.h"
45 
46 namespace Mezzanine
47 {
48  namespace Network
49  {
50  ///////////////////////////////////////////////////////////////////////////////
51  /// @brief A socket class using the TCP stream protocol.
52  ///////////////////////////////////////
53  class MEZZ_LIB TCPSocket : virtual public Socket
54  {
55  protected:
56  public:
57  /// @brief Class constructor.
58  TCPSocket();
59  /// @brief Class destructor.
60  virtual ~TCPSocket();
61 
62  ///////////////////////////////////////////////////////////////////////////////
63  // Utility
64 
65  /// @copydoc Socket::GetTransportLayerProtocol() const
66  TransportLayerProtocol GetTransportLayerProtocol() const;
67 
68  ///////////////////////////////////////////////////////////////////////////////
69  // Core Operations
70 
71  /// @brief Prepares this socket for incoming connections.
72  /// @param Backlog The amount of pending connections to keep track of in the queue before rejecting other connections.
73  /// @return Returns true if this put the socket into a listening state, false if there was a failure.
74  Boole Listen(const Integer Backlog = 5);
75  /// @brief Accepts an incoming connection from a remote host.
76  /// @param Address The address structure to be populated with connection data to the Accepted remote host.
77  /// @return Returns a pointer to a new socket specifically configured to talk to the Accepted remote host, or NULL if there was a failure.
78  TCPSocket* Accept(SystemAddress& Address);
79 
80  ///////////////////////////////////////////////////////////////////////////////
81  // Configuration
82 
83  /// @brief Sets whether or not a connection on this socket should use periodic packets during inactivity to ensure the connection remains valid.
84  /// @param Alive Whether or not the connection this socket has should be kept active.
85  void SetKeepAlive(const Boole Alive);
86  /// @brief Gets whether or not a connection on this socket should use periodic packets during inactivity to ensure the connection remains valid.
87  /// @return Returns true if connections should send periodic packets during periods of inactivity, false otherwise.
88  Boole GetKeepAlive() const;
89  /// @brief If enabled, the Nagle algorithm is disabled and TCP segments will be sent immediately.
90  /// @remarks In most cases you won't want to disable the delay. TCP is smart, let it do it's job. Overutilization of the network can create
91  /// it's own problems and that can easily be the case by using this option.
92  /// @param NoDelay If true, transmissions will be sent ASAP regardless of transmission size.
93  void SetNoDelay(const Boole NoDelay);
94  /// @brief Gets whether or not the Nagle algorithm is disabled.
95  /// @return Returns true if transmissions aren't delayed via the Nagle algorithm, false otherwise.
96  Boole GetNoDelay() const;
97  };//TCPSocket
98  }//Network
99 }//Mezzanine
100 
101 #endif
This is a basic socket interface for the transmission and retrieval of packets.
Definition: socket.h:152
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
TransportLayerProtocol
This is an enum listing for recognized protocols on Layer 4 of the OSI model.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
A socket class using the TCP stream protocol.
Definition: tcpsocket.h:53
A simple class that stores a complete set of information for establishing connections.
Definition: systemaddress.h:53