| 1296 | } |
| 1297 | |
| 1298 | bool TNonblockingIOThread::notify(TNonblockingServer::TConnection* conn) { |
| 1299 | auto fd = getNotificationSendFD(); |
| 1300 | if (fd < 0) { |
| 1301 | return false; |
| 1302 | } |
| 1303 | |
| 1304 | int ret = -1; |
| 1305 | long kSize = sizeof(conn); |
| 1306 | const char * pos = (const char *)const_cast_sockopt(&conn); |
| 1307 | |
| 1308 | #if defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H) |
| 1309 | struct pollfd pfd = {fd, POLLOUT, 0}; |
| 1310 | |
| 1311 | while (kSize > 0) { |
| 1312 | pfd.revents = 0; |
| 1313 | ret = poll(&pfd, 1, -1); |
| 1314 | if (ret < 0) { |
| 1315 | return false; |
| 1316 | } else if (ret == 0) { |
| 1317 | continue; |
| 1318 | } |
| 1319 | |
| 1320 | if (pfd.revents & POLLHUP || pfd.revents & POLLERR) { |
| 1321 | ::THRIFT_CLOSESOCKET(fd); |
| 1322 | return false; |
| 1323 | } |
| 1324 | |
| 1325 | if (pfd.revents & POLLOUT) { |
| 1326 | ret = send(fd, pos, kSize, 0); |
| 1327 | if (ret < 0) { |
| 1328 | if (errno == EAGAIN) { |
| 1329 | continue; |
| 1330 | } |
| 1331 | |
| 1332 | ::THRIFT_CLOSESOCKET(fd); |
| 1333 | return false; |
| 1334 | } |
| 1335 | |
| 1336 | kSize -= ret; |
| 1337 | pos += ret; |
| 1338 | } |
| 1339 | } |
| 1340 | #else |
| 1341 | fd_set wfds, efds; |
| 1342 | |
| 1343 | while (kSize > 0) { |
| 1344 | FD_ZERO(&wfds); |
| 1345 | FD_ZERO(&efds); |
| 1346 | FD_SET(fd, &wfds); |
| 1347 | FD_SET(fd, &efds); |
| 1348 | ret = select(static_cast<int>(fd + 1), nullptr, &wfds, &efds, nullptr); |
| 1349 | if (ret < 0) { |
| 1350 | return false; |
| 1351 | } else if (ret == 0) { |
| 1352 | continue; |
| 1353 | } |
| 1354 | |
| 1355 | if (FD_ISSET(fd, &efds)) { |
no test coverage detected