TCP-specific implementation of the MAbstractConnection interface.
Inheritance:
Public Methods
-
CTCPConnection(const std::string& aIface, const std::string& aPluginBase)
- Default constructor.
-
bool GetInterfaces()
- Checks if required interface is found.
-
~CTCPConnection()
- Default destructor.
-
bool Connect(const std::string& aAddress, int aPort)
- Connects to a remote device.
-
bool Disconnect()
- Kills the existing connection.
-
void Close()
- Explicitly closes the socket.
-
int Write(const void* aOutBuf, int aLength)
- Sends data to the other end of the connection.
-
int Read(void* aInBuf, int aLength)
- Reads data from an open connection.
-
const std::string& GetRemoteAddress()
- Returns connection's remote address.
-
int GetFd()
- Returns connection's file descriptor.
-
bool Listen()
- Sets the connection to the listening state.
-
bool Listen(int aPort)
- Sets the connection to the listening state.
-
MAbstractConnection* AcceptL()
- Accepts the incoming connection and returns a new connection object.
-
bool IsListening()
- Tells if the connection is listening.
-
bool IsConnected()
- Tells if the connection is established.
-
bool HasData()
- Tells if the connection has data waiting
Documentation
TCP-specific implementation of the MAbstractConnection interface.
This class offers a unified interface through what TCP can be used
like any other transport medium in the PeerHood environment. Note that no
instances of this class should be created directly. Instead, use the
provided PeerHood factory class.
CTCPConnection(const std::string& aIface, const std::string& aPluginBase)
-
Default constructor, sets the initial vatiables to their default values
and creates a new TCP socket.
- Parameters:
- aIface - interface which is wanted to use
aPluginBase - plugin which uses this class (must be GPRS or WLAN)
- Returns:
- none
bool GetInterfaces()
-
Checks if required interface is found. This method
checks if the interface defined in the constructor could
be found.
- Returns:
- false if interface couldn't be found
~CTCPConnection()
-
Default desttructor, deletes allocated variables
- Returns:
- none
bool Connect(const std::string& aAddress, int aPort)
-
Connects to a remote device for a given address and port
which is PeerHood's default PSM.
- Parameters:
- aAddress - The destination address.
aPort - The destination port.
- Returns:
- true if the connection could be established
bool Disconnect()
-
Kills the existing connection. If there's no connection or it could not
be closed in a controlled way then the error code is returned. The existing
connection will be closed regardless of the return value.
- Returns:
- true if the connection was dropped in a controlled manner
void Close()
-
Explicitly closes the socket without any additional state checking,
i.e. this function will execute even if there's no existing connection.
This function is used by the PeerHood engine to ensure that no file
descriptors are leaked.
- Returns:
- none
int Write(const void* aOutBuf, int aLength)
-
Sends data to the other end of the connection. Note that this
function is not endianess-safe.
- Parameters:
- aOutBuf - Buffer containing the data that should be written.
aLength - The number of bytes to be written.
- Returns:
- the number of bytes written or -1 in the case of an error
int Read(void* aInBuf, int aLength)
-
Reads data from an open connection. Just like
<code>Read</code> this function is not endianess-safe so it should be
treated more like a standard Posix sequential socket.
- Parameters:
- aInBuf - Buffer where the data is read to.
aLength - The number of bytes that should be read.
- Returns:
- the number of bytes read or -1 in the case of an error
const std::string& GetRemoteAddress()
-
Returns connection's remote address. Note that the existence of the
address doesn't mean that there's a connection established.
- Returns:
- connection's remote address
int GetFd()
-
Returns connection's file descriptor. Other classes can have a direct
access to the connection's socket (or similar entity) via this function's
return value.
- Returns:
- connection's file descriptor or -1 if one isn't available
bool Listen()
-
Sets the connection to the listening state. This function must be
called before any incoming connections targeted to this object can be
accepted. This function will always listen the connection type's default
port. If some other port is needed then the <code>Listen(int aPort)</code>
should be used instead.
- Returns:
- true if successfull
bool Listen(int aPort)
-
Sets the connection to the listening state. This function must be
called before any incoming connections targeted to this object can be
accepted.
- Parameters:
- aPort - The port that should be listened.
- Returns:
- true if successfull
MAbstractConnection* AcceptL()
-
Accepts the incoming connection and returns a new connection object. If
accepting fails then NULL is returned.
- Returns:
- new connection object or NULL in the case of an error
bool IsListening()
-
Tells if the connection is in the listening state or not.
- Returns:
- true if the connection is in the listening state
bool IsConnected()
-
Tells if the connection is established or not.
- Returns:
- true if the connection is established
bool HasData()
-
Waits for the connection to have data to read, and returns true
- Returns:
- true if the data is ready
- This class has no child classes.
- See Also:
- MAbstractConnection
Alphabetic index HTML hierarchy of classes or Java
This page was generated with the help of DOC++.