| 42 | } |
| 43 | |
| 44 | long Interface::Poll(handle_t& client, Message& m){ |
| 45 | handle_t newIf; |
| 46 | while((newIf = InterfaceAccept(interfaceHandle))){ // Accept any incoming connections |
| 47 | if(newIf > 0){ |
| 48 | endpoints.push_back(newIf); |
| 49 | |
| 50 | for(Waiter* waiter : waiters){ |
| 51 | waiter->RepopulateHandles(); // Repopulate handles |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if(queue.size() > 0){ // Check for messages on the queue |
| 57 | auto& front = queue.front(); |
| 58 | |
| 59 | client = front.client; |
| 60 | m.Set(front.data, front.length, front.id); |
| 61 | |
| 62 | queue.pop_front(); |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | for(auto it = endpoints.begin(); !endpoints.empty() && it != endpoints.end(); it++){ |
| 67 | handle_t& endpoint = *it; |
| 68 | InterfaceMessageInfo msg = {endpoint, 0, nullptr, 0}; |
| 69 | |
| 70 | while(long ret = EndpointDequeue(endpoint, &msg.id, &msg.length, dataBuffer)){ |
| 71 | if(ret < 0){ // We have probably disconnected |
| 72 | if(ret == -ENOTCONN){ |
| 73 | DestroyKObject(endpoint); |
| 74 | } |
| 75 | |
| 76 | endpoints.erase(it); |
| 77 | |
| 78 | queue.push_back({.client = endpoint, .id = MessagePeerDisconnect, .data = nullptr, .length = 0}); |
| 79 | |
| 80 | for(Waiter* waiter : waiters){ |
| 81 | waiter->RepopulateHandles(); |
| 82 | } |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | msg.data = dataBuffer; |
| 87 | queue.push_back(msg); |
| 88 | |
| 89 | dataBuffer = new uint8_t[msgSize]; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if(queue.size() > 0){ |
| 94 | auto& front = queue.front(); |
| 95 | |
| 96 | client = front.client; |
| 97 | m.Set(front.data, front.length, front.id); |
| 98 | |
| 99 | queue.pop_front(); |
| 100 | return 1; |
| 101 | } else { |
nothing calls this directly
no test coverage detected