Browse Source

Merge branch 'unicode_translation' of https://github.com/CendioAlex/tigervnc

tags/v1.10.90
Pierre Ossman 4 years ago
parent
commit
8b4be5fd8e
3 changed files with 38 additions and 35 deletions
  1. 4
    7
      common/network/TcpSocket.cxx
  2. 27
    26
      common/rdr/Exception.cxx
  3. 7
    2
      common/rdr/Exception.h

+ 4
- 7
common/network/TcpSocket.cxx View File

hints.ai_next = NULL; hints.ai_next = NULL;


if ((result = getaddrinfo(host, NULL, &hints, &ai)) != 0) { if ((result = getaddrinfo(host, NULL, &hints, &ai)) != 0) {
throw Exception("unable to resolve host by name: %s",
gai_strerror(result));
throw GAIException("unable to resolve host by name", result);
} }


sock = -1; sock = -1;
if (err == 0) if (err == 0)
throw Exception("No useful address for host"); throw Exception("No useful address for host");
else else
throw SocketException("unable connect to socket", err);
throw SocketException("unable to connect to socket", err);
} }


// Take proper ownership of the socket // Take proper ownership of the socket
snprintf (service, sizeof (service) - 1, "%d", port); snprintf (service, sizeof (service) - 1, "%d", port);
service[sizeof (service) - 1] = '\0'; service[sizeof (service) - 1] = '\0';
if ((result = getaddrinfo(addr, service, &hints, &ai)) != 0) if ((result = getaddrinfo(addr, service, &hints, &ai)) != 0)
throw rdr::Exception("unable to resolve listening address: %s",
gai_strerror(result));
throw GAIException("unable to resolve listening address", result);


try { try {
createTcpListeners(listeners, ai); createTcpListeners(listeners, ai);
} }


if ((result = getaddrinfo (p, NULL, &hints, &ai)) != 0) { if ((result = getaddrinfo (p, NULL, &hints, &ai)) != 0) {
throw Exception("unable to resolve host by name: %s",
gai_strerror(result));
throw GAIException("unable to resolve host by name", result);
} }


memcpy (&pattern.address.u.sa, ai->ai_addr, ai->ai_addrlen); memcpy (&pattern.address.u.sa, ai->ai_addr, ai->ai_addrlen);

+ 27
- 26
common/rdr/Exception.cxx View File

#include <tchar.h> #include <tchar.h>
#include <winsock2.h> #include <winsock2.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h>
#else
#include <netdb.h>
#endif #endif


#include <string.h> #include <string.h>
va_end(ap); va_end(ap);
} }


SystemException::SystemException(const char* s, int err_)
: Exception("%s", s), err(err_)
GAIException::GAIException(const char* s, int err)
: Exception("%s", s)
{ {
strncat(str_, ": ", len-1-strlen(str_)); strncat(str_, ": ", len-1-strlen(str_));
#ifdef _WIN32 #ifdef _WIN32
// Windows error messages are crap, so use unix ones for common errors.
const char* msg = 0;
switch (err) {
case WSAECONNREFUSED: msg = "Connection refused"; break;
case WSAETIMEDOUT: msg = "Connection timed out"; break;
case WSAECONNRESET: msg = "Connection reset by peer"; break;
case WSAECONNABORTED: msg = "Connection aborted"; break;
}
if (msg) {
strncat(str_, msg, len-1-strlen(str_));
} else {
#ifdef UNICODE
WCHAR* tmsg = new WCHAR[len-strlen(str_)];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
0, err, 0, tmsg, len-1-strlen(str_), 0);
WideCharToMultiByte(CP_ACP, 0, tmsg, wcslen(tmsg)+1,
str_+strlen(str_), len-strlen(str_), 0, 0);
delete [] tmsg;
wchar_t currStr[len-strlen(str_)];
wcsncpy(currStr, gai_strerrorW(err), len-1-strlen(str_));
WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_),
len-1-strlen(str_), 0, 0);
#else #else
char* currStr = str_+strlen(str_);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
0, err, 0, currStr, len-1-strlen(str_), 0);
//FIXME: perhaps print the error number (NNNN)
strncat(str_, gai_strerror(err), len-1-strlen(str_));
#endif #endif
int l = strlen(str_);
if ((l >= 2) && (str_[l-2] == '\r') && (str_[l-1] == '\n'))
}

SystemException::SystemException(const char* s, int err_)
: Exception("%s", s), err(err_)
{
strncat(str_, ": ", len-1-strlen(str_));
#ifdef _WIN32
wchar_t *currStr = new wchar_t[len-strlen(str_)];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
0, err, 0, currStr, len-1-strlen(str_), 0);
WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_),
len-1-strlen(str_), 0, 0);
delete [] currStr;

int l = strlen(str_);
if ((l >= 2) && (str_[l-2] == '\r') && (str_[l-1] == '\n'))
str_[l-2] = 0; str_[l-2] = 0;
}


#else #else
strncat(str_, strerror(err), len-1-strlen(str_)); strncat(str_, strerror(err), len-1-strlen(str_));

+ 7
- 2
common/rdr/Exception.h View File

struct SystemException : public Exception { struct SystemException : public Exception {
int err; int err;
SystemException(const char* s, int err_); SystemException(const char* s, int err_);
};
};

struct GAIException : public Exception {
int err;
GAIException(const char* s, int err_);
};


struct TimedOut : public Exception { struct TimedOut : public Exception {
TimedOut() : Exception("Timed out") {} TimedOut() : Exception("Timed out") {}
}; };
struct EndOfStream : public Exception { struct EndOfStream : public Exception {
EndOfStream() : Exception("End of stream") {} EndOfStream() : Exception("End of stream") {}
}; };

Loading…
Cancel
Save