mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-31 07:12:39 -06:00
*Core: Fixing TcpSocket connection behaviour when server unavailable
git-svn-id: svn://ultimatepp.org/upp/trunk@5070 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
fdcf80446f
commit
3d81121473
8 changed files with 140 additions and 94 deletions
|
|
@ -84,6 +84,9 @@ class TcpSocket {
|
|||
|
||||
int global_timeout;
|
||||
int start_time;
|
||||
#ifdef PLATFORM_WIN32
|
||||
int connection_start;
|
||||
#endif
|
||||
|
||||
int errorcode;
|
||||
String errordesc;
|
||||
|
|
@ -139,7 +142,7 @@ class TcpSocket {
|
|||
void SetSockError(const char *context);
|
||||
|
||||
static int GetErrorCode();
|
||||
static bool WouldBlock();
|
||||
bool WouldBlock();
|
||||
static void Init();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -274,6 +274,9 @@ TcpSocket::TcpSocket()
|
|||
waitstep = 10;
|
||||
asn1 = false;
|
||||
global_timeout = Null;
|
||||
#ifdef PLATFORM_WIN32
|
||||
connection_start = Null;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool TcpSocket::Open(int family, int type, int protocol)
|
||||
|
|
@ -285,6 +288,7 @@ bool TcpSocket::Open(int family, int type, int protocol)
|
|||
return false;
|
||||
LLOG("TcpSocket::Data::Open() -> " << (int)socket);
|
||||
#ifdef PLATFORM_WIN32
|
||||
connection_start = msecs();
|
||||
u_long arg = 1;
|
||||
if(ioctlsocket(socket, FIONBIO, &arg))
|
||||
SetSockError("ioctlsocket(FIO[N]BIO)");
|
||||
|
|
@ -489,7 +493,9 @@ bool TcpSocket::WouldBlock()
|
|||
return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN);
|
||||
#endif
|
||||
#ifdef PLATFORM_WIN32
|
||||
return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(ENOTCONN);
|
||||
if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000)
|
||||
return true;
|
||||
return c == SOCKERR(EWOULDBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -571,8 +577,12 @@ bool TcpSocket::RawWait(dword flags, int end_time)
|
|||
SetSockError("wait");
|
||||
return false;
|
||||
}
|
||||
if(avail > 0)
|
||||
if(avail > 0) {
|
||||
#ifdef PLATFORM_WIN32
|
||||
connection_start = Null;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
if(IsGlobalTimeout())
|
||||
return false;
|
||||
if(to <= 0 && timeout)
|
||||
|
|
@ -597,8 +607,14 @@ bool TcpSocket::Wait(dword flags, int end_time)
|
|||
|
||||
int TcpSocket::GetEndTime() const
|
||||
{
|
||||
return min(IsNull(global_timeout) ? INT_MAX : start_time + global_timeout,
|
||||
IsNull(timeout) ? INT_MAX : msecs() + timeout);
|
||||
int o = min(IsNull(global_timeout) ? INT_MAX : start_time + global_timeout,
|
||||
IsNull(timeout) ? INT_MAX : msecs() + timeout);
|
||||
#ifdef PLATFORM_WIN32
|
||||
if(GetErrorCode() == SOCKERR(ENOTCONN) && !IsNull(connection_start))
|
||||
if(msecs(connection_start) < 20000)
|
||||
o = connection_start + 20000;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
bool TcpSocket::Wait(dword flags)
|
||||
|
|
|
|||
|
|
@ -317,6 +317,8 @@ public:
|
|||
void SetEditPos(const EditPos& o);
|
||||
|
||||
void SerializeSettings(Stream& s);
|
||||
|
||||
void HideList() { list.Hide(); }
|
||||
|
||||
typedef IconDes CLASSNAME;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,28 @@
|
|||
#ifndef _ide_IconDes_IconDes_h_
|
||||
#define _ide_IconDes_IconDes_h_
|
||||
|
||||
#include <ide/Common/Common.h>
|
||||
#include <IconDes/IconDes.h>
|
||||
|
||||
struct IdeImgView : IdeDesigner, Ctrl {
|
||||
Size img_sz;
|
||||
Image img;
|
||||
String filename;
|
||||
|
||||
virtual void Paint(Draw& w);
|
||||
|
||||
virtual String GetFileName() const { return filename; }
|
||||
virtual void EditMenu(Bar& menu);
|
||||
virtual void Save() {}
|
||||
virtual Ctrl& DesignerCtrl() { return *this; }
|
||||
|
||||
typedef IdeImgView CLASSNAME;
|
||||
};
|
||||
|
||||
#ifndef _ide_ImgDes_ImgDes_h_
|
||||
#define _ide_ImgDes_ImgDes_h_
|
||||
|
||||
#include <ide/Common/Common.h>
|
||||
#include <ide/IconDes/IconDes.h>
|
||||
|
||||
struct IdeImgView : IdeDesigner, Ctrl {
|
||||
Size img_sz;
|
||||
Image img;
|
||||
String filename;
|
||||
|
||||
virtual void Paint(Draw& w);
|
||||
|
||||
virtual String GetFileName() const { return filename; }
|
||||
virtual void EditMenu(Bar& menu);
|
||||
virtual void Save() {}
|
||||
virtual Ctrl& DesignerCtrl() { return *this; }
|
||||
|
||||
typedef IdeImgView CLASSNAME;
|
||||
};
|
||||
|
||||
struct IdePngDes : IdeIconDes {
|
||||
virtual void Save();
|
||||
|
||||
void Load(const char *filename);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,64 +1,71 @@
|
|||
#include "Img.h"
|
||||
|
||||
void IdeImgView::Paint(Draw& w)
|
||||
{
|
||||
Size sz = GetSize();
|
||||
String t = (img_sz != img.GetSize() ? "Resized from: " : "Image size: ");
|
||||
t << Format("%d x %d", img_sz.cx, img_sz.cy);
|
||||
int tcy = Draw::GetStdFontCy();
|
||||
w.DrawRect(0, 0, sz.cx, tcy, SColorFace());
|
||||
w.DrawText(5, 0, t, StdFont(), SColorText());
|
||||
int ii = 0;
|
||||
for(int x = 0; x < sz.cx; x += 16) {
|
||||
int jj = ii;
|
||||
for(int y = tcy; y < sz.cy; y += 16)
|
||||
w.DrawRect(x, y, 16, 16, jj++ & 1 ? LtGray() : WhiteGray());
|
||||
ii++;
|
||||
}
|
||||
w.DrawImage(5, 5 + tcy, img);
|
||||
}
|
||||
|
||||
void IdeImgView::EditMenu(Bar& menu)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool IsImgFile(const String& path)
|
||||
{
|
||||
String s = ToLower(GetFileExt(path));
|
||||
return s == ".png" || s == ".jpg" || s == ".gif" || s == ".bmp";
|
||||
}
|
||||
|
||||
struct ImageViewModule : public IdeModule {
|
||||
virtual void CleanUsc() {}
|
||||
virtual bool ParseUsc(CParser& p) { return false; }
|
||||
virtual Image FileIcon(const char *path) {
|
||||
return IsImgFile(path) ? IconDesImg::FileIcon() : Null;
|
||||
}
|
||||
virtual IdeDesigner *CreateDesigner(const char *path, byte) {
|
||||
if(IsImgFile(path)) {
|
||||
FileIn in(path);
|
||||
One<StreamRaster> o = StreamRaster::OpenAny(in);
|
||||
if(o) {
|
||||
Size sz = o->GetSize();
|
||||
IdeImgView *d = new IdeImgView;
|
||||
d->img_sz = sz;
|
||||
d->filename = path;
|
||||
if(sz.cx < 1024 && sz.cy < 768)
|
||||
d->img = o->GetImage();
|
||||
else {
|
||||
ImageEncoder m;
|
||||
Rescale(m, GetFitSize(sz, Size(1024, 768)), *o, sz);
|
||||
d->img = m;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
INITBLOCK
|
||||
{
|
||||
RegisterIdeModule(Single<ImageViewModule>());
|
||||
}
|
||||
#include "Img.h"
|
||||
|
||||
void IdeImgView::Paint(Draw& w)
|
||||
{
|
||||
Size sz = GetSize();
|
||||
String t = (img_sz != img.GetSize() ? "Resized from: " : "Image size: ");
|
||||
t << Format("%d x %d", img_sz.cx, img_sz.cy);
|
||||
int tcy = Draw::GetStdFontCy();
|
||||
w.DrawRect(0, 0, sz.cx, tcy, SColorFace());
|
||||
w.DrawText(5, 0, t, StdFont(), SColorText());
|
||||
int ii = 0;
|
||||
for(int x = 0; x < sz.cx; x += 16) {
|
||||
int jj = ii;
|
||||
for(int y = tcy; y < sz.cy; y += 16)
|
||||
w.DrawRect(x, y, 16, 16, jj++ & 1 ? LtGray() : WhiteGray());
|
||||
ii++;
|
||||
}
|
||||
w.DrawImage(5, 5 + tcy, img);
|
||||
}
|
||||
|
||||
void IdeImgView::EditMenu(Bar& menu)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool IsImgFile(const String& path)
|
||||
{
|
||||
String s = ToLower(GetFileExt(path));
|
||||
return s == ".png" || s == ".jpg" || s == ".gif" || s == ".bmp";
|
||||
}
|
||||
|
||||
struct ImageViewModule : public IdeModule {
|
||||
virtual void CleanUsc() {}
|
||||
virtual bool ParseUsc(CParser& p) { return false; }
|
||||
virtual Image FileIcon(const char *path) {
|
||||
return IsImgFile(path) ? IconDesImg::FileIcon() : Null;
|
||||
}
|
||||
virtual IdeDesigner *CreateDesigner(const char *path, byte) {
|
||||
if(IsImgFile(path)) {
|
||||
FileIn in(path);
|
||||
One<StreamRaster> o = StreamRaster::OpenAny(in);
|
||||
if(o) {
|
||||
Size sz = o->GetSize();
|
||||
if(ToLower(GetFileExt(path)) == ".png" && sz.cx <= 768 && sz.cy <= 512) {
|
||||
IdePngDes *d = new IdePngDes;
|
||||
d->Load(path);
|
||||
return d;
|
||||
}
|
||||
else {
|
||||
IdeImgView *d = new IdeImgView;
|
||||
d->img_sz = sz;
|
||||
d->filename = path;
|
||||
if(sz.cx <= 1024 && sz.cy <= 768)
|
||||
d->img = o->GetImage();
|
||||
else {
|
||||
ImageEncoder m;
|
||||
Rescale(m, GetFitSize(sz, Size(1024, 768)), *o, sz);
|
||||
d->img = m;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
INITBLOCK
|
||||
{
|
||||
RegisterIdeModule(Single<ImageViewModule>());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ description "\377B";
|
|||
|
||||
file
|
||||
Img.h,
|
||||
ImgEdit.cpp,
|
||||
Png.cpp,
|
||||
Img.icpp;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
#include "Img.h"
|
||||
|
||||
//
|
||||
15
uppsrc/ide/Img/Png.cpp
Normal file
15
uppsrc/ide/Img/Png.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include "Img.h"
|
||||
|
||||
void IdePngDes::Save()
|
||||
{
|
||||
}
|
||||
|
||||
void IdePngDes::Load(const char *_filename)
|
||||
{
|
||||
Clear();
|
||||
filename = _filename;
|
||||
filetime = FileGetTime(filename);
|
||||
Image m = StreamRaster::LoadFileAny(filename);
|
||||
AddImage(filename, m, false);
|
||||
HideList();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue