VCF::Socket Class Reference
#include <vcf/NetworkKit/Socket.h>
Inheritance diagram for VCF::Socket:

Public Types | |
| enum | SocketType { stStream, stStreamAsync, stDatagram, stDatagramAsync } |
| enum | { SelectNoWait = (uint32)0, SelectWaitForever = (uint32)-1 } |
| enum | SocketState { ssError = 0x0001, ssReadable = 0x0002, ssWriteable = 0x0004, ssConnected = 0x0010, ssListening = 0x0020, ssOpen = 0x0100, ssClosed = 0x0000 } |
| enum | SocketEvents { seClientConnected = 112491, seClientDisconnected, seReadyToRead, seReadyToWrite } |
Public Member Functions | |
| Socket () | |
| Creates an unconnected socket in stStream mode. | |
| Socket (const SocketType &socketType) | |
| Creates an unconnected socket of the requested type. | |
| Socket (unsigned short port) | |
| Creates a bound and listening socket in stStream mode. | |
| Socket (const String &host, unsigned short port) | |
| Creates a connected socket in stStream mode. | |
| virtual | ~Socket () |
| void | open () |
| Opens the socket for use and creates allocates any neccessary OS resoruces for the socket (depending on the peer implementation). | |
| void | close () |
| Closes the socket and frees up any underlying OS resources that were allocated for the socket by the previous call to open(). | |
| void | connect (const String &host, unsigned short port) |
| Connects to a specified host and port. | |
| void | listen (unsigned short port) |
| This will start the socket listening on the specified port. | |
| TCPSocket * | accept () |
| Accepts a new connection and returns a new TCP socket instance. | |
| void | setOptions (Dictionary &options) |
| Sets the options for a socket. | |
| Dictionary | getOptions () |
| Returns a dictionary containing the current options for the socket. | |
| IPAddress | getLocalHostIPAddress () |
| Returns the local ip address for this socket. | |
| IPAddress | getRemoteHostIPAddress () |
| Returns the remote ip address that this socket is connected to. | |
| unsigned short | getLocalPort () |
| unsigned short | getRemotePort () |
| SocketPeer * | getPeer () |
| SocketType | getSocketType () |
| Returns the socket type. | |
| bool | isReadable () const |
| bool | hasError () const |
| bool | isWriteable () const |
| bool | isConnected () const |
| bool | isListening () const |
| bool | isOpen () const |
| bool | isClosed () const |
| bool | pending () |
| Does a quick test to see if there is any readable or writeable data available for the socket. | |
| void | internal_setErrorState (bool val) |
| Do not call this method - for internal use only. | |
| void | internal_setReadable (bool val) |
| Do not call this method - for internal use only. | |
| void | internal_setWriteable (bool val) |
| Do not call this method - for internal use only. | |
| bool | wouldOperationBlock () |
| Indicates whether the current operation would block. | |
| void | selectFor (uint32 timeout, uint32 flags) |
| Perform a select, on this socket, for a specified timeout period, checking against some set of flags that will indicate whether or not we should look for readable, writeable, or error states. | |
Static Public Member Functions | |
| static bool | validateOptions (Dictionary &options) |
Public Attributes | |
| VCF::Delegate | SocketEventDelegate |
| ClientConnected | |
| ClientDisconnected | |
| VCF::Delegate | EventDelegate |
| ReadyToRead | |
| ReadyToWrite | |
Static Public Attributes | |
| static const String | soBlocking |
| This key indicates whether or not the socket is blocking or not. | |
| static const String | soBroadcast |
| Bool value. | |
| static const String | soDontLinger |
| Bool value. | |
| static const String | soDontRoute |
| Bool value. | |
| static const String | soKeepAlive |
| Bool value. | |
| static const String | soRecvBuffer |
| int value | |
| static const String | soReuseAddress |
| Bool value. | |
| static const String | soSendBuffer |
| int value | |
Protected Member Functions | |
| Socket (SocketPeer *peer) | |
| Creates a socket from an existing peer intance. | |
Protected Attributes | |
| SocketPeer * | peer_ |
| SocketType | type_ |
| int | state_ |
Member Enumeration Documentation
|
|
|
|
|
|
|
|
|
|
Constructor & Destructor Documentation
|
|
Creates an unconnected socket in stStream mode.
|
|
|
Creates an unconnected socket of the requested type.
|
|
|
Creates a bound and listening socket in stStream mode.
|
|
||||||||||||
|
Creates a connected socket in stStream mode. A connection is made to the specified host and port |
|
|
|
|
|
Creates a socket from an existing peer intance. This is used primarily by the accept() method. |
Member Function Documentation
|
|
Accepts a new connection and returns a new TCP socket instance. Assumes the listen() call has already occurred. If it has not then an exception is thrown by the underlying peer implementation. This method will block until a socket connection has been detected unless the instance has been set to non blocking. This is only valid when called by a TCP socket.
|
|
|
Closes the socket and frees up any underlying OS resources that were allocated for the socket by the previous call to open().
|
|
||||||||||||
|
Connects to a specified host and port. If the peer is unable to connect, then a SocketException exception is thrown.
|
|
|
Returns the local ip address for this socket.
|
|
|
|
|
|
Returns a dictionary containing the current options for the socket.
|
|
|
|
|
|
Returns the remote ip address that this socket is connected to.
|
|
|
|
|
|
Returns the socket type. Can be one of the SocketType enumeration values.
|
|
|
|
|
|
Do not call this method - for internal use only.
|
|
|
Do not call this method - for internal use only.
|
|
|
Do not call this method - for internal use only.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This will start the socket listening on the specified port. This can be called for either a UDP or TCP socket, with the appropriate underlying calls to bind and/or listen made as neccessary. |
|
|
Opens the socket for use and creates allocates any neccessary OS resoruces for the socket (depending on the peer implementation). If it was alread open, then it is first closed and then opened. Once this is called the socket's state will be set to Socket::ssOpen. |
|
|
Does a quick test to see if there is any readable or writeable data available for the socket.
|
|
||||||||||||
|
Perform a select, on this socket, for a specified timeout period, checking against some set of flags that will indicate whether or not we should look for readable, writeable, or error states. When this function returns, the socket's state may change depending on the flags specified and the result of the internal call to select. After returning you may call the isReadable(), isWriteable(), or hasError() methods to determine the current state. For example: Socket s("foobar.com", 1234 ); s.selectFor( 120, Socket::ssReadable ); if ( s.isReadable() ) { //do something, such as reading data from the //socket... }
|
|
|
Sets the options for a socket. The options are stored as a dictionary of items, with the keys being 1 or more values represented by the Socket::soXXX const string variables. The values are VariantData instances whose precise meaning depends on the key. For example, if you specify the Socket::soBlocking key, then the value is bool, indicating whether or not the socket should be set to blocking mode.
|
|
|
|
|
|
Indicates whether the current operation would block. Assumes a non blocking socket. This is roughly equivalent to getting a an EWOULDBLOCK or WSAEWOULDBLOCK error number.
|
Member Data Documentation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This key indicates whether or not the socket is blocking or not. It's value type is a bool. |
|
|
Bool value.
|
|
|
|
|
|
Bool value.
|
|
|
Bool value.
|
|
|
Bool value.
|
|
|
int value
|
|
|
Bool value.
|
|
|
int value
|
|
|
|
|
|
|
The documentation for this class was generated from the following file:
- vcf/NetworkKit/Socket.h
