??????(thread.c):?
?
- ??
- ?conn_queue_item {
- ?sfd out of the;
- ?init_state;
- ?event_flags;
- ?read_buffer_size;
- ?is_udp;
?to establish a connection fd?
?
- ???conn_queue CQ;
- ?conn_queue {
?
???{
?
- ?event_base?
- ?
- ?
?
- ?
?
?
???
???{
- ?sfd out of the;
- ?State;
- ?event event;
- ?which;
- ?* RBUF;
??thread??process:??
?
?
?worker threads if MT mode * /?
?
?encapsulates create listening socket bound address,set the non-blocking mode and register the listening socket???
?
??thread_init all workers thread,look at the core code thread_init?
??nthreads,??event_base *??{
- ????
- ?(LIBEVENT_THREAD) * nthreads);
- ?(threads) {
- ??
- ??
- ?(i = 0; i
- ?fds [2];
- ?(pipe (fds)) {
- ??
- ??
- ??
- ?
- ?(i = 1; i
????
???* me) {
- ?(! me-> base) {
- base = event_init ();
- ?(! me-> base) {
- ??
- ?
- notify_event,me-> notify_receive_fd,
- base,& me-> notify_event);
- ??
- ?(event_add (& me->??0) == -1) {
- ??
- new_conn_queue);
???all workers thread pipe read end the libevent of read events,wait for the main thread last all workers CQ?initialization?????
????fd,??which,??* arg) {
- ?buf [1];
- ??
- ?(read (fd,buf,1)! = 1)
- ?(settings.verbose,> 0)
- ??
- new_conn_queue);
- ??
- ?(NULL! = item) {
- sfd,item-> init_state,item-> event_flags,
- read_buffer_size,item-> is_udp,me-> base);
- ????
? SFD is already established connection descriptor,by conn_new function of the descriptor registration the libevent read event,me-> Base on behalf of a thread structure,that is the descriptor event processing the to this workersThreading,the most important elements of conn_new?method?is:?
???SFD,????init_state,????event_flags
- ???read_buffer_size,?????event_base * base) {
- ??
- event,sfd,event_flags,event_handler,??*) c);
- event);
- ev_flags = event_flags;
- ?(event_add (& c-> event,0) == -1) {
- ?(conn_add_to_freelist (c)) {
- ?NULL;
- ??
?????
???drive_machine (conn * c) {
- ?stop =?
- ?SFD,flags = 1;
- ?sockaddr_storage addr;
- ?res;
- ??
- ??
- ?(! stop) {
- ??
- ?(c-> state) {
- ?(addr);
- ?((sfd = accept (c-> sfd,??sockaddr *) & addr,& addrlen)) == -1) {
- ?
- ?((flags = fcntl (sfd,??0)) <0 | |
- ??
- ?(try_read_command,(c) = 0) {
????
?conn_states to {
???
??sfd,????
- ?read_buffer_size,??{
- ???=??+ 1)%?
- ??
- ??
- sfd = sfd;
- init_state = init_state;
- event_flags = event_flags;
- read_buffer_size = read_buffer_size;
- is_udp = is_udp;
- ??
- ?new_conn_queue,item);
- ??
- ?Thread_id);
- ?(write (threads???1)! = 1) {
???????
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|