muduo network class library code profiling --Channel

Channel data members of the class

public :
 // two callable object type aliases 
typedef std :: function < void ()> EventCallback; 
typedef std :: function < void (Timestamp)> ReadEventCallback; 

Private :
 // Event: POLLIN, POLLPRI, POLLOUT 
static  const  int kNoneEvent;
 static  const  int kReadEvent;
 static  const  int kWriteEvent; 

// which EventLoop object pointer this Channel belongs 
EventLoop * loop_; 

// attention to this file descriptor 
const  int   FD_; 

//The Channel Register attention what events: a combination of POLLIN, POLLPRI, POLLOUT like 
int         events_; 

// currently active event: the combination POLLIN, POLLPRI, POLLOUT like 
int         revents_; // IT's Received Event at The types of poll or epoll 

// in a subclass PollPoller class: index represents the polling subscript fd array
 // subclass EpollPoller class: index represents the three states: kNew (new epoll fd is not added to the list of concerns within), kAdded (already add), kDeleted (deleted) 
int         index_; // Used by Poller. 

// ???? 
BOOL        logHup_; 

// ???? 
std :: weak_ptr < void > tie_; 

// ???? 
BOOL tied_; 

// executing Channel callback function
BOOL eventHandling_; 

// Channel file descriptor fd, or whether to be added to the watchlist 
BOOL addedToLoop_; 

// Channel fd belongs to the callback function calls the event comes from an even higher level assignment 
ReadEventCallback readCallback_; 
EventCallback writeCallback_; 
EventCallback closeCallback_; 
EventCallback errorCallback_;

 

Channel class action

1. Storage fd_ when there is need callback function after the events of upper soon: readCallback_, writeCallback_, closeCallback_, errorCallback_

2 . To enhance the lifetime of an object? ?

3. fd_ (or Channel) added to the watchlist poll of EventLoop inside.

 

First, add (/ delete / modify) fd_ (or Channel) to watchlist poll inside of EventLoop

 

  void enableReading() { events_ |= kReadEvent; update(); }
  void disableReading() { events_ &= ~kReadEvent; update(); }
  void enableWriting() { events_ |= kWriteEvent; update(); }
  void disableWriting() { events_ &= ~kWriteEvent; update(); }
  void disableAll() { events_ = kNoneEvent; update(); }
  bool isWriting() const { return events_ & kWriteEvent; }
  bool isReading() const { return events_ & kReadEvent; }

 

void Channel::update()
{
  addedToLoop_ = true;
  loop_->updateChannel(this);
}

In fact, the final call is EventLoop objects Channel object belongs updateChannel () function.

flow chart:

 

Channel object does not have the file descriptor fd, will not close the file descriptor fd destructor when the object.

Channel will different IO event (or listener readable and writable) distribution for different callback.

 

Second, when there is an event coming after fd_ upper callback function

 

Third, to enhance the lifetime of the object? ? ?

 

Guess you like

Origin www.cnblogs.com/jialin0x7c9/p/12246071.html