|
EasySockets v2.2.1
A simple, cross platform socket library for C++.
|
An object which represents a connection between two applications. More...
#include <PosixSocket.hpp>
Public Member Functions | |
| PosixSocket () | |
| Default constructs a socket. | |
| PosixSocket (IpVersion ip_version, Protocol protocol) | |
| Constructor for Socket. | |
| ~PosixSocket () | |
| PosixSocket (const PosixSocket &)=delete | |
| PosixSocket & | operator= (const PosixSocket &)=delete |
| PosixSocket (PosixSocket &&other) noexcept | |
| PosixSocket & | operator= (PosixSocket &&other) noexcept |
| void | bind_to (const EndPoint &end_point) |
| Binds a socket to the given end point. | |
| void | connect_to (const EndPoint &end_point) |
| Connects a socket to the given end point. | |
| void | listen_for_connections (int backlog) |
| Makes the socket start listening for incoming connections. | |
| PosixSocket | accept_connection () |
| Accepts incoming connections. | |
| int64_t | receive_data (char *buffer, int buffer_size) |
| Waits to receive data from the connected end point. | |
| int64_t | receive_data_from (char *buffer, int buffer_size, EndPoint &sender_end_point) |
| Waits to receive data from any endpoint. | |
| int64_t | send_data (const char *buffer, int buffer_size) |
| Sends data to the connected end point. | |
| int64_t | send_data_to (const char *buffer, int buffer_size, const EndPoint &end_point) |
| Sends data to the provided end point. | |
| void | close () |
| Closes the socket. | |
Static Public Member Functions | |
| static PosixSocket | make_connected_tcp (const EndPoint &end_point) |
| Makes a TCP socket connected to the given endpoint. | |
| static PosixSocket | make_connected_udp (const EndPoint &end_point) |
| Makes a UDP socket connected to the given endpoint. | |
| static PosixSocket | make_bound_tcp (Port port, IpVersion ip_version=IpVersion::DUAL_STACK) |
| Makes a TCP socket bound to the given port. | |
| static PosixSocket | make_bound_udp (Port port, IpVersion ip_version=IpVersion::DUAL_STACK) |
| Makes a UDP socket bound to the given port. | |
An object which represents a connection between two applications.
On creation, type of ip addresses that the socket will use and the layer 4/transport layer protocol is specified.
From this, methods like .bind_to(EndPoint end_point) and .connect_to(EndPoint end_point) to give the socket an address and port so that it can start communicating with other applications.
For connectionless protocols like UDP, data can be sent and received without binding or connecting first.
Can be moved from but not copied. Members are the same across all implementations.
| es::PosixSocket::PosixSocket | ( | ) |
Default constructs a socket.
This socket will not be usable and will have to be assigned to something else.
Constructor for Socket.
| ip_version | The version of ip addresses that the socket will use. |
| protocol | The layer 4/transport layer protocol that the socket will use. |
| es::PosixSocket::~PosixSocket | ( | ) |
|
delete |
|
noexcept |
| PosixSocket es::PosixSocket::accept_connection | ( | ) |
Accepts incoming connections.
.listen(int backlog)must be called first.
| void es::PosixSocket::bind_to | ( | const EndPoint & | end_point | ) |
Binds a socket to the given end point.
| end_point | The endpoint that the socket will use. "0.0.0.0" will bind to all IPv4 interfaces, "::0"will bind to all IPv6 interfaces and "::"" will bind to all interfaces. |
| void es::PosixSocket::close | ( | ) |
Closes the socket.
Is automatically called on destruction. Will make blocking methods on socket that are currently beign executed throw.
| void es::PosixSocket::connect_to | ( | const EndPoint & | end_point | ) |
Connects a socket to the given end point.
| end_point | The endpoint that the socket will use. |
| void es::PosixSocket::listen_for_connections | ( | int | backlog | ) |
Makes the socket start listening for incoming connections.
Must be bound with .bind(EndPoint end_point) before being called.
| backlog | The amount of connections that can be waiting to be accepted at a time. If the amount of connections exceeds the backlog, then new connections will be dropped. Connections can be accepted with .accept_connection. |
|
static |
Makes a TCP socket bound to the given port.
| port | The port which the socket will be bound to. |
| ip_version | Optional paramater for the IP version that the socket will use. Defaults to IpVersion::DUAL_STACK. |
|
static |
Makes a UDP socket bound to the given port.
| port | The port which the socket will be bound to. |
| ip_version | Optional paramater for the IP version that the socket will use. Defaults to IpVersion::DUAL_STACK. |
|
static |
Makes a TCP socket connected to the given endpoint.
| end_point | The endpoint that the socket is attempting to connect to. |
|
static |
Makes a UDP socket connected to the given endpoint.
| end_point | The endpoint that the socket is attempting to connect to. |
|
delete |
|
noexcept |
| int64_t es::PosixSocket::receive_data | ( | char * | buffer, |
| int | buffer_size ) |
Waits to receive data from the connected end point.
Must be connected to another end point.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| int64_t es::PosixSocket::receive_data_from | ( | char * | buffer, |
| int | buffer_size, | ||
| EndPoint & | sender_end_point ) |
Waits to receive data from any endpoint.
Can only be used with connectionless protocols like UDP.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| sender_end_point | An out parameter will give back the end point of the sender. |
| int64_t es::PosixSocket::send_data | ( | const char * | buffer, |
| int | buffer_size ) |
Sends data to the connected end point.
Must be connected to another end point.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| int64_t es::PosixSocket::send_data_to | ( | const char * | buffer, |
| int | buffer_size, | ||
| const EndPoint & | end_point ) |
Sends data to the provided end point.
Must be connected to another end point.
| buffer | The buffer which data received will be placed into. |
| buffer_size | The size of the buffer provided. |
| end_point | The endpoint that the data will be sent to. |