mirror of
https://github.com/levinsv/pgadmin3.git
synced 2026-05-15 06:05:49 -06:00
update pgadmin3.exe
This commit is contained in:
commit
88f1160280
16 changed files with 41207 additions and 41075 deletions
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
|
|
@ -20,6 +20,9 @@
|
|||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
,"env": {
|
||||
"LD_LIBRARY_PATH": "${workspaceFolder}/build"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -77,7 +77,8 @@ file(GLOB_RECURSE SOURCES
|
|||
)
|
||||
|
||||
##########################################################
|
||||
|
||||
set(RPATH ".")
|
||||
list(APPEND CMAKE_BUILD_RPATH ${RPATH})
|
||||
add_executable(${PROJECT_NAME} )
|
||||
# После сборки — разделить символы и приложение
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
|
|
|
|||
|
|
@ -1047,9 +1047,6 @@ bool pgConn::IsAlive()
|
|||
|
||||
int pgConn::GetStatus() const
|
||||
{
|
||||
if (!this)
|
||||
return PGCONN_BAD;
|
||||
|
||||
if (conn)
|
||||
((pgConn *)this)->connStatus = PQstatus(conn);
|
||||
|
||||
|
|
@ -1246,7 +1243,7 @@ bool pgConn::TableHasColumn(wxString schemaname, wxString tblname, const wxStrin
|
|||
if (schemaname.IsEmpty())
|
||||
schemaname = wxT("public");
|
||||
|
||||
if (this && GetStatus() == PGCONN_OK)
|
||||
if (GetStatus() == PGCONN_OK)
|
||||
{
|
||||
tblname.Replace(wxT("\\"), wxT("\\\\"));
|
||||
tblname.Replace(wxT("'"), wxT("''"));
|
||||
|
|
|
|||
|
|
@ -27,8 +27,10 @@
|
|||
#define CTRLID_CBDATABASE 4243
|
||||
#define CTRLID_CBUSERNAME 4244
|
||||
#define CTRLID_CBROLENAME 4245
|
||||
#define CTRLID_CBGROUP 4246
|
||||
|
||||
BEGIN_EVENT_TABLE(dlgSelectConnection, DialogWithHelp)
|
||||
EVT_COMBOBOX(CTRLID_CBGROUP, dlgSelectConnection::OnChangeGroup)
|
||||
EVT_COMBOBOX(CTRLID_CBSERVER, dlgSelectConnection::OnChangeServer)
|
||||
EVT_COMBOBOX(CTRLID_CBDATABASE, dlgSelectConnection::OnChangeDatabase)
|
||||
EVT_TEXT(CTRLID_CBSERVER, dlgSelectConnection::OnTextChange)
|
||||
|
|
@ -56,17 +58,31 @@ dlgSelectConnection::dlgSelectConnection(wxWindow *parent, frmMain *form) :
|
|||
if (form != NULL)
|
||||
style |= wxCB_READONLY;
|
||||
|
||||
cbServer = new ctlComboBoxFix(this, CTRLID_CBSERVER, ConvertDialogToPixels(wxPoint(65, 5)), ConvertDialogToPixels(wxSize(135, 12)), style);
|
||||
cbDatabase = new wxComboBox(this, CTRLID_CBDATABASE, wxEmptyString, ConvertDialogToPixels(wxPoint(65, 20)), ConvertDialogToPixels(wxSize(135, 12)), wxArrayString(), style);
|
||||
cbUsername = new wxComboBox(this, CTRLID_CBUSERNAME, wxEmptyString, ConvertDialogToPixels(wxPoint(65, 35)), ConvertDialogToPixels(wxSize(135, 12)), wxArrayString(), style);
|
||||
cbRolename = new wxComboBox(this, CTRLID_CBROLENAME, wxEmptyString, ConvertDialogToPixels(wxPoint(65, 50)), ConvertDialogToPixels(wxSize(135, 12)), wxArrayString(), style);
|
||||
cbGroup = new wxComboBox(this, CTRLID_CBGROUP, wxEmptyString, ConvertDialogToPixels(wxPoint(70, 5)), ConvertDialogToPixels(wxSize(135, 12)), wxArrayString(), style);
|
||||
cbServer = new ctlComboBoxFix(this, CTRLID_CBSERVER, ConvertDialogToPixels(wxPoint(70, 20)), ConvertDialogToPixels(wxSize(135, 12)), style);
|
||||
cbDatabase = new wxComboBox(this, CTRLID_CBDATABASE, wxEmptyString, ConvertDialogToPixels(wxPoint(70, 35)), ConvertDialogToPixels(wxSize(135, 12)), wxArrayString(), style);
|
||||
cbUsername = new wxComboBox(this, CTRLID_CBUSERNAME, wxEmptyString, ConvertDialogToPixels(wxPoint(70, 50)), ConvertDialogToPixels(wxSize(135, 12)), wxArrayString(), style);
|
||||
cbRolename = new wxComboBox(this, CTRLID_CBROLENAME, wxEmptyString, ConvertDialogToPixels(wxPoint(70, 75)), ConvertDialogToPixels(wxSize(135, 12)), wxArrayString(), style);
|
||||
|
||||
if (form == NULL)
|
||||
{
|
||||
cbServer->SetValue(settings->Read(wxT("QuickConnect/server"), wxEmptyString));
|
||||
cbGroup->SetValue(settings->Read(wxT("QuickConnect/group"), wxEmptyString));
|
||||
cbDatabase->SetValue(settings->Read(wxT("QuickConnect/database"), wxEmptyString));
|
||||
cbUsername->SetValue(settings->Read(wxT("QuickConnect/username"), wxEmptyString));
|
||||
cbRolename->SetValue(settings->Read(wxT("QuickConnect/rolename"), wxEmptyString));
|
||||
} else {
|
||||
wxTreeItemIdValue foldercookie, servercookie;
|
||||
wxTreeItemId folderitem, serveritem;
|
||||
ctlTree *browser = mainForm->GetBrowser();
|
||||
folderitem = browser->GetFirstChild(browser->GetRootItem(), foldercookie);
|
||||
cbGroup->Append("");
|
||||
while (folderitem)
|
||||
{
|
||||
wxString grp=browser->GetItemText(folderitem);
|
||||
cbGroup->Append(grp);
|
||||
folderitem = browser->GetNextChild(browser->GetRootItem(), foldercookie);
|
||||
}
|
||||
}
|
||||
|
||||
btnOK->Enable(cbServer->GetValue().Length() > 0 && cbDatabase->GetValue().Length() > 0 && cbUsername->GetValue().Length() > 0);
|
||||
|
|
@ -84,7 +100,16 @@ wxString dlgSelectConnection::GetHelpPage() const
|
|||
return wxT("connect");
|
||||
}
|
||||
|
||||
|
||||
void dlgSelectConnection::OnChangeGroup(wxCommandEvent &ev)
|
||||
{
|
||||
int sel = cbGroup->GetCurrentSelection();
|
||||
if (sel >= 0)
|
||||
{
|
||||
bool found=BuildServerCombo(currconn);
|
||||
if (!found) cbServer->SetSelection(0);
|
||||
OnChangeServer(ev);
|
||||
}
|
||||
}
|
||||
void dlgSelectConnection::OnChangeServer(wxCommandEvent &ev)
|
||||
{
|
||||
int item;
|
||||
|
|
@ -307,6 +332,7 @@ pgConn *dlgSelectConnection::CreateConn(wxString &server, wxString &dbname, wxSt
|
|||
if (writeMRU)
|
||||
{
|
||||
settings->Write(wxT("QuickConnect/server"), cbServer->GetValue());
|
||||
settings->Write(wxT("QuickConnect/group"), cbGroup->GetValue());
|
||||
settings->Write(wxT("QuickConnect/database"), cbDatabase->GetValue());
|
||||
settings->Write(wxT("QuickConnect/username"), cbUsername->GetValue());
|
||||
settings->Write(wxT("QuickConnect/rolename"), cbRolename->GetValue());
|
||||
|
|
@ -314,11 +340,8 @@ pgConn *dlgSelectConnection::CreateConn(wxString &server, wxString &dbname, wxSt
|
|||
}
|
||||
return newconn;
|
||||
}
|
||||
|
||||
int dlgSelectConnection::Go(pgConn *conn, wxBitmapComboBox *cb)
|
||||
{
|
||||
bool dlgSelectConnection::BuildServerCombo(pgConn *conn) {
|
||||
bool foundServer = false;
|
||||
cbConnection = cb;
|
||||
if (mainForm != NULL)
|
||||
{
|
||||
ctlTree *browser = mainForm->GetBrowser();
|
||||
|
|
@ -326,11 +349,18 @@ int dlgSelectConnection::Go(pgConn *conn, wxBitmapComboBox *cb)
|
|||
wxTreeItemId folderitem, serveritem;
|
||||
pgObject *object;
|
||||
pgServer *server;
|
||||
|
||||
wxString grp;
|
||||
cbServer->Clear();
|
||||
if (cbGroup->GetCurrentSelection() != wxNOT_FOUND) {
|
||||
grp=cbGroup->GetValue();
|
||||
}
|
||||
folderitem = browser->GetFirstChild(browser->GetRootItem(), foldercookie);
|
||||
while (folderitem)
|
||||
{
|
||||
if (browser->ItemHasChildren(folderitem))
|
||||
bool isGroup=true;
|
||||
if (grp.Length()>0)
|
||||
if (browser->GetItemText(folderitem)!=grp ) isGroup=false;
|
||||
if (browser->ItemHasChildren(folderitem) && isGroup)
|
||||
{
|
||||
serveritem = browser->GetFirstChild(folderitem, servercookie);
|
||||
while (serveritem)
|
||||
|
|
@ -355,7 +385,6 @@ int dlgSelectConnection::Go(pgConn *conn, wxBitmapComboBox *cb)
|
|||
folderitem = browser->GetNextChild(browser->GetRootItem(), foldercookie);
|
||||
}
|
||||
}
|
||||
|
||||
cbServer->SetFocus();
|
||||
|
||||
wxCommandEvent ev;
|
||||
|
|
@ -390,6 +419,15 @@ int dlgSelectConnection::Go(pgConn *conn, wxBitmapComboBox *cb)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundServer;
|
||||
}
|
||||
int dlgSelectConnection::Go(pgConn *conn, wxBitmapComboBox *cb)
|
||||
{
|
||||
bool foundServer = false;
|
||||
cbConnection = cb;
|
||||
currconn=conn;
|
||||
foundServer = BuildServerCombo(conn);
|
||||
|
||||
return ShowModal();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,8 +267,12 @@ frmMain::frmMain(const wxString &title)
|
|||
browser->SetFocus();
|
||||
wxString selServerName=settings->Read(wxT("Servers/SelectItem"), "");
|
||||
if (selServerName.Len()>0) {
|
||||
wxTreeItemId sel=browser->FindItem(root,selServerName,true);
|
||||
if (sel.IsOk()) browser->SelectItem(sel);
|
||||
wxTreeItemId sel=browser->FindItem(root,selServerName,false);
|
||||
if (sel.IsOk()) {
|
||||
browser->SelectItem(sel);
|
||||
currentObject=browser->GetObject(sel);
|
||||
//execSelChange(sel, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1148,6 +1152,25 @@ wxTreeItemId frmMain::RestoreEnvironment(pgServer *server)
|
|||
|
||||
int frmMain::ReconnectServer(pgServer *server, bool restore)
|
||||
{
|
||||
if (server->GetPuttyTunnel()) {
|
||||
// check open port
|
||||
int port=server->GetPort();
|
||||
wxString localhost=server->GetName(); // localhost
|
||||
if (!isPortOpen(localhost,port,500)) {
|
||||
server->GetPuttyTunnel()->StartDialog(winMain, server); // execute plugin
|
||||
int count=0;
|
||||
do {
|
||||
wxMilliSleep(200);
|
||||
count++;
|
||||
} while (!isPortOpen(localhost,port,500) && count<20); // wait create putty tunnel
|
||||
if (count>=20) {
|
||||
StartMsg(_("Create putty tunnel error."));
|
||||
EndMsg(true);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a server object and connect it.
|
||||
wxBusyInfo waiting(wxString::Format(_("Connecting to server %s (%s:%d)"),
|
||||
server->GetDescription().c_str(), server->GetName().c_str(), server->GetPort()), this);
|
||||
|
|
@ -1312,7 +1335,7 @@ void frmMain::StoreServers()
|
|||
{
|
||||
wxString key;
|
||||
++numServers;
|
||||
if (cursoritem==serveritem) selServerName=server->GetName();
|
||||
if (cursoritem==serveritem) selServerName=browser->GetItemText((serveritem));
|
||||
key.Printf(wxT("Servers/%d/"), numServers);
|
||||
settings->Write(key + wxT("Server"), server->GetName());
|
||||
settings->Write(key + wxT("HostAddr"), server->GetHostAddr());
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ wxWindow *pluginUtilityFactory::StartDialog(frmMain *form, pgObject *obj)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern pluginUtilityFactory *puttyTunnel;
|
||||
bool pluginUtilityFactory::CheckEnable(pgObject *obj)
|
||||
{
|
||||
// First check that this is one of the supported server types
|
||||
|
|
@ -403,7 +403,6 @@ bool pluginUtilityFactory::CheckEnable(pgObject *obj)
|
|||
if (server_types.Index(serverType) == wxNOT_FOUND)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now check that this is one of the supported object types
|
||||
// for this plugin. If none are specified, then anything goes
|
||||
if (obj && applies_to.Count() > 0)
|
||||
|
|
@ -414,11 +413,14 @@ bool pluginUtilityFactory::CheckEnable(pgObject *obj)
|
|||
else {
|
||||
//"puttyforward"
|
||||
int id=GetId();
|
||||
if (winMain==NULL) return false;
|
||||
wxMenu *m=winMain->GetPluginsMenu();
|
||||
m->SetLabel(id,"[Putty tunnel forward]");
|
||||
wxMenu *m=NULL;
|
||||
if (winMain) {
|
||||
m=winMain->GetPluginsMenu();
|
||||
m->SetLabel(id,"[Putty tunnel forward]");
|
||||
}
|
||||
if (obj->GetMetaType()==PGM_SERVER) {
|
||||
pgServer* srv = (pgServer*) obj;
|
||||
srv->SetPuttyTunnel(NULL);
|
||||
wxString host=obj->GetName();
|
||||
wxString sport=NumToStr((long)srv->GetPort());
|
||||
wxString f ;
|
||||
|
|
@ -447,8 +449,10 @@ bool pluginUtilityFactory::CheckEnable(pgObject *obj)
|
|||
if (port.Len()>0 && port[0]=='L' && sport==port.substr(1)) {
|
||||
// found putty config
|
||||
title=filename;
|
||||
m->SetLabel(id,title);
|
||||
if (winMain) m->SetLabel(id,title);
|
||||
isfound=true;
|
||||
srv->SetPuttyTunnel(this);
|
||||
if (!winMain) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ wxSize GetBestSize(wxGrid& grid,
|
|||
|
||||
public:
|
||||
void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
|
||||
const wxRect& rect, int row, int col, bool isSelected);
|
||||
const wxRect& rect, int row, int col, bool isSelected) wxOVERRIDE;
|
||||
CursorCellRenderer(int thous_pixel_sep);
|
||||
private:
|
||||
int thousands_pixel_sep;
|
||||
|
|
|
|||
|
|
@ -36,15 +36,17 @@ public:
|
|||
|
||||
private:
|
||||
void OnChangeServer(wxCommandEvent &ev);
|
||||
void OnChangeGroup(wxCommandEvent &ev);
|
||||
void OnChangeDatabase(wxCommandEvent &ev);
|
||||
void OnTextChange(wxCommandEvent &ev);
|
||||
void OnOK(wxCommandEvent &ev);
|
||||
void OnCancel(wxCommandEvent &ev);
|
||||
|
||||
bool BuildServerCombo(pgConn *conn);
|
||||
pgServer *remoteServer;
|
||||
wxBitmapComboBox *cbConnection;
|
||||
ctlComboBoxFix *cbServer;
|
||||
wxComboBox *cbDatabase, *cbUsername, *cbRolename;
|
||||
pgConn *currconn;
|
||||
wxComboBox *cbDatabase, *cbUsername, *cbRolename, *cbGroup;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
class frmMain;
|
||||
class pgServer;
|
||||
class pluginUtilityFactory;
|
||||
|
||||
class pgServerFactory : public pgaFactory
|
||||
{
|
||||
|
|
@ -366,6 +367,10 @@ public:
|
|||
void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0);
|
||||
void ShowHint(frmMain *form, bool force);
|
||||
void ShowStatistics(frmMain *form, ctlListView *statistics);
|
||||
void SetPuttyTunnel(pluginUtilityFactory *puttytunnel) {
|
||||
puttyTunnel=puttytunnel;
|
||||
}
|
||||
pluginUtilityFactory* GetPuttyTunnel() {return puttyTunnel;}
|
||||
wxString GetHelpPage(bool forCreate) const
|
||||
{
|
||||
return wxT("pg/managing-databases");
|
||||
|
|
@ -448,6 +453,7 @@ public:
|
|||
{
|
||||
sslcompression = b;
|
||||
}
|
||||
|
||||
|
||||
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
|
||||
//SSH Tunnel
|
||||
|
|
@ -560,6 +566,7 @@ private:
|
|||
bool inRecovery, replayPaused;
|
||||
wxString receiveLoc, replayLoc, replayTimestamp;
|
||||
wxDateTime confLoadedSince;
|
||||
pluginUtilityFactory *puttyTunnel=NULL; // if exists putty tunnel for pgServer
|
||||
|
||||
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
|
||||
bool createSSHTunnel();
|
||||
|
|
|
|||
|
|
@ -282,6 +282,7 @@ wxString qtTypeIdent(const wxString &value); // add " if necessary
|
|||
bool make_identifier(const wxString &strname, wxString &s, wxString &n, bool islower);
|
||||
wxSize getScreenSizeForPoint(const wxPoint screenPos);
|
||||
void showHelpHtml(wxWindow *parent, const wxString &htmlHelp,wxPoint screenPos, wxSize size);
|
||||
bool isPortOpen(const wxString& host, int port , int timeout_ms);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -202,7 +202,10 @@ public:
|
|||
wxDataObjectComposite* dataobj = new wxDataObjectComposite();
|
||||
dataobj->Add(new wxHTMLDataObject(h));
|
||||
wxTheClipboard->SetData(dataobj);
|
||||
wxTheClipboard->Close();
|
||||
// fix for linux app crush
|
||||
wxSafeYield();
|
||||
wxTheClipboard->Close(); // crush app without wxSafeYield();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,39 +2,43 @@
|
|||
<resource>
|
||||
<object class="wxDialog" name="dlgSelectConnection">
|
||||
<title>Connect to Server</title>
|
||||
<size>205,98d</size>
|
||||
<size>205,109d</size>
|
||||
<style>wxDEFAULT_DIALOG_STYLE|wxCAPTION|wxSYSTEM_MENU</style>
|
||||
<object class="wxStaticText" name="stGroup">
|
||||
<label>Group</label>
|
||||
<pos>5,7d</pos>
|
||||
</object>
|
||||
<object class="wxStaticText" name="stServer">
|
||||
<label>Server</label>
|
||||
<pos>5,7d</pos>
|
||||
<pos>5,22d</pos>
|
||||
</object>
|
||||
<object class="wxStaticText" name="stDatabase">
|
||||
<label>Database</label>
|
||||
<pos>5,22d</pos>
|
||||
<pos>5,37d</pos>
|
||||
</object>
|
||||
<object class="wxStaticText" name="stUsername">
|
||||
<label>Username</label>
|
||||
<pos>5,37d</pos>
|
||||
<pos>5,54d</pos>
|
||||
</object>
|
||||
<object class="wxStaticText" name="stRolename">
|
||||
<label>Rolename</label>
|
||||
<pos>5,54d</pos>
|
||||
<pos>5,80d</pos>
|
||||
</object>
|
||||
<object class="wxButton" name="wxID_HELP">
|
||||
<label>&Help</label>
|
||||
<pos>2,80d</pos>
|
||||
<pos>2,95d</pos>
|
||||
<style></style>
|
||||
</object>
|
||||
<object class="wxButton" name="wxID_OK">
|
||||
<label>&OK</label>
|
||||
<default>1</default>
|
||||
<pos>97,80d</pos>
|
||||
<pos>97,95d</pos>
|
||||
<style></style>
|
||||
</object>
|
||||
<object class="wxButton" name="wxID_CANCEL">
|
||||
<label>&Cancel</label>
|
||||
<default>0</default>
|
||||
<pos>150,80d</pos>
|
||||
<pos>150,95d</pos>
|
||||
</object>
|
||||
</object>
|
||||
</resource>
|
||||
|
|
|
|||
82064
ui/xrcDialogs.cpp
82064
ui/xrcDialogs.cpp
File diff suppressed because it is too large
Load diff
|
|
@ -972,16 +972,16 @@ int FormatterSQL::ParseSql(int flags) {
|
|||
vi.txt = tmp;
|
||||
vi.type = keyword;
|
||||
vi.flags = flg;
|
||||
if (tmp == "from" && i2 >= 2) {
|
||||
if (tmp == "from" && i2 >= 2) { // special case "distinct from" this no "from"
|
||||
wxString s = items[items.size() - 2].txt;
|
||||
if (s.Len() >= 8 && s.substr(s.Len() - 8).CmpNoCase("distinct") == 0) {
|
||||
vi.flags = 0;
|
||||
}
|
||||
}
|
||||
if (keyEntities[n].name == "case") {
|
||||
if (strcmp(keyEntities[n].name,"case") == 0) {
|
||||
bracket.push(items.size());
|
||||
}
|
||||
else if (keyEntities[n].name == "end") {
|
||||
else if (strcmp(keyEntities[n].name,"end") == 0) {
|
||||
int idx = -1;
|
||||
if (bracket.size() > 0) {
|
||||
idx = bracket.top();
|
||||
|
|
@ -994,14 +994,17 @@ int FormatterSQL::ParseSql(int flags) {
|
|||
vi.endlevel = idx;
|
||||
if (idx != -1) items[idx].endlevel = items.size();
|
||||
|
||||
} else if (keyEntities[n].name == "then"||
|
||||
keyEntities[n].name == "loop" ) { // for plpgsql
|
||||
} else if (strcmp(keyEntities[n].name, "then")== 0 ||
|
||||
strcmp(keyEntities[n].name,"loop") == 0 ) { // for plpgsql query without ";"
|
||||
// if ... then
|
||||
// while ... loop or for .. in query loop
|
||||
|
||||
// special break parse query ONLY recurse level == 0
|
||||
if (bracket.size() == 0) {
|
||||
i=i+tmp.Len()-1;
|
||||
i=i+tmp.Len()-1; // skip stop keyword
|
||||
break;
|
||||
}
|
||||
//
|
||||
}
|
||||
}
|
||||
i += tmp.Len() - 1;
|
||||
|
|
|
|||
|
|
@ -1535,5 +1535,49 @@ void showHelpHtml(wxWindow *parent, const wxString &htmlHelp,wxPoint screenPos,
|
|||
|
||||
}
|
||||
|
||||
#include <wx/socket.h>
|
||||
|
||||
|
||||
bool isPortOpen(const wxString& host, int port , int timeout_ms) {
|
||||
wxSocketClient client;
|
||||
//client.SetTimeout(1); // 1 секунда таймаут (можно уменьшить до 0.5 или 0.2)
|
||||
|
||||
wxIPV4address addr;
|
||||
addr.Hostname(host);
|
||||
addr.Service(port);
|
||||
// Issue the connection request
|
||||
client.Connect(addr, false);
|
||||
|
||||
// Wait until the request completes or until we decide to give up
|
||||
while ( !client.WaitOnConnect(0, timeout_ms) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
bool success = client.IsConnected();
|
||||
return success;
|
||||
|
||||
/* int sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
inet_pton(AF_INET, host.c_str(), &addr.sin_addr);
|
||||
|
||||
// Установка таймаута (опционально, для ускорения)
|
||||
timeval tv{};
|
||||
tv.tv_sec = timeout_ms / 1000;
|
||||
tv.tv_usec = (timeout_ms % 1000) * 1000;
|
||||
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
|
||||
int result = connect(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
|
||||
|
||||
close(sock);
|
||||
|
||||
return result == 0; // true, если порт открыт (сервер принимает соединения)
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue