forked from organicmaps/organicmaps
Merge pull request #321 from gardster/online_tests_fix
ConnectionStatus platform method for Linux.
This commit is contained in:
commit
9bc68e689b
1 changed files with 29 additions and 4 deletions
|
@ -1,14 +1,27 @@
|
|||
#include "platform/platform.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
#include "base/scope_guard.hpp"
|
||||
|
||||
#include "coding/file_reader.hpp"
|
||||
|
||||
#include "std/bind.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
// Web service ip to check internet connection. Now it's a mail.ru ip.
|
||||
char constexpr kSomeWorkingWebServer[] = "217.69.139.202";
|
||||
} // namespace
|
||||
|
||||
/// @return directory where binary resides, including slash at the end
|
||||
static bool GetBinaryFolder(string & outPath)
|
||||
|
@ -91,7 +104,7 @@ Platform::Platform()
|
|||
}
|
||||
|
||||
string Platform::UniqueClientId() const
|
||||
{
|
||||
{
|
||||
string machineFile = "/var/lib/dbus/machine-id";
|
||||
if (IsFileExistsByFullPath("/etc/machine-id"))
|
||||
machineFile = "/etc/machine-id";
|
||||
|
@ -104,7 +117,6 @@ string Platform::UniqueClientId() const
|
|||
}
|
||||
else
|
||||
return "n0dbus0n0lsb00000000000000000000";
|
||||
|
||||
}
|
||||
|
||||
void Platform::RunOnGuiThread(TFunctor const & fn)
|
||||
|
@ -121,6 +133,19 @@ void Platform::RunAsync(TFunctor const & fn, Priority p)
|
|||
|
||||
Platform::EConnectionType Platform::ConnectionStatus()
|
||||
{
|
||||
// @TODO Add implementation
|
||||
return EConnectionType::CONNECTION_NONE;
|
||||
int socketFd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
MY_SCOPE_GUARD(closeSocket, bind(&close, socketFd));
|
||||
if (socketFd < 0)
|
||||
return EConnectionType::CONNECTION_NONE;
|
||||
|
||||
struct sockaddr_in addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(80);
|
||||
inet_pton(AF_INET, kSomeWorkingWebServer, &addr.sin_addr);
|
||||
|
||||
if (connect(socketFd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) < 0)
|
||||
return EConnectionType::CONNECTION_NONE;
|
||||
|
||||
return EConnectionType::CONNECTION_WIFI;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue