#include <Socket.hpp>


Public Member Functions | |
| boost::shared_ptr < Socket > | accept () |
| Accept a connection on a socket. | |
| void | bind (int Port) |
| Bind a socket to a port. | |
| void | closeSocket () |
| Close the socket. | |
| void | connect (std::string Host, int Port) |
| Connect to a server. | |
| void | createSocket (SocketDomain Domain=SOCKET_INTERNET, SocketType Type=SOCKET_STREAM) |
| Create a socket. | |
| std::string | getAddress () const |
| Get the socket's address. | |
| int | getOldSocket () const |
| Get the old socket (what it was before disconnect). | |
| int | getSocket () const |
| Get the socket. | |
| bool | isSocketValid () const |
| Test if a socket is valid or not. | |
| void | listen () |
| Listen on a socket. | |
| void | processEvents () |
| Process events on the socket. | |
| int | readIntoBuffer (DynamicBuffer< char > &Buffer) |
| Read from the socket into a buffer. | |
| void | setEventWatcher (SocketEventWatcher *pWatcher) |
| Set the event watcher. | |
| void | setMessageMode (bool Enabled) |
| Enable automatic message handling mode? | |
| void | setTo (Socket const &SocketToBecome) |
| Initialize from another socket. | |
| void | shutdown () |
| Shutdown socket processing. | |
| int | write (const char *Buffer, int BufLen) |
| Write date to the socket. | |
| void | writeMessage (std::string const &Message, bool FormatMessage=true) |
| Write message to socket. | |
| Socket () | |
| Default Constructor. | |
| Socket (Socket const &InitFrom) | |
| Init Constructor. | |
| virtual | ~Socket () |
| Destructor. | |
Protected Member Functions | |
| void | addToMessageBuffer (char *Data, int BufLen) |
| Add data to the message buffer. | |
| void | handleSocketDisconnect () |
| Handle a socket disconnect. | |
| void | handleSocketRead (DynamicBuffer< char > &ReadBuffer) |
| Handle a socket read. | |
| void | init () |
| Initialize the socket. | |
| int | read (char *Buffer, int BufLen) |
| Read from a socket. | |
| void | setAddress () |
| Set the socket's address. | |
| void | threadProcRead () |
| Thread procedure for reading from the socket. | |
Protected Attributes | |
| std::string | mAddress |
| The socket's address. | |
| int | mBacklog |
| Listen with backlog enabled? | |
| SocketDomain | mDomain |
| Socket domain. | |
| SocketEventWatcher * | mpEventWatcher |
| Object that listens for events on this socket. | |
| int | mOldSocket |
| The old socket. | |
| int | mPort |
| Socket port. | |
| bool | mProcessing |
| Keep processing? | |
| SocketProtocol | mProtocol |
| Socket protocol. | |
| DynamicBuffer< char > | mMessageBuffer |
| Buffer that holds messages. | |
| bool | mMessageMode |
| Do automatic message processing? | |
| struct sockaddr_in | mSockAddr |
| The socket addres structure. | |
| socklen_t | mSockAddrLen |
| Length of the socket address. | |
| int | mSocket |
| The socket. | |
| SocketType | mType |
| Socket type. | |
Classes | |
| struct | SocketReadThreadProc |
This class represents an abstraction to the BSD socket interface
Definition at line 120 of file Socket.hpp.
| Socket::Socket | ( | Socket const & | InitFrom | ) |
Init Constructor.
Default Constructor.
Definition at line 96 of file Socket.cpp.
References init(), mpEventWatcher, and setTo().
| boost::shared_ptr< Socket > Socket::accept | ( | ) |
Accept a connection on a socket.
Accept connections.
Definition at line 120 of file Socket.cpp.
References cdbg1, mPort, mProcessing, mSocket, POLL_TIMEOUT, Socket(), and SOCKET_ERROR.
Referenced by H::SocketServer::threadProc().
| void Socket::bind | ( | int | Port | ) |
Bind a socket to a port.
| Port | The port to bind to |
Definition at line 196 of file Socket.cpp.
References mPort, mSockAddr, mSocket, and mType.
Referenced by H::SocketServer::acceptConnections().
| void Socket::connect | ( | std::string | Host, | |
| int | Port | |||
| ) |
Connect to a server.
Connect to a server on Port at Host.
| Host | The server to connect to | |
| Port | The port to connect to |
Definition at line 237 of file Socket.cpp.
References cdbg4, closeSocket(), mpEventWatcher, mPort, mSockAddr, mSocket, H::SocketEventWatcher::onSocketConnect(), setAddress(), and SOCKET_ERROR.
Referenced by H::SocketClient::connectToServer().
| std::string Socket::getAddress | ( | ) | const |
Get the socket's address.
Get the socket's address / hostname.
Definition at line 299 of file Socket.cpp.
References mAddress.
| int Socket::getOldSocket | ( | ) | const [virtual] |
Get the old socket (what it was before disconnect).
Implements H::SocketInterface.
Definition at line 307 of file Socket.cpp.
References mOldSocket.
| int Socket::getSocket | ( | ) | const [virtual] |
Get the socket.
Implements H::SocketInterface.
Definition at line 315 of file Socket.cpp.
References mSocket.
| bool Socket::isSocketValid | ( | ) | const |
Test if a socket is valid or not.
Definition at line 355 of file Socket.cpp.
References mSocket, and SOCKET_ERROR.
Referenced by threadProcRead().
| int Socket::readIntoBuffer | ( | DynamicBuffer< char > & | Buffer | ) |
Read from the socket into a buffer.
Read from the socket, info a buffer.
| Buffer | The buffer to read into |
Definition at line 404 of file Socket.cpp.
References H::DynamicBuffer< DataType >::addToBuffer(), addToMessageBuffer(), cdbg, handleSocketDisconnect(), PACKET_SIZE, and read().
Referenced by threadProcRead().
| void Socket::setEventWatcher | ( | SocketEventWatcher * | pWatcher | ) |
Set the event watcher.
| pWatcher | The event watcher |
Definition at line 451 of file Socket.cpp.
References mpEventWatcher.
Referenced by H::SocketClient::SocketClient().
| void Socket::setMessageMode | ( | bool | Enabled | ) |
Enable automatic message handling mode?
| Enabled | True if message mode should be enabled |
Definition at line 459 of file Socket.cpp.
References mMessageMode.
| void Socket::setTo | ( | Socket const & | SocketToBecome | ) |
| void Socket::shutdown | ( | ) |
Shutdown socket processing.
Shutdown all socket processing.
Reimplemented in H::SocketServer, and GizmodLibVisualPlugin.
Definition at line 483 of file Socket.cpp.
References mProcessing.
Referenced by ~Socket().
| int Socket::write | ( | const char * | Buffer, | |
| int | BufLen | |||
| ) |
Write date to the socket.
Write data to the socket.
| Buffer | The data to send | |
| BufLen | Length of data to send |
Definition at line 522 of file Socket.cpp.
References mSocket.
Referenced by writeMessage().
| void Socket::writeMessage | ( | std::string const & | Message, | |
| bool | FormatMessage = true | |||
| ) |
Write message to socket.
| Message | The message to write | |
| FormatMessage | Format the massage for easy receiving |
It also formats the message for easy decomposition by SocketServer
Definition at line 552 of file Socket.cpp.
References STOP_CODON, and write().
Referenced by H::SocketClient::sendToServer().
| void Socket::addToMessageBuffer | ( | char * | Data, | |
| int | BufLen | |||
| ) | [protected] |
Add data to the message buffer.
Add to the message buffer.
Definition at line 159 of file Socket.cpp.
References H::DynamicBuffer< DataType >::addToBuffer(), H::DynamicBuffer< DataType >::clear(), H::DynamicBuffer< DataType >::getBuffer(), H::DynamicBuffer< DataType >::length(), mMessageBuffer, mMessageMode, mpEventWatcher, H::SocketEventWatcher::onSocketMessage(), and STOP_CODON_CHAR.
Referenced by readIntoBuffer().
| void Socket::init | ( | ) | [protected] |
Initialize the socket.
Init the socket.
Reimplemented in GizmodLibVisualPlugin.
Definition at line 339 of file Socket.cpp.
References DEFAULT_BACKLOG, mBacklog, mDomain, mMessageMode, mPort, mProcessing, mProtocol, mSockAddrLen, mSocket, mType, SOCKET_ERROR, H::SOCKET_INTERNET, H::SOCKET_PROTO_TCP, and H::SOCKET_STREAM.
Referenced by closeSocket(), and Socket().
| int Socket::read | ( | char * | Buffer, | |
| int | BufLen | |||
| ) | [protected] |
Read from a socket.
| Buffer | The buffer to read into | |
| BufLen | The length of the buffer |
Definition at line 380 of file Socket.cpp.
References handleSocketDisconnect(), and mSocket.
Referenced by readIntoBuffer().
| void Socket::setAddress | ( | ) | [protected] |
Set the socket's address.
Set the socket's address from internal structures.
Definition at line 443 of file Socket.cpp.
References mAddress, and mSockAddr.
Referenced by connect().
1.5.3