Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F129998
SocketNetworkSystem.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
SocketNetworkSystem.h
View Options
#ifndef _SOCKETNETWORKSYSTEM_H_
#define _SOCKETNETWORKSYSTEM_H_
#include
<echo/Network/NetRedefinitions.h>
#include
<echo/Network/NetworkManager.h>
#include
<echo/Network/NetworkSystem.h>
#include
<echo/Kernel/TaskThread.h>
#include
<echo/Kernel/Mutex.h>
#include
<list>
#include
<map>
namespace
Echo
{
class
Connection
;
class
ConnectionDetails
;
class
IncomingConnectionListener
;
class
SocketNetworkSystem
:
public
NetworkSystem
{
protected
:
class
SocketThreadTask
;
Mutex
mConnectionsMutex
;
std
::
map
<
Socket
,
shared_ptr
<
Connection
>
>
mConnections
;
std
::
map
<
Socket
,
IncomingConnectionListener
*
>
mIncomingConnectionListeners
;
std
::
vector
<
TaskThread
*
>
mThreads
;
std
::
vector
<
SocketThreadTask
*
>
mSocketThreadTasks
;
std
::
map
<
Socket
,
SocketThreadTask
*
>
mSocketThreadTaskConnectionLookup
;
bool
mStarted
;
//Read set for listen and read data
//Write set for connect and write data
//except for connect failed
//Each SocketThreadTask can monitor up to FD_SETSIZE
class
SocketThreadTask
:
public
Task
{
public
:
SocketThreadTask
(
SocketNetworkSystem
*
s
);
~
SocketThreadTask
();
bool
AddSocket
(
Socket
s
);
bool
RemoveSocket
(
Socket
s
);
void
EnableWriteCheck
(
Socket
s
);
void
DisableWriteCheck
(
Socket
s
);
void
Update
(
Seconds
lastFrameTime
);
private
:
void
HandleSelectError
(
int
code
);
Mutex
mPendingSocketsMutex
;
std
::
list
<
Socket
>
mAllSockets
;
std
::
vector
<
Socket
>
mPendingSockets
;
std
::
vector
<
Socket
>
mPendingRemovalSockets
;
std
::
vector
<
Socket
>
mPendingWriteDisableSockets
;
std
::
vector
<
Socket
>
mPendingWriteEnableSockets
;
fd_set
mReadSet
;
fd_set
mWriteSet
;
fd_set
mExceptSet
;
u32
mCount
;
SocketNetworkSystem
*
mSystem
;
};
private
:
friend
class
SocketThreadTask
;
void
CheckForTimeout
(
Socket
s
);
void
ReadNotify
(
Socket
s
);
void
WriteNotify
(
Socket
s
);
void
ExceptNotify
(
Socket
s
);
bool
IsSocketConnected
(
Socket
s
);
SocketThreadTask
*
CreateThreadTask
();
/**
* Attempts to accept a connection.
* @returns false if the socket is not a listening socket, otherwise true.
*/
bool
AcceptConnection
(
Socket
s
);
public
:
struct
InterfaceInformation
{
std
::
string
mHostname
;
std
::
string
mIPAddress
;
std
::
string
mSubnetMask
;
std
::
string
mGateway
;
std
::
string
mDNS1
;
std
::
string
mDNS2
;
std
::
string
mMacAddress
;
};
SocketNetworkSystem
(
NetworkManager
&
networkManager
);
~
SocketNetworkSystem
();
//Initialise the Network System. Perform initialisation/allocations here
bool
Initialise
();
//Start is called when ENetwork begins execution. This is a good
//point to execute any threads.
bool
Start
();
void
CleanUp
();
void
DisconnectAll
();
//This method should fill outSupportedConnectionTypes with any connection types this system supports.
//Common connection types include, Passive and Direct
void
GetSupportedConnectionTypes
(
std
::
vector
<
std
::
string
>&
outSupportedConnectionTypes
);
//This method should fill outAdditionalInformation with any additional information required or optional
//for each of the supported connection types. Each entry in this vector should correlate with each
//corresponding element in the vector in GetSupportedConnectionTypes().
void
GetAdditionalConnectionInformationFormat
(
std
::
vector
<
std
::
string
>&
outAdditionalInformation
);
static
bool
GetInterfaceInformation
(
std
::
vector
<
InterfaceInformation
>&
outInterfaceInformation
);
//Perform an Asynchronous Listen. IMPORTANT: This function should not block
bool
Listen
(
IncomingConnectionListener
*
listener
,
const
ConnectionDetails
&
connectionDetails
);
//Perform an Asynchronous Connect. IMPORTANT: This function should not block
shared_ptr
<
Connection
>
Connect
(
const
ConnectionDetails
&
connectionDetails
,
Connection
::
ConnectCallback
connectionCallback
,
Connection
::
DisconnectCallback
disconnectCallback
);
void
UpdateSocket
(
Socket
s
,
shared_ptr
<
Connection
>
connection
);
void
EnableSocketWriteCheck
(
Socket
s
);
void
DisableSocketWriteCheck
(
Socket
s
);
//Returns true on success, or false if there was an error
bool
SetSocketBlockingEnabled
(
int
fd
,
bool
blocking
);
void
CleanSocket
(
Socket
s
);
/**
* Attempts to get the host IP by name or string IP.
* @param hostNameOrIP The hostname or IP address as a string, e.g. www.emblem.net.au or 192.168.1.1.
* @param output The IPv4 address will be written to this value upon success. The value is not modified
* if there is an error.
* @return false if the DNS lookup failed.
*/
static
bool
GetHostByName
(
const
std
::
string
&
hostnameOrIP
,
u32
&
output
);
static
bool
HandleError
(
int
code
);
};
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Mon, May 19, 11:44 AM (16 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
76742
Default Alt Text
SocketNetworkSystem.h (4 KB)
Attached To
Mode
rEE Echo 3
Attached
Detach File
Event Timeline
Log In to Comment