static */
| 1379 | |
| 1380 | /* static */ |
| 1381 | void TNonblockingIOThread::notifyHandler(evutil_socket_t fd, short which, void* v) { |
| 1382 | auto* ioThread = (TNonblockingIOThread*)v; |
| 1383 | assert(ioThread); |
| 1384 | (void)which; |
| 1385 | |
| 1386 | while (true) { |
| 1387 | TNonblockingServer::TConnection* connection = nullptr; |
| 1388 | const int kSize = sizeof(connection); |
| 1389 | long nBytes = recv(fd, cast_sockopt(&connection), kSize, 0); |
| 1390 | if (nBytes == kSize) { |
| 1391 | if (connection == nullptr) { |
| 1392 | // this is the command to stop our thread, exit the handler! |
| 1393 | ioThread->breakLoop(false); |
| 1394 | return; |
| 1395 | } |
| 1396 | connection->transition(); |
| 1397 | } else if (nBytes > 0) { |
| 1398 | // throw away these bytes and hope that next time we get a solid read |
| 1399 | TOutput::instance().printf("notifyHandler: Bad read of %d bytes, wanted %d", nBytes, kSize); |
| 1400 | ioThread->breakLoop(true); |
| 1401 | return; |
| 1402 | } else if (nBytes == 0) { |
| 1403 | TOutput::instance().printf("notifyHandler: Notify socket closed!"); |
| 1404 | ioThread->breakLoop(false); |
| 1405 | // exit the loop |
| 1406 | break; |
| 1407 | } else { // nBytes < 0 |
| 1408 | if (THRIFT_GET_SOCKET_ERROR != THRIFT_EWOULDBLOCK |
| 1409 | && THRIFT_GET_SOCKET_ERROR != THRIFT_EAGAIN) { |
| 1410 | TOutput::instance().perror("TNonblocking: notifyHandler read() failed: ", THRIFT_GET_SOCKET_ERROR); |
| 1411 | ioThread->breakLoop(true); |
| 1412 | return; |
| 1413 | } |
| 1414 | // exit the loop |
| 1415 | break; |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | void TNonblockingIOThread::breakLoop(bool error) { |
| 1421 | if (error) { |
nothing calls this directly
no test coverage detected