MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / recv

Method recv

source/network/ODSocketClient.cpp:152–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152ODSocketClient::ODComStatus ODSocketClient::recv(ODPacket& s)
153{
154 switch(mSource)
155 {
156 case ODSource::none:
157 {
158 // We should not try to send anything until connected
159 OD_LOG_ERR("Unexpected null server mode");
160 return ODComStatus::Error;
161 }
162 case ODSource::network:
163 {
164 sf::Socket::Status status = mSockClient.receive(s.mPacket);
165 if (status == sf::Socket::Done)
166 {
167 s.writePacket(mGameClock.getElapsedTime().asMilliseconds(),
168 mReplayOutputStream);
169 return ODComStatus::OK;
170 }
171
172 if((!mSockClient.isBlocking()) &&
173 (status == sf::Socket::NotReady))
174 {
175 return ODComStatus::NotReady;
176 }
177
178 if(status == sf::Socket::Disconnected)
179 {
180 OD_LOG_WRN("Socket disconnected");
181 return ODComStatus::Error;
182 }
183 OD_LOG_ERR("Could not receive data from client status=" + Helper::toString(status));
184 return ODComStatus::Error;
185 }
186 case ODSource::file:
187 {
188 OD_ASSERT_TRUE(mPendingPacket != 0);
189 s = mPendingPacket;
190 mPendingTimestamp = -1;
191 return ODComStatus::OK;
192 }
193 default:
194 break;
195 }
196 return ODComStatus::Error;
197}
198
199bool ODSocketClient::isConnected()
200{

Callers 1

Calls 2

writePacketMethod · 0.80
toStringFunction · 0.70

Tested by

no test coverage detected