| 107 | } |
| 108 | |
| 109 | void* epoll_thread(void* arg) { |
| 110 | EpollMeta* em = (EpollMeta*)arg; |
| 111 | em->nthread = 0; |
| 112 | em->nfold = 0; |
| 113 | #if defined(OS_LINUX) |
| 114 | epoll_event e[32]; |
| 115 | #elif defined(OS_MACOSX) |
| 116 | struct kevent e[32]; |
| 117 | #endif |
| 118 | |
| 119 | while (!server_stop) { |
| 120 | #if defined(OS_LINUX) |
| 121 | const int n = epoll_wait(em->epfd, e, ARRAY_SIZE(e), -1); |
| 122 | #elif defined(OS_MACOSX) |
| 123 | const int n = kevent(em->epfd, NULL, 0, e, ARRAY_SIZE(e), NULL); |
| 124 | #endif |
| 125 | if (server_stop) { |
| 126 | break; |
| 127 | } |
| 128 | if (n < 0) { |
| 129 | if (EINTR == errno) { |
| 130 | continue; |
| 131 | } |
| 132 | #if defined(OS_LINUX) |
| 133 | PLOG(FATAL) << "Fail to epoll_wait"; |
| 134 | #elif defined(OS_MACOSX) |
| 135 | PLOG(FATAL) << "Fail to kevent"; |
| 136 | #endif |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | for (int i = 0; i < n; ++i) { |
| 141 | #if defined(OS_LINUX) |
| 142 | SocketMeta* m = (SocketMeta*)e[i].data.ptr; |
| 143 | #elif defined(OS_MACOSX) |
| 144 | SocketMeta* m = (SocketMeta*)e[i].udata; |
| 145 | #endif |
| 146 | if (m->req.fetch_add(1, butil::memory_order_acquire) == 0) { |
| 147 | bthread_t th; |
| 148 | bthread_start_urgent( |
| 149 | &th, &BTHREAD_ATTR_SMALL, process_thread, m); |
| 150 | ++em->nthread; |
| 151 | } else { |
| 152 | ++em->nfold; |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | return NULL; |
| 157 | } |
| 158 | |
| 159 | void* client_thread(void* arg) { |
| 160 | ClientMeta* m = (ClientMeta*)arg; |
nothing calls this directly
no test coverage detected