Files
devilutionX/Source/platform/ctr/sockets.cpp
T
Gleb Mazovetskiy 4fa3732526 Add missing <cstdint> includes
Done with the following script:

```ruby
Dir["Source/**/*.{h,c,cc,cpp,hpp}"].each do |path|
  v = File.read(path)
  next if !v.include?("uint32_t") || v.include?("cstdint")

  lines = v.lines
  line_num = if lines[2].start_with?(" *")
    lines.index { |l| l.start_with?(" */") } + 3
  else
    3
  end

  lines.insert(line_num, "#include <cstdint>\n")

  File.write(path, lines.join(""))
end
```

then fixed-up manually
2023-05-10 13:50:12 +01:00

72 lines
1.3 KiB
C++

#include "platform/ctr/sockets.hpp"
#include <cstdint>
#include <malloc.h>
#include <3ds.h>
#include "utils/log.hpp"
namespace devilution {
constexpr auto SOC_ALIGN = 0x1000;
constexpr auto SOC_BUFFERSIZE = 0x100000;
static u32 *socBuffer;
static bool initialized;
static bool waitForWifi()
{
// 100 ms
constexpr s64 sleepNano = 100 * 1000 * 1000;
// 5 sec
constexpr int loopCount = 5 * 1000 / 100;
uint32_t wifi = 0;
for (int i = 0; i < loopCount; ++i) {
if (R_SUCCEEDED(ACU_GetWifiStatus(&wifi)) && wifi)
return true;
svcSleepThread(sleepNano);
}
return false;
}
void n3ds_socExit()
{
if (socBuffer == nullptr)
return;
socExit();
free(socBuffer);
socBuffer = nullptr;
}
void n3ds_socInit()
{
if (!waitForWifi()) {
LogError("n3ds_socInit: Wifi off");
return;
}
socBuffer = (u32 *)memalign(SOC_ALIGN, SOC_BUFFERSIZE);
if (socBuffer == nullptr) {
LogError("n3ds_socInit: memalign() failed");
return;
}
Result result = socInit(socBuffer, SOC_BUFFERSIZE);
if (!R_SUCCEEDED(result)) {
LogError("n3ds_socInit: socInit() failed");
free(socBuffer);
return;
}
if (!initialized)
atexit([]() { n3ds_socExit(); });
initialized = true;
}
} // namespace devilution