 |
libfilezilla
|
Go to the documentation of this file. 1 #ifndef LIBFILEZILLA_SOCKET_HEADER
2 #define LIBFILEZILLA_SOCKET_HEADER
62 return (
static_cast<std::underlying_type_t<socket_event_flag>
>(lhs) &
static_cast<std::underlying_type_t<socket_event_flag>
>(rhs)) != 0;
66 return static_cast<socket_event_flag>(
static_cast<std::underlying_type_t<socket_event_flag>
>(lhs) |
static_cast<std::underlying_type_t<socket_event_flag>
>(rhs));
102 socket_event_source*
const root_{};
106 struct socket_event_type;
133 struct hostaddress_event_type{};
175 int set_buffer_sizes(
int size_receive,
int size_send);
178 address_type address_family()
const;
185 std::string local_ip(
bool strip_zone_index =
false)
const;
192 int local_port(
int& error)
const;
194 static std::string address_to_string(sockaddr
const* addr,
int addr_len,
bool with_port =
true,
bool strip_zone_index =
false);
195 static std::string address_to_string(
char const* buf,
int buf_len);
202 bool bind(std::string
const& address);
205 typedef intptr_t socket_t;
207 typedef int socket_t;
211 friend class socket_thread;
224 socket_thread* socket_thread_{};
230 unsigned int port_{};
234 int buffer_sizes_[2];
261 std::swap(fd_, rhs.fd_);
265 socket_base::socket_t detach() {
266 socket_base::socket_t ret = fd_;
271 explicit operator bool()
const {
return fd_ != -1; }
274 socket_base::socket_t fd_{-1};
287 friend class socket_thread;
303 int listen(address_type family,
int port = 0);
306 std::unique_ptr<socket> accept(
int& error,
fz::event_handler * handler =
nullptr);
364 virtual int read(
void*
buffer,
unsigned int size,
int& error) = 0;
365 virtual int write(
void const*
buffer,
unsigned int size,
int& error) = 0;
370 virtual int peer_port(
int& error)
const = 0;
372 virtual int connect(
native_string const& host,
unsigned int port, address_type family = address_type::unknown) = 0;
386 virtual int shutdown() = 0;
389 virtual int shutdown_read() = 0;
409 friend class socket_thread;
420 bool is_connected()
const {
438 virtual int connect(
native_string const& host,
unsigned int port, address_type family = address_type::unknown)
override;
455 virtual int read(
void *
buffer,
unsigned int size,
int& error)
override;
472 virtual int write(
void const*
buffer,
unsigned int size,
int& error)
override;
479 std::string peer_ip(
bool strip_zone_index =
false)
const;
489 virtual int peer_port(
int& error)
const override;
497 int ideal_send_buffer_size();
499 virtual int shutdown()
override;
521 flag_keepalive = 0x02
524 int flags()
const {
return flags_; }
527 void set_flags(
int flags,
bool enable);
530 void set_flags(
int flags);
537 void set_keepalive_interval(duration
const& d);
591 virtual int peer_port(
int& error)
const override {
return next_layer_.peer_port(error); }
617 virtual int shutdown_read()
override;
640 event_handler* event_handler_{};
641 socket_interface& next_layer_;
642 bool event_passthrough_{};
664 #define EISCONN WSAEISCONN
667 #define EINPROGRESS WSAEINPROGRESS
670 #define EAFNOSUPPORT WSAEAFNOSUPPORT
673 #define EADDRINUSE WSAEADDRINUSE
676 #define ENOBUFS WSAENOBUFS
678 #ifndef EPROTONOSUPPORT
679 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
682 #define EALREADY WSAEALREADY
685 #define ECONNREFUSED WSAECONNREFUSED
688 #define ENOTSOCK WSAENOTSOCK
691 #define ETIMEDOUT WSAETIMEDOUT
694 #define ENETUNREACH WSAENETUNREACH
697 #define EHOSTUNREACH WSAEHOSTUNREACH
700 #define ENOTCONN WSAENOTCONN
703 #define ENETRESET WSAENETRESET
706 #define EOPNOTSUPP WSAEOPNOTSUPP
709 #define ESHUTDOWN WSAESHUTDOWN
712 #define EMSGSIZE WSAEMSGSIZE
715 #define ECONNABORTED WSAECONNABORTED
718 #define ECONNRESET WSAECONNRESET
721 #define EHOSTDOWN WSAEHOSTDOWN
std::string socket_error_string(int error)
Gets a symbolic name for socket errors.
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition: buffer.hpp:25
listen_socket_state
Definition: socket.hpp:239
virtual int peer_port(int &error) const override
Definition: socket.hpp:591
socket_state
State transitions are monotonically increasing.
Definition: socket.hpp:326
@ none
How the socket is initially.
The duration class represents a time interval in milliseconds.
Definition: time.hpp:271
@ shut_down
Write side has finished shutting down. Receive still working normally.
This is the recommended event class.
Definition: event.hpp:65
@ listening
Only in listening state you can get a connection event.
@ failed
Socket has failed. Further events disabled.
A base class for socket layers.
Definition: socket.hpp:567
fz::socket_event_flag change_socket_event_handler(event_handler *old_handler, event_handler *new_handler, socket_event_source const *const source, fz::socket_event_flag remove)
Changes all pending socket events from source.
IPv6 capable, non-blocking socket class.
Definition: socket.hpp:407
socket_event_flag
The type of a socket event.
Definition: socket.hpp:33
socket_event_source * root() const
Gets the root source.
Definition: socket.hpp:92
@ connected
Socket is in its normal working state. You can get send and receive events.
Declares the event_handler class.
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:33
virtual int shutdown_read() override
Definition: socket.hpp:539
void remove_socket_events(event_handler *handler, socket_event_source const *const source)
Remove all pending socket events from source sent to handler.
virtual native_string peer_host() const override
Definition: socket.hpp:584
Lightweight holder for socket descriptors.
Definition: socket.hpp:249
Simple Listen socket.
Definition: socket.hpp:284
simple_event< socket_event_type, socket_event_source *, socket_event_flag, int > socket_event
Definition: socket.hpp:106
@ closed
Socket has been closed. Further events disabled.
Interface for sockets.
Definition: socket.hpp:358
Various functions to deal with IP address strings.
native_string socket_error_description(int error)
Gets a human-readable, translated description of the error.
All classes sending socket events should derive from this.
Definition: socket.hpp:83
Simple handler for asynchronous event processing.
Definition: event_handler.hpp:54
Sets some global macros and further includes string.hpp.
A simple scoped lock.
Definition: mutex.hpp:64
@ none
How the socket is initially.
socket_interface & next()
The next layer further down. Usually another layer or the actual socket.
Definition: socket.hpp:594
A dumb thread-pool for asynchronous tasks.
Definition: thread_pool.hpp:62
Common base clase for fz::socket and fz::listen_socket.
Definition: socket.hpp:165
simple_event< hostaddress_event_type, socket_event_source *, std::string > hostaddress_event
Definition: socket.hpp:138
The namespace used by libfilezilla.
Definition: apply.hpp:17