Argentum Online - Servidor
socket.h
1
#ifndef __SOCKET_H__
2
#define __SOCKET_H__
3
4
#include <netdb.h>
5
#include <sys/socket.h>
6
#include <unistd.h>
7
8
#include <string>
9
10
#include "../my_exception.h"
11
12
class
Socket
{
13
private
:
14
bool
_is_open;
15
bool
_is_connected;
16
int
socketfd;
17
18
// Private from fd
19
explicit
Socket
(
int
socketfd);
20
21
int
get_results(
struct
addrinfo** results,
const
char
* node,
22
const
char
* service,
int
flags);
23
24
int
get_socketfd(
struct
addrinfo* results,
25
int
(*setup)(
int
,
const
struct
sockaddr*, socklen_t));
26
27
int
socket_setup(
const
char
* node,
const
char
* port,
28
int
(*setup)(
int
,
const
struct
sockaddr*, socklen_t),
29
int
flags);
30
31
public
:
32
// Client
33
Socket
(
const
std::string& node,
const
std::string& port);
34
35
// Server
36
Socket
(
const
std::string& port,
const
size_t
& max_client_q);
37
38
// Cannot be copied
39
Socket
(
const
Socket
& other) =
delete
;
40
Socket
& operator=(
Socket
& other) =
delete
;
41
42
// Move Constructor
43
Socket
(
Socket
&& other);
44
Socket
& operator=(
Socket
&& other);
45
46
// If socket was created for host-side, accept a client as a Socket
47
Socket
accept();
48
49
bool
is_connected()
const
;
50
51
bool
is_open()
const
;
52
53
// Send lenght ammount of bytes
54
size_t
send(
const
char
* bytes,
size_t
lenght);
55
56
// Send a char
57
Socket
& operator<<(
const
char
c);
58
59
// Recieve at most size ammout of bytes
60
size_t
recv(
char
* buffer,
size_t
size);
61
62
// Recieve a char
63
Socket
& operator>>(
char
& c);
64
65
void
shutdown_and_close();
66
67
~
Socket
();
68
};
69
70
#endif //__SOCKET_H__
Socket
Definition:
socket.h:12
include
network
socket.h
Generado por
1.8.19