1 #ifndef LIBFILEZILLA_SOCKET_HEADER 2 #define LIBFILEZILLA_SOCKET_HEADER 19 enum class socket_event_flag
57 socket_event_source*
const root_{};
61 struct socket_event_type;
81 struct hostaddress_event_type{};
122 int set_buffer_sizes(
int size_receive,
int size_send);
125 address_type address_family()
const;
132 std::string local_ip(
bool strip_zone_index =
false)
const;
139 int local_port(
int& error)
const;
141 static std::string address_to_string(sockaddr
const* addr,
int addr_len,
bool with_port =
true,
bool strip_zone_index =
false);
142 static std::string address_to_string(
char const* buf,
int buf_len);
149 bool bind(std::string
const& address);
152 typedef intptr_t socket_t;
154 typedef int socket_t;
158 friend class socket_thread;
175 socket_thread* socket_thread_{};
177 unsigned int port_{};
181 int buffer_sizes_[2];
207 friend class socket_thread;
223 int listen(address_type family,
int port = 0);
226 std::unique_ptr<socket> accept(
int& error);
231 do_set_event_handler(pEvtHandler);
278 virtual int read(
void*
buffer,
unsigned int size,
int& error) = 0;
279 virtual int write(
void const*
buffer,
unsigned int size,
int& error) = 0;
281 virtual void set_event_handler(
event_handler* pEvtHandler) = 0;
284 virtual int peer_port(
int& error)
const = 0;
286 virtual int connect(
native_string const& host,
unsigned int port, address_type family = address_type::unknown) = 0;
296 virtual int shutdown() = 0;
316 friend class socket_thread;
325 bool is_connected()
const {
343 virtual int connect(
native_string const& host,
unsigned int port, address_type family = address_type::unknown)
override;
360 virtual int read(
void *
buffer,
unsigned int size,
int& error)
override;
377 virtual int write(
void const*
buffer,
unsigned int size,
int& error)
override;
384 std::string peer_ip(
bool strip_zone_index =
false)
const;
394 virtual int peer_port(
int& error)
const override;
402 int ideal_send_buffer_size();
408 void retrigger(socket_event_flag event);
410 virtual int shutdown()
override;
412 virtual void set_event_handler(
event_handler* pEvtHandler)
override;
420 flag_keepalive = 0x02
423 int flags()
const {
return flags_; }
424 void set_flags(
int flags);
431 void set_keepalive_interval(duration
const& d);
434 friend class socket_base;
435 friend class listen_socket;
441 duration keepalive_interval_;
447 #define EISCONN WSAEISCONN 450 #define EINPROGRESS WSAEINPROGRESS 453 #define EAFNOSUPPORT WSAEAFNOSUPPORT 456 #define EADDRINUSE WSAEADDRINUSE 459 #define ENOBUFS WSAENOBUFS 461 #ifndef EPROTONOSUPPORT 462 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 465 #define EALREADY WSAEALREADY 468 #define ECONNREFUSED WSAECONNREFUSED 471 #define ENOTSOCK WSAENOTSOCK 474 #define ETIMEDOUT WSAETIMEDOUT 477 #define ENETUNREACH WSAENETUNREACH 480 #define EHOSTUNREACH WSAEHOSTUNREACH 483 #define ENOTCONN WSAENOTCONN 486 #define ENETRESET WSAENETRESET 489 #define EOPNOTSUPP WSAEOPNOTSUPP 492 #define ESHUTDOWN WSAESHUTDOWN 495 #define EMSGSIZE WSAEMSGSIZE 498 #define ECONNABORTED WSAECONNABORTED 501 #define ECONNRESET WSAECONNRESET 504 #define EHOSTDOWN WSAEHOSTDOWN A simple scoped lock.
Definition: mutex.hpp:61
Interface for sockets.
Definition: socket.hpp:272
simple_event< socket_event_type, socket_event_source *, socket_event_flag, int > socket_event
Definition: socket.hpp:61
Simple handler for asynchronous event processing.
Definition: event_handler.hpp:54
Declares the event_handler class.
Common base clase for fz::socket and fz::listen_socket.
Definition: socket.hpp:112
Socket has been closed. Further events disabled.
Definition: socket.hpp:204
Various functions to deal with IP address strings.
Socket is in its normal working state. You can get send and receive events.
Socket has failed. Further events disabled.
This is the recommended event class.
Definition: event.hpp:63
simple_event< hostaddress_event_type, socket_event_source *, std::string > hostaddress_event
Definition: socket.hpp:86
IPv6 capable, non-blocking socket class.
Definition: socket.hpp:314
socket_event_source * root() const
Gets the root source.
Definition: socket.hpp:47
void remove_socket_events(event_handler *handler, socket_event_source const *const source)
Remove all pending socket events from source sent to handler.
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:32
socket_state
State transitions are monotonically increasing.
Definition: socket.hpp:240
Only in listening state you can get a connection event.
The namespace used by libfilezilla.
Definition: apply.hpp:16
listen_socket_state
Definition: socket.hpp:188
All classes sending socket events should derive from this.
Definition: socket.hpp:38
Sets some global macros and further includes string.hpp.
How the socket is initially.
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition: buffer.hpp:23
Definition: thread_pool.hpp:59
Write side has finished shutting down. Receive still working normally.