forked from KMakowsky/Socket.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Socket.h
55 lines (52 loc) · 1.42 KB
/
Socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Socket.h
// SocketServer
//
// Created by Kay Makowsky on 14.06.16.
// Copyright © 2016 Kay Makowsky. All rights reserved.
//
#ifndef SOCKET_H
#define SOCKET_H
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <vector>
#include <sys/un.h>
#include <errno.h>
using namespace std;
class Socket
{
public:
int sock;
string address;
string port;
struct addrinfo address_info;
Socket();
Socket(int domain,int type,int protocol);
int bind(string ip, string port);
int connect(string ip, string port);
int listen(int max_queue);
Socket* accept();
int socket_write(string msg);
int socket_read(string &buf,int len);
int socket_safe_read(string &buf,int len,int seconds);
int socket_writeTo(string msg, string ip, string port);
int socket_readFrom(string &buf, int len, string ip, string port);
int socket_set_opt(int level, int optname, void* optval);
int socket_get_opt(int level, int optname, void* optval);
int set_blocking();
int set_non_blocking();
int socket_shutdown(int how);
void close();
static int select(vector<Socket> *reads, vector<Socket> *writes, vector<Socket> *exceptions,int seconds);
static string ipFromHostName(string hostname);
};
#endif