|
#include <CSocket.h>

Public Types | |
| enum | CSocketOpenMode { SOM_CREATE, SOM_CONNECT, SOM_BIND } |
| A mode to open a socket, one of. More... | |
Public Member Functions | |
| CSocket (int32_t domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0) | |
| Constructor. | |
| virtual | ~CSocket () |
| Destructor. | |
| int | handle () const |
| Returns socket handle. | |
| void | attach (SOCKET socketHandle) |
| Attaches socket handle. | |
| void | host (std::string hostName) |
| Sets the host name. | |
| std::string | host () const |
| Returns the host name. | |
| void | port (int32_t portNumber) |
| Sets the port number. | |
| int32_t | port () const |
| Returns the current port number. | |
| void | open_addr (CSocketOpenMode openMode=SOM_CREATE, sockaddr_in *addr=0L) |
| Opens the socket connection by address. | |
| virtual void | open (std::string hostName="", int32_t port=0, CSocketOpenMode openMode=SOM_CONNECT) |
| Opens the client socket connection by host and port. | |
| void | listen (int32_t portNumber=0) |
| Opens the server socket connection on port (binds/listens). | |
| void | accept (int &clientSocketFD, struct sockaddr_in &clientInfo) |
| In server mode, waits for the incoming connection. | |
| virtual void | close () |
| Closes the socket connection. | |
| bool | active () const |
| Returns the current socket state. | |
| int32_t | control (int flag, uint32_t *check) |
| Calls Unix fcntl() or Windows ioctlsocket(). | |
| void | setOption (int level, int option, int value) throw (sptk::CException) |
| Sets socket option value Throws an error if not succeeded. | |
| void | getOption (int level, int option, int &value) throw (sptk::CException) |
| Gets socket option value. | |
| int32_t | recv (void *buffer, uint32_t size) |
| Reads data from the socket in regular or TLS mode. | |
| int32_t | send (const void *buffer, uint32_t len) |
| Reads data from the socket in regular or TLS mode. | |
| uint32_t | readLine (char *buffer, uint32_t size) |
| Reads one line (terminated with CRLF) from the socket into existing memory buffer. | |
| uint32_t | readLine (CBuffer &buffer) |
| Reads one line (terminated with CRLF) from the socket into existing memory buffer. | |
| uint32_t | readLine (std::string &s) |
| Reads one line (terminated with CRLF) from the socket into string. | |
| uint32_t | read (char *buffer, uint32_t size, sockaddr_in *from=NULL) |
| Reads data from the socket. | |
| uint32_t | read (CBuffer &buffer, sockaddr_in *from=NULL) |
| Reads data from the socket into memory buffer. | |
| uint32_t | write (const char *buffer, uint32_t size, const sockaddr_in *peer=0) |
| Writes data to the socket. | |
| uint32_t | write (const CBuffer &buffer) |
| Writes data to the socket. | |
| bool | readyToRead (uint32_t waitmsec) |
| Reports true if socket is ready for reading from it. | |
| bool | readyToWrite () |
| Reports true if socket is ready for writing to it. | |
| CSocket & | operator<< (const std::string &) |
| Stream std::string input. | |
| CSocket & | operator>> (std::string &) |
| Stream std::string output. | |
Protected Member Functions | |
| char | getChar () |
| Reads a single char from the socket. | |
Protected Attributes | |
| SOCKET | m_sockfd |
| Socket internal (OS) handle. | |
| int32_t | m_domain |
| Socket domain type. | |
| int32_t | m_type |
| Socket type. | |
| int32_t | m_protocol |
| Socket protocol. | |
| std::string | m_host |
| Host name. | |
| int32_t | m_port |
| Port number. | |
| fd_set | m_inputs |
| The set of socket descriptors for reading. | |
| fd_set | m_outputs |
| The set of socket descriptors for writing. | |
| CSocketReader | m_reader |
| Socket buffered reader. | |
| CBuffer | m_stringBuffer |
| Buffer to read a line. | |
Allows to establish a network connection to the host by name and port address
| sptk::CSocket::CSocket | ( | int32_t | domain = AF_INET, |
|
| int32_t | type = SOCK_STREAM, |
|||
| int32_t | protocol = 0 | |||
| ) |
Constructor.
| domain | int32_t, socket domain type | |
| type | int32_t, socket type | |
| protocol | int32_t, protocol type |
| void sptk::CSocket::accept | ( | int & | clientSocketFD, | |
| struct sockaddr_in & | clientInfo | |||
| ) |
In server mode, waits for the incoming connection.
When incoming connection is made, exits returning the connection info
| clientSocketFD | int&, connected client socket FD | |
| clientInfo | sockaddr_in&, connected client info |
| bool sptk::CSocket::active | ( | ) | const [inline] |
Returns the current socket state.
References m_sockfd.
Referenced by sptk::CFTPConnect::active().
| void sptk::CSocket::attach | ( | SOCKET | socketHandle | ) |
Attaches socket handle.
| socketHandle | SOCKET, existing socket handle |
| void sptk::CSocket::getOption | ( | int | level, | |
| int | option, | |||
| int & | value | |||
| ) | throw (sptk::CException) |
Gets socket option value.
Throws an error if not succeeded
| void sptk::CSocket::host | ( | std::string | hostName | ) |
Sets the host name.
| hostName | std::string, the host name |
Referenced by sptk::CImapDS::host().
| void sptk::CSocket::listen | ( | int32_t | portNumber = 0 |
) |
Opens the server socket connection on port (binds/listens).
| portNumber | int32_t, the port number |
| virtual void sptk::CSocket::open | ( | std::string | hostName = "", |
|
| int32_t | port = 0, |
|||
| CSocketOpenMode | openMode = SOM_CONNECT | |||
| ) | [virtual] |
Opens the client socket connection by host and port.
| hostName | std::string, the host name | |
| port | int32_t, the port number | |
| openMode | CSocketOpenMode, socket open mode |
| void sptk::CSocket::open_addr | ( | CSocketOpenMode | openMode = SOM_CREATE, |
|
| sockaddr_in * | addr = 0L | |||
| ) |
Opens the socket connection by address.
| openMode | CSocketOpenMode, SOM_CREATE for UDP socket, SOM_BIND for the server socket, and SOM_CONNECT for the client socket | |
| addr | sockaddr_in*, defines socket address/port information |
| int32_t sptk::CSocket::port | ( | ) | const [inline] |
| void sptk::CSocket::port | ( | int32_t | portNumber | ) |
Sets the port number.
| portNumber | int32_t, the port number |
| uint32_t sptk::CSocket::read | ( | CBuffer & | buffer, | |
| sockaddr_in * | from = NULL | |||
| ) |
Reads data from the socket into memory buffer.
| buffer | const CBuffer&, the memory buffer | |
| from | sockaddr_in*, an optional structure for source address |
| uint32_t sptk::CSocket::read | ( | char * | buffer, | |
| uint32_t | size, | |||
| sockaddr_in * | from = NULL | |||
| ) |
Reads data from the socket.
| buffer | char *, the memory buffer | |
| size | uint32_t, the memory buffer size | |
| from | sockaddr_in*, an optional structure for source address |
| uint32_t sptk::CSocket::readLine | ( | std::string & | s | ) |
Reads one line (terminated with CRLF) from the socket into string.
| s | std::string&, the destination string |
| uint32_t sptk::CSocket::readLine | ( | CBuffer & | buffer | ) |
Reads one line (terminated with CRLF) from the socket into existing memory buffer.
The memory buffer is extended automatically to fit the string.
| buffer | CBuffer&, the destination buffer |
| uint32_t sptk::CSocket::readLine | ( | char * | buffer, | |
| uint32_t | size | |||
| ) |
Reads one line (terminated with CRLF) from the socket into existing memory buffer.
The output string should fit the buffer or it will be returned incomplete.
| buffer | char *, the destination buffer | |
| size | uint32_t, the destination buffer size |
| bool sptk::CSocket::readyToRead | ( | uint32_t | waitmsec | ) |
Reports true if socket is ready for reading from it.
| waitmsec | uint32_t, read timeout in msec |
| int32_t sptk::CSocket::recv | ( | void * | buffer, | |
| uint32_t | size | |||
| ) |
Reads data from the socket in regular or TLS mode.
| buffer | void *, the destination buffer | |
| size | uint32_t, the destination buffer size |
| int32_t sptk::CSocket::send | ( | const void * | buffer, | |
| uint32_t | len | |||
| ) |
Reads data from the socket in regular or TLS mode.
| buffer | const void *, the send buffer | |
| size | uint32_t, the send data length |
| uint32_t sptk::CSocket::write | ( | const CBuffer & | buffer | ) |
Writes data to the socket.
| buffer | const CBuffer&, the memory buffer |
| uint32_t sptk::CSocket::write | ( | const char * | buffer, | |
| uint32_t | size, | |||
| const sockaddr_in * | peer = 0 | |||
| ) |
Writes data to the socket.
| buffer | const char *, the memory buffer | |
| size | uint32_t, the memory buffer size | |
| peer | const sockaddr_in*, optional peer information |