EasySockets v2.0.0
A simple, cross platform socket library for C++.
Loading...
Searching...
No Matches
WindowsSocket.hpp
1#pragma once
2
3#include <winsock2.h>
4#include <ws2tcpip.h>
5#include <EasySockets/Api/SocketTypes.hpp>
6#include <EasySockets/Api/Addresses.hpp>
7#include <EasySockets/Api/Documentation.hpp>
8
9namespace es
10{
12 ES_API_DOC(socket)
25 {
26 public:
27 ES_API_DOC(socket_constructor)
33 WindowsSocket(IpVersion ip_version, Protocol protocol);
34
36
37 WindowsSocket(const WindowsSocket&) = delete;
38
40
41 WindowsSocket(WindowsSocket&& other) noexcept;
42
43 WindowsSocket& operator=(WindowsSocket&& other) noexcept;
44
45 ES_API_DOC(socket_bind_to)
52 void bind_to(const EndPoint& end_point);
53
54 ES_API_DOC(socket_connect_to)
59 void connect_to(const EndPoint& end_point);
60
61 ES_API_DOC(socket_listen_for_connections)
71 void listen_for_connections(int backlog);
72
73 ES_API_DOC(socket_accept_connection)
81
82 ES_API_DOC(socket_receive_data)
90 int64_t receive_data(char* buffer, int buffer_size);
91
92 ES_API_DOC(socket_receive_data_from)
102 int64_t receive_data_from(char* buffer, int buffer_size, EndPoint& sender_end_point);
103
104 ES_API_DOC(socket_send_data)
112 int64_t send_data(const char* buffer, int buffer_size);
113
114 ES_API_DOC(socket_send_data_to)
123 int64_t send_data_to(const char* buffer, int buffer_size, const EndPoint& end_point);
124
125 private:
126 // data that winsock needs for the socket
127 struct WinsockData
128 {
129 int af;
130 int type;
131 int protocol;
132 };
133
134 // only for internal use when creating a socket for accepting
136
137 // must free with freeaddrinfo
138 addrinfo* resolve_address(const EndPoint& end_point, int flags);
139
140 SOCKET m_socket;
141 WinsockData m_winsock_data;
142 };
143}
An object which represents a connection between two applications.
Definition WindowsSocket.hpp:25
int64_t receive_data(char *buffer, int buffer_size)
Waits to receive data from the connected end point.
Definition WindowsSocket.cpp:148
WindowsSocket(const WindowsSocket &)=delete
WindowsSocket(IpVersion ip_version, Protocol protocol)
Constructor for Socket.
Definition WindowsSocket.cpp:26
int64_t receive_data_from(char *buffer, int buffer_size, EndPoint &sender_end_point)
Waits to receive data from any endpoint.
Definition WindowsSocket.cpp:158
void listen_for_connections(int backlog)
Makes the socket start listening for incoming connections.
Definition WindowsSocket.cpp:126
WindowsSocket & operator=(const WindowsSocket &)=delete
int64_t send_data(const char *buffer, int buffer_size)
Sends data to the connected end point.
Definition WindowsSocket.cpp:190
WindowsSocket accept_connection()
Accepts incoming connections.
Definition WindowsSocket.cpp:134
void connect_to(const EndPoint &end_point)
Connects a socket to the given end point.
Definition WindowsSocket.cpp:105
int64_t send_data_to(const char *buffer, int buffer_size, const EndPoint &end_point)
Sends data to the provided end point.
Definition WindowsSocket.cpp:200
void bind_to(const EndPoint &end_point)
Binds a socket to the given end point.
Definition WindowsSocket.cpp:84
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