@@ -157,32 +157,23 @@ int hyper_handle_event(int efd, struct epoll_event *event)
157157 fprintf (stdout , "%s get event %d, he %p, fd %d. ops %p\n" ,
158158 __func__ , event -> events , he , he -> fd , he -> ops );
159159
160- /* do not handle hup event if have in event */
160+ /* do not handle hup event if have in/out event */
161161 if ((event -> events & EPOLLIN ) && he -> ops -> read ) {
162162 fprintf (stdout , "%s event EPOLLIN, he %p, fd %d, %p\n" ,
163163 __func__ , he , he -> fd , he -> ops );
164- if (he -> ops -> read && he -> ops -> read (he , efd ) < 0 )
165- return -1 ;
166- } else if (event -> events & EPOLLHUP ) {
167- fprintf (stdout , "%s event EPOLLHUP, he %p, fd %d, %p\n" ,
168- __func__ , he , he -> fd , he -> ops );
169- if (he -> ops -> hup )
170- he -> ops -> hup (he , efd );
171- return 0 ;
164+ return he -> ops -> read (he , efd );
172165 }
173-
174- if (event -> events & EPOLLOUT ) {
166+ if ((event -> events & EPOLLOUT ) && he -> ops -> write ) {
175167 fprintf (stdout , "%s event EPOLLOUT, he %p, fd %d, %p\n" ,
176168 __func__ , he , he -> fd , he -> ops );
177- if (he -> ops -> write && he -> ops -> write (he , efd ) < 0 )
178- return -1 ;
169+ return he -> ops -> write (he , efd );
179170 }
180171
181- if (event -> events & EPOLLERR ) {
182- fprintf (stdout , "get epoll err on event: %p\n" , he );
172+ if ((event -> events & EPOLLHUP ) || (event -> events & EPOLLERR )) {
173+ fprintf (stdout , "%s event EPOLLHUP or EPOLLERR, he %p, fd %d, %x\n" ,
174+ __func__ , he , he -> fd , event -> events );
183175 if (he -> ops -> hup )
184176 he -> ops -> hup (he , efd );
185- return 0 ;
186177 }
187178
188179 return 0 ;
0 commit comments