socketselect.h
2.02 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// socketselect.h
// BBAAPIRequest
//
// Created by cairui01 on 2020/05/11.
// Copyright (c) 2020年 baidu. All rights reserved.
//
#ifndef _SOCKSTSELECT_
#define _SOCKSTSELECT_
#include "socketpoll.h"
#if 0/*TARGET_OS_MAC*/
#if __APPLE__
#import <TargetConditionals.h>
#if TARGET_OS_MAC
#include <sys/event.h>
#endif
#endif
class SocketSelect {
public:
SocketSelect(SocketBreaker& _breaker, bool _autoclear = false);
~SocketSelect();
void PreSelect();
void Read_FD_SET(int _socket);
void Write_FD_SET(int _socket);
void Exception_FD_SET(int _socket);
int Select();
int Select(int _msec);
int Select(int _sec, int _usec);
int Errno() const;
int Read_FD_ISSET(int _socket) const;
int Write_FD_ISSET(int _socket) const;
int Exception_FD_ISSET(int _socket) const;
bool IsBreak() const;
bool IsException() const;
SocketBreaker& Breaker();
private:
SocketSelect(const SocketSelect&);
SocketSelect& operator=(const SocketSelect&);
private:
SocketBreaker& breaker_;
int kq_;
struct kevent *events_;
int trigered_events_;
int errno_;
bool autoclear_;
};
#else
namespace apirequest {
namespace sdt {
class SocketSelect {
public:
SocketSelect(SocketBreaker& _breaker, bool _autoclear = false);
virtual ~SocketSelect();
void PreSelect();
void Read_FD_SET(SOCKET _socket);
void Write_FD_SET(SOCKET _socket);
void Exception_FD_SET(SOCKET _socket);
virtual int Select();
virtual int Select(int _msec);
int Ret() const;
int Errno() const;
int Read_FD_ISSET(SOCKET _socket) const;
int Write_FD_ISSET(SOCKET _socket) const;
int Exception_FD_ISSET(SOCKET _socket) const;
bool IsBreak() const;
bool IsException() const;
SocketBreaker& Breaker();
SocketPoll& Poll();
private:
SocketSelect(const SocketSelect&);
SocketSelect& operator=(const SocketSelect&);
protected:
SocketPoll socket_poll_;
};
}} // namespace apirequest::sdt
#endif
#endif