MCPcopy Create free account
hub / github.com/SFML/SFML / receive

Method receive

src/SFML/Network/TcpSocket.cpp:1177–1260  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

1175
1176////////////////////////////////////////////////////////////
1177Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& received)
1178{
1179 // First clear the variables to fill
1180 received = 0;
1181
1182 // Check the destination buffer
1183 if (!data)
1184 {
1185 err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl;
1186 return Status::Error;
1187 }
1188
1189 auto sizeReceived = 0;
1190
1191 if (m_impl->tlsState)
1192 {
1193 // Handle receiving over a TLS stream
1194 assert(m_impl->tlsState->handshakeComplete && "TLS handshake must be complete before sending application data");
1195
1196 if (!m_impl->tlsState->handshakeComplete)
1197 {
1198 err() << "TLS handshake must be complete before sending application data" << std::endl;
1199 return Status::Error;
1200 }
1201
1202 sizeReceived = mbedtls_ssl_read(&m_impl->tlsState->sslContext, static_cast<unsigned char*>(data), size);
1203
1204 switch (sizeReceived)
1205 {
1206 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
1207 [[fallthrough]];
1208 case MBEDTLS_ERR_NET_CONN_RESET:
1209 received = 0;
1210 return Status::Disconnected;
1211 case MBEDTLS_ERR_SSL_WANT_READ:
1212 [[fallthrough]];
1213 case MBEDTLS_ERR_SSL_WANT_WRITE:
1214 [[fallthrough]];
1215 case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS:
1216 [[fallthrough]];
1217#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
1218 case MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET:
1219 [[fallthrough]];
1220#endif
1221 case MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS:
1222 received = 0;
1223 return Status::Partial;
1224 default:
1225 break;
1226 }
1227
1228 // If any other error occurred or the TLS stream has no more data to provide, reset the TLS state
1229 if (sizeReceived < 0)
1230 {
1231 m_impl->tlsState.reset();
1232 return Status::Error;
1233 }
1234

Callers

nothing calls this directly

Calls 5

PendingPacketClass · 0.85
resetMethod · 0.80
onReceiveMethod · 0.80
clearMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected