-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathchannel.h
More file actions
57 lines (43 loc) · 1.2 KB
/
channel.h
File metadata and controls
57 lines (43 loc) · 1.2 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
#pragma once
#ifndef CHANNEL_H
#define CHANNEL_H
#include <functional>
#include <memory>
#include <sys/epoll.h>
#include <sys/time.h>
#include "base/log.h"
#include "simplebuffer.h"
#include "httpmessage.h"
class EventLoop;
class Channel
{
public:
typedef std::function<void (EventLoop &, std::shared_ptr<Channel>)> CallbackType;
explicit Channel(int fd);
void SetReadCallback(CallbackType readCallback);
void SetWriteCallback(CallbackType writeCallback);
void SetErrorCallback(CallbackType errorCallback);
void SetEvents(int events);
int GetFd();
int GetEvents();
SimpleBuffer & GetInBuffer();
SimpleBuffer & GetOutBuffer();
HttpMessage & GetHttpMessage();
const struct timeval & GetLastActiveTime();
void SetLastActiveTime(const struct timeval & stTimeval);
int GetMinHeapIndex();
void SetMinHeapIndex(int minHeapIndex);
void HandleEvent(EventLoop & eventLoop, std::shared_ptr<Channel> ptChannel, int revents);
private:
const int m_fd;
int m_events;
CallbackType m_readCallback;
CallbackType m_writeCallback;
CallbackType m_errorCallback;
SimpleBuffer m_inBuffer;
SimpleBuffer m_outBuffer;
HttpMessage m_httpmessage;
struct timeval m_stLastActiveTime;
int m_minHeapIndex;
};
#endif