EasySockets v2.0.0
A simple, cross platform socket library for C++.
Loading...
Searching...
No Matches
PosixSocket.hpp
1#pragma once
2
3#include <EasySockets/Api/SocketTypes.hpp>
4#include <EasySockets/Api/Addresses.hpp>
5#include <EasySockets/Api/Documentation.hpp>
6#include <netdb.h>
7
8namespace es
9{
11 ES_API_DOC(socket)
24 {
25 public:
26 ES_API_DOC(socket_constructor)
32 PosixSocket(IpVersion ip_version, Protocol protocol);
33
35
36 PosixSocket(const PosixSocket&) = delete;
37
39
40 PosixSocket(PosixSocket&& other) noexcept;
41
42 PosixSocket& operator=(PosixSocket&& other) noexcept;
43
44 ES_API_DOC(socket_bind_to)
51 void bind_to(const EndPoint& end_point);
52
53 ES_API_DOC(socket_connect_to)
58 void connect_to(const EndPoint& end_point);
59
60 ES_API_DOC(socket_listen_for_connections)
70 void listen_for_connections(int backlog);
71
72 ES_API_DOC(socket_accept_connection)
80
81 ES_API_DOC(socket_receive_data)
89 int64_t receive_data(char* buffer, int buffer_size);
90
91 ES_API_DOC(socket_receive_data_from)
101 int64_t receive_data_from(char* buffer, int buffer_size, EndPoint& sender_end_point);
102
103 ES_API_DOC(socket_send_data)
111 int64_t send_data(const char* buffer, int buffer_size);
112
113 ES_API_DOC(socket_send_data_to)
122 int64_t send_data_to(const char* buffer, int buffer_size, const EndPoint& end_point);
123
124 private:
125 struct SocketData
126 {
127 int af;
128 int type;
129 int protocol;
130 };
131
132 PosixSocket();
133
134 addrinfo* resolve_address(const EndPoint& end_point); // must call freeaddrinfo afterward
135
136 int m_socket;
137 SocketData m_socket_data;
138 };
139}
An object which represents a connection between two applications.
Definition PosixSocket.hpp:24
void listen_for_connections(int backlog)
Makes the socket start listening for incoming connections.
Definition PosixSocket.cpp:124
void connect_to(const EndPoint &end_point)
Connects a socket to the given end point.
Definition PosixSocket.cpp:104
PosixSocket(const PosixSocket &)=delete
PosixSocket accept_connection()
Accepts incoming connections.
Definition PosixSocket.cpp:130
PosixSocket & operator=(const PosixSocket &)=delete
void bind_to(const EndPoint &end_point)
Binds a socket to the given end point.
Definition PosixSocket.cpp:84
PosixSocket(IpVersion ip_version, Protocol protocol)
Constructor for Socket.
Definition PosixSocket.cpp:19
int64_t send_data_to(const char *buffer, int buffer_size, const EndPoint &end_point)
Sends data to the provided end point.
Definition PosixSocket.cpp:188
int64_t receive_data_from(char *buffer, int buffer_size, EndPoint &sender_end_point)
Waits to receive data from any endpoint.
Definition PosixSocket.cpp:153
int64_t send_data(const char *buffer, int buffer_size)
Sends data to the connected end point.
Definition PosixSocket.cpp:179
int64_t receive_data(char *buffer, int buffer_size)
Waits to receive data from the connected end point.
Definition PosixSocket.cpp:144
Protocol
Layer 4/transport layer protocol.
Definition SocketTypes.hpp:26
IpVersion
Version of IP address.
Definition SocketTypes.hpp:11
Definition Addresses.hpp:7
Represents the address + port that identifies a connection. Initialized by {Address,...
Definition Addresses.hpp:29