-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSocket.h
More file actions
54 lines (43 loc) · 1005 Bytes
/
Socket.h
File metadata and controls
54 lines (43 loc) · 1005 Bytes
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
//
// Socket.h
// MessageLoop
//
// Created by Lymons on 14-3-20.
// Copyright (c) 2014年 Lymons. All rights reserved.
//
#ifndef __MessageLoop__Socket__
#define __MessageLoop__Socket__
#include <iostream>
#include <vector>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
using namespace std;
class SocketNotifier;
class Socket
{
public:
Socket(SocketNotifier *n);
int StartServer();
int StartClientConnect(int& server_sock);
int WaitClient();
int NotifyOpposite(int sock);
void CloseConnect(int sock);
private:
SocketNotifier *_notifier;
fd_set _sockets;
int _server_sock;
int _maxsock;
int _conn_amount;
struct timeval _tv; //Select超时返回的时间。
vector<int> _socks;
private:
int AcceptClient();
int ReadClient(int index);
};
#endif /* defined(__MessageLoop__Socket__) */