libfilezilla
|
Simple Listen socket. More...
#include <socket.hpp>
Public Member Functions | |
listen_socket (thread_pool &pool, event_handler *evt_handler) | |
listen_socket (listen_socket const &)=delete | |
listen_socket & | operator= (listen_socket const &)=delete |
int | listen (address_type family, int port=0) |
Starts listening. More... | |
std::unique_ptr< socket > | accept (int &error, fz::event_handler *handler=nullptr) |
Accepts incoming connection. If no socket is returned, error contains the reason. | |
socket_descriptor | fast_accept (int &error) |
Like accept, but only returns a socket descriptor. More... | |
listen_socket_state | get_state () const |
void | set_event_handler (event_handler *pEvtHandler) |
Public Member Functions inherited from socket_base | |
int | set_buffer_sizes (int size_receive, int size_send) |
Sets socket buffer sizes. More... | |
address_type | address_family () const |
If connected, either ipv4, ipv6 or unix, unknown otherwise. | |
std::string | local_ip (bool strip_zone_index=false) const |
Returns local address of a connected socket. More... | |
int | local_port (int &error) const |
Returns local port of a connected socket. More... | |
bool | bind (std::string const &address) |
Bind socket to the specific local IP. More... | |
Public Member Functions inherited from socket_event_source | |
socket_event_source * | root () const |
Gets the root source. More... | |
Static Public Member Functions | |
static std::unique_ptr< listen_socket > | from_descriptor (socket_descriptor &&desc, thread_pool &pool, int &error, fz::event_handler *handler=nullptr) |
Static Public Member Functions inherited from socket_base | |
static std::string | address_to_string (sockaddr const *addr, int addr_len, bool with_port=true, bool strip_zone_index=false) |
static std::string | address_to_string (char const *buf, int buf_len) |
Friends | |
class | socket_base |
class | socket_thread |
Additional Inherited Members | |
Public Types inherited from socket_base | |
typedef intptr_t | socket_t |
Protected Member Functions inherited from socket_base | |
socket_base (thread_pool &pool, event_handler *evt_handler, socket_event_source *ev_source) | |
int | close () |
void | detach_thread (scoped_lock &l) |
Protected Member Functions inherited from socket_event_source | |
socket_event_source (socket_event_source *root) | |
Protected Attributes inherited from socket_base | |
thread_pool & | thread_pool_ |
event_handler * | evt_handler_ |
socket_thread * | socket_thread_ {} |
socket_event_source *const | ev_source_ {} |
socket_t | fd_ {-1} |
unsigned int | port_ {} |
int | family_ |
int | buffer_sizes_ [2] |
Protected Attributes inherited from socket_event_source | |
socket_event_source *const | root_ {} |
Simple Listen socket.
When a client connects, a socket event with the connection flag is send.
Call accept to accept.
socket_descriptor fast_accept | ( | int & | error | ) |
Like accept, but only returns a socket descriptor.
Best suited for tight accept loops where the descriptor is handed off to other threads.
int listen | ( | address_type | family, |
int | port = 0 |
||
) |
Starts listening.
If no port is given, let the operating system decide on a port. Can use local_port to query it afterwards.
The address type, if not fz::address_type::unknown, must may the type of the address passed to bind()