* Receive a packet at TCP level * @return Whether at least one packet was received. */
| 131 | * @return Whether at least one packet was received. |
| 132 | */ |
| 133 | bool NetworkContentSocketHandler::ReceivePackets() |
| 134 | { |
| 135 | /* |
| 136 | * We read only a few of the packets. This as receiving packets can be expensive |
| 137 | * due to the re-resolving of the parent/child relations and checking the toggle |
| 138 | * state of all bits. We cannot do this all in one go, as we want to show the |
| 139 | * user what we already received. Otherwise, it can take very long before any |
| 140 | * progress is shown to the end user that something has been received. |
| 141 | * It is also the case that we request extra content from the content server in |
| 142 | * case there is an unknown (in the content list) piece of content. These will |
| 143 | * come in after the main lists have been requested. As a result, we won't be |
| 144 | * getting everything reliably in one batch. Thus, we need to make subsequent |
| 145 | * updates in that case as well. |
| 146 | * |
| 147 | * As a result, we simple handle an arbitrary number of packets in one cycle, |
| 148 | * and let the rest be handled in subsequent cycles. These are ran, almost, |
| 149 | * immediately after this cycle so in speed it does not matter much, except |
| 150 | * that the user interface will appear better responding. |
| 151 | * |
| 152 | * What arbitrary number to choose is the ultimate question though. |
| 153 | */ |
| 154 | std::unique_ptr<Packet> p; |
| 155 | static const int MAX_PACKETS_TO_RECEIVE = 42; |
| 156 | int i = MAX_PACKETS_TO_RECEIVE; |
| 157 | while (--i != 0 && (p = this->ReceivePacket()) != nullptr) { |
| 158 | bool cont = this->HandlePacket(*p); |
| 159 | if (!cont) return true; |
| 160 | } |
| 161 | |
| 162 | return i != MAX_PACKETS_TO_RECEIVE - 1; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | /** |
nothing calls this directly
no test coverage detected