[pan2] glib fixes for 2.31.3 : https://bugzilla.gnome.org/show_bug.cgi?id=665289 reverted gio, doesn't work
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] glib fixes for 2.31.3 : https://bugzilla.gnome.org/show_bug.cgi?id=665289 reverted gio, doesn't work
- Date: Sat, 3 Dec 2011 21:02:52 +0000 (UTC)
commit 365e28759852f6b16a384f826c60b9efa93053dd
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date: Sat Dec 3 09:52:29 2011 +0100
glib fixes for 2.31.3 : https://bugzilla.gnome.org/show_bug.cgi?id=665289
reverted gio, doesn't work with win32, perhaps later...
bla
configure.in | 2 +-
pan/data-impl/data-impl.cc | 2 +-
pan/data/article-cache.h | 2 +-
pan/general/file-util.h | 2 +-
pan/general/locking.h | 2 +-
pan/general/macros.h | 5 +-
pan/general/time-elapsed.h | 4 +-
pan/general/worker-pool.cc | 2 +-
pan/general/worker-pool.h | 3 +-
pan/gui/pan.cc | 2 +-
pan/gui/render-bytes.cc | 2 +-
pan/gui/render-bytes.h | 2 +-
pan/tasks/socket-impl-gio.cc | 230 ++++++++++++++++++++++++++++++++++---
pan/tasks/socket-impl-gio.h | 3 +-
pan/usenet-utils/mime-utils.h | 2 +-
pan/usenet-utils/text-massager.cc | 1 -
16 files changed, 227 insertions(+), 39 deletions(-)
---
diff --git a/configure.in b/configure.in
index 6a29f68..9756d28 100644
--- a/configure.in
+++ b/configure.in
@@ -44,7 +44,7 @@ dnl
dnl GtkSpell is optional: GTKSPELL_REQUIRED refers to the minimum version
dnl needed if you want to build Pan with spellchecking in the Post window.
-GLIB_REQUIRED=2.14.0
+GLIB_REQUIRED=2.28.6
GMIME_REQUIRED=2.4.0
GTK_REQUIRED=2.16.0
GTK3_REQUIRED=3.0.0
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index 9f6bc53..c8f3fd4 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -24,7 +24,7 @@
#include <config.h>
extern "C" {
#include <glib/gi18n.h>
- #include <glib/gfileutils.h> // for g_build_filename
+ #include <glib.h> // for g_build_filename
}
#include <pan/general/debug.h>
#include <pan/general/file-util.h>
diff --git a/pan/data/article-cache.h b/pan/data/article-cache.h
index 6780fad..ba07e95 100644
--- a/pan/data/article-cache.h
+++ b/pan/data/article-cache.h
@@ -23,7 +23,7 @@
#include <map>
#include <vector>
extern "C" {
- #include <glib/gtypes.h> // for guint64
+ #include <glib.h> // for guint64
}
#include <pan/general/string-view.h>
#include <pan/general/quark.h>
diff --git a/pan/general/file-util.h b/pan/general/file-util.h
index a81f751..48aeda9 100644
--- a/pan/general/file-util.h
+++ b/pan/general/file-util.h
@@ -25,7 +25,7 @@
extern "C" {
#include <stddef.h>
#include <stdio.h>
- #include <glib/gtypes.h>
+ #include <glib.h>
#include <glib/gstdio.h>
}
#include <pan/general/string-view.h>
diff --git a/pan/general/locking.h b/pan/general/locking.h
index 0217ff9..4850576 100644
--- a/pan/general/locking.h
+++ b/pan/general/locking.h
@@ -22,7 +22,7 @@
#ifndef _Mutex_h_
#define _Mutex_h_
-#include <glib/gthread.h>
+#include <glib.h>
namespace pan
{
diff --git a/pan/general/macros.h b/pan/general/macros.h
index 6d4a293..d9c6050 100644
--- a/pan/general/macros.h
+++ b/pan/general/macros.h
@@ -62,12 +62,11 @@
extern "C"
{
- #include <glibconfig.h> // get the version
- #include <glib/gutils.h> // get GLIB_CHECK_VERSION
+ #include <glib.h>
// pick up g_assert()
#if GLIB_CHECK_VERSION(2,16,0)
- #include <glib/gtestutils.h>
+ #include <glib.h>
#else
#include <glib/gmessages.h>
#endif
diff --git a/pan/general/time-elapsed.h b/pan/general/time-elapsed.h
index 255e7c5..7dd5594 100644
--- a/pan/general/time-elapsed.h
+++ b/pan/general/time-elapsed.h
@@ -1,9 +1,7 @@
#ifndef __Time_Elapsed_h__
#define __Time_Elapsed_h__
-#include <glib/gtypes.h> // for GTimeVal
-#include <glib/gmain.h> // for g_get_current_time
-#include <glib/gtimer.h> // for GUSEC_PER_SEC
+#include <glib.h>
namespace pan
{
diff --git a/pan/general/worker-pool.cc b/pan/general/worker-pool.cc
index 6ff4b76..e33dcc7 100644
--- a/pan/general/worker-pool.cc
+++ b/pan/general/worker-pool.cc
@@ -21,7 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <cassert>
-#include <glib/gmain.h> // for g_idle_add
+#include <glib.h> // for g_idle_add
#include <pan/general/debug.h>
#include <pan/general/macros.h>
#include "worker-pool.h"
diff --git a/pan/general/worker-pool.h b/pan/general/worker-pool.h
index 302b46e..9999d67 100644
--- a/pan/general/worker-pool.h
+++ b/pan/general/worker-pool.h
@@ -24,8 +24,7 @@
#define _Worker_Pool_H_
#include <set>
-#include <glib/gtypes.h>
-#include <glib/gthreadpool.h>
+#include <glib.h>
namespace pan
{
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index 6b1c5c7..413e2e9 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -522,7 +522,7 @@ main (int argc, char *argv[])
///////////// DBUS
-
+ /// TODO : make it work with win32
Pan pan(data, queue, cache, prefs, group_prefs);
#ifndef G_OS_WIN32
pan_dbus_init(&pan);
diff --git a/pan/gui/render-bytes.cc b/pan/gui/render-bytes.cc
index 3d4577f..f1b513a 100644
--- a/pan/gui/render-bytes.cc
+++ b/pan/gui/render-bytes.cc
@@ -1,4 +1,4 @@
-#include <glib/gutils.h> // g_snprintf
+#include <glib.h> // g_snprintf
#include "render-bytes.h"
namespace pan
diff --git a/pan/gui/render-bytes.h b/pan/gui/render-bytes.h
index 0659daf..9f5b50a 100644
--- a/pan/gui/render-bytes.h
+++ b/pan/gui/render-bytes.h
@@ -1,6 +1,6 @@
#ifndef RENDER_BYTES_H
#define RENDER_BYTES_H
-#include <glib/gtypes.h>
+#include <glib.h>
namespace pan {
extern char* render_bytes (guint64);
}
diff --git a/pan/tasks/socket-impl-gio.cc b/pan/tasks/socket-impl-gio.cc
index 7930e73..e02b78e 100644
--- a/pan/tasks/socket-impl-gio.cc
+++ b/pan/tasks/socket-impl-gio.cc
@@ -32,7 +32,6 @@
extern "C" {
#include <unistd.h>
#include <glib/gi18n.h>
- #include <gio/gio.h>
}
#include <pan/general/file-util.h>
@@ -40,6 +39,51 @@ extern "C" {
#include <pan/general/macros.h>
#include <pan/general/worker-pool.h>
+#ifdef G_OS_WIN32
+ // this #define is necessary for mingw
+ #define _WIN32_WINNT 0x0501
+ #include <ws2tcpip.h>
+ #undef gai_strerror
+ /*
+ #define gai_strerror(i) gai_strerror_does_not_link (i)
+ static const char*
+ gai_strerror_does_not_link (int errval)
+ {
+ static char buf[32];
+ g_snprintf (buf, sizeof(buf), "Winsock error %d", errval);
+ return buf;
+ }
+ */
+ static const char*
+ get_last_error (int err)
+ {
+ const char * msg = 0;
+ switch(err) {
+ case WSANOTINITIALISED: msg = "No successful WSAStartup call yet."; break;
+ case WSAENETDOWN: msg = "The network subsystem has failed."; break;
+ case WSAEADDRINUSE: msg = "Fully qualified address already bound"; break;
+ case WSAEADDRNOTAVAIL: msg = "The specified address is not a valid address for this computer."; break;
+ case WSAEFAULT: msg = "Error in socket address"; break;
+ case WSAEINPROGRESS: msg = "A call is already in progress"; break;
+ case WSAEINVAL: msg = "The socket is already bound to an address."; break;
+ case WSAENOBUFS: msg = "Not enough buffers available, too many connections."; break;
+ case WSAENOTSOCK: msg = "The descriptor is not a socket."; break;
+ case 11001: msg = "Host not found"; break;
+ default: msg = "Connect failed";
+ }
+ return msg;
+ }
+
+#else
+ #include <signal.h>
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
+ #include <arpa/inet.h>
+ #define closesocket(fd) close(fd)
+#endif
+
#include <pan/general/debug.h>
#include <pan/general/log.h>
#include <pan/general/string-view.h>
@@ -50,39 +94,184 @@ using namespace pan;
namespace
{
- const unsigned int TIMEOUT_SECS (30);
-}
+ typedef int (*t_getaddrinfo)(const char *,const char *, const struct addrinfo*, struct addrinfo **);
+ t_getaddrinfo p_getaddrinfo (0);
-namespace
-{
+ typedef void (*t_freeaddrinfo)(struct addrinfo*);
+ t_freeaddrinfo p_freeaddrinfo (0);
+
+ void ensure_module_inited (void)
+ {
+ static bool inited (false);
+
+ if (!inited)
+ {
+ p_freeaddrinfo=NULL;
+ p_getaddrinfo=NULL;
+
+#ifdef G_OS_WIN32
+ WSADATA wsaData;
+ WSAStartup(MAKEWORD(2,2), &wsaData);
+
+ char sysdir[MAX_PATH], path[MAX_PATH+8];
+
+ if(GetSystemDirectory(sysdir,MAX_PATH)!=0)
+ {
+ HMODULE lib=NULL;
+ FARPROC pfunc=NULL;
+ const char *libs[]={"ws2_32","wship6",NULL};
+
+ for(const char **p=libs;*p!=NULL;++p)
+ {
+ g_snprintf(path,MAX_PATH+8,"%s\\%s",sysdir,*p);
+ lib=LoadLibrary(path);
+ if(!lib)
+ continue;
+ pfunc=GetProcAddress(lib,"getaddrinfo");
+ if(!pfunc)
+ {
+ FreeLibrary(lib);
+ lib=NULL;
+ continue;
+ }
+ p_getaddrinfo=reinterpret_cast<t_getaddrinfo>(pfunc);
+ pfunc=GetProcAddress(lib,"freeaddrinfo");
+ if(!pfunc)
+ {
+ FreeLibrary(lib);
+ lib=NULL;
+ p_getaddrinfo=NULL;
+ continue;
+ }
+ p_freeaddrinfo=reinterpret_cast<t_freeaddrinfo>(pfunc);
+ break;
+ }
+ }
+#else
+ p_freeaddrinfo=::freeaddrinfo;
+ p_getaddrinfo=::getaddrinfo;
+#endif
+ inited = true;
+ }
+ }
GIOChannel *
create_channel (const StringView& host_in, int port, std::string& setme_err)
{
-
- GIOChannel * channel (0);
+ int err;
+ int sockfd;
#ifndef G_OS_WIN32
signal (SIGPIPE, SIG_IGN);
#endif
+ // get an addrinfo for the host
const std::string host (host_in.str, host_in.len);
char portbuf[32], hpbuf[255];
g_snprintf (portbuf, sizeof(portbuf), "%d", port);
- g_snprintf (hpbuf, sizeof(hpbuf), "%s:%s", host_in.str, portbuf);
+ g_snprintf (hpbuf,sizeof(hpbuf),"%s:%s",host_in.str,portbuf);
+
+#ifdef G_OS_WIN32 // windows might not have getaddrinfo...
+ if (!p_getaddrinfo)
+ {
+ struct hostent * ans = isalpha (host[0])
+ ? gethostbyname (host.c_str())
+ : gethostbyaddr (host.c_str(), host.size(), AF_INET);
+
+ err = WSAGetLastError();
+ if (err || !ans) {
+ setme_err = get_last_error (err);
+ return 0;
+ }
+
+ // try opening the socket
+ sockfd = socket (AF_INET, SOCK_STREAM, 0 /*IPPROTO_TCP*/);
+ if (sockfd < 0)
+ return 0;
+
+ // Try connecting
+ int i = 0;
+ err = -1;
+ struct sockaddr_in server;
+ memset (&server, 0, sizeof(struct sockaddr_in));
+ while (err && ans->h_addr_list[i])
+ {
+ char *addr = ans->h_addr_list[i];
+ memcpy (&server.sin_addr, addr, ans->h_length);
+ server.sin_family = AF_INET;
+ server.sin_port = htons(port);
+ ++i;
+ err = connect (sockfd,(struct sockaddr*)&server, sizeof(server));
+ }
- GSocketClient * client = g_socket_client_new ();
- g_return_val_if_fail(client, 0);
+ if (err) {
+ closesocket (sockfd);
+ setme_err = get_last_error (err);
+ return 0;
+ }
+ }
+ else
+#endif // #ifdef G_OS_WIN32 ...
+ {
+ errno = 0;
+ struct addrinfo hints;
+ memset (&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = 0;
+ hints.ai_family = 0;
+ hints.ai_socktype = SOCK_STREAM;
+ struct addrinfo * ans;
+ err = p_getaddrinfo (host.c_str(), portbuf, &hints, &ans);
+ if (err != 0) {
+ char buf[512];
+ snprintf (buf, sizeof(buf), _("Error connecting to \"%s\""), hpbuf);
+ setme_err = buf;
+ if (errno) {
+ setme_err += " (";
+ setme_err += file :: pan_strerror (errno);
+ setme_err += ")";
+ }
+ return 0;
+ }
- GSocketConnection * conn = g_socket_client_connect_to_host
- (client, hpbuf, 119, 0, NULL);
- g_return_val_if_fail(conn, 0);
+ // try to open a socket on any ipv4 or ipv6 addresses we found
+ errno = 0;
+ sockfd = -1;
+ for (struct addrinfo * walk(ans); walk && sockfd<0; walk=walk->ai_next)
+ {
+ // only use ipv4 or ipv6 addresses
+ if ((walk->ai_family!=PF_INET) && (walk->ai_family!=PF_INET6))
+ continue;
+
+ // try to create a socket...
+ sockfd = ::socket (walk->ai_family, walk->ai_socktype, walk->ai_protocol);
+ if (sockfd < 0)
+ continue;
+
+ // and make a connection
+ if (::connect (sockfd, walk->ai_addr, walk->ai_addrlen) < 0) {
+ closesocket (sockfd);
+ sockfd = -1;
+ }
+ }
- GSocket* g(g_socket_connection_get_socket(conn));
- g_return_val_if_fail(g, 0);
+ // cleanup
+ p_freeaddrinfo (ans);
+ }
- int sockfd = g_socket_get_fd(g);
+ // create the giochannel...
+ if (sockfd < 0) {
+ char buf[512];
+ snprintf (buf, sizeof(buf), _("Error connecting to \"%s\""), hpbuf);
+ setme_err = buf;
+ if (errno) {
+ setme_err += " (";
+ setme_err += file :: pan_strerror (errno);
+ setme_err += ")";
+ }
+ return 0;
+ }
+ GIOChannel * channel (0);
#ifndef G_OS_WIN32
channel = g_io_channel_unix_new (sockfd);
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
@@ -93,7 +282,6 @@ namespace
g_io_channel_set_encoding (channel, NULL, NULL);
g_io_channel_set_buffered (channel, true);
g_io_channel_set_line_term (channel, "\n", 1);
-
return channel;
}
}
@@ -318,7 +506,7 @@ GIOChannelSocket :: gio_func (GIOChannel * channel,
* could be a bug in gcc 4.2.1.
*/
/*if (_abort_flag) _listener->on_socket_abort (this);
- else*/ if (result == IO_ERR) _listener->on_socket_error (this);
+ else*/ if (result == IO_ERR) _listener->on_socket_error (this);
else if (result == IO_READ) set_watch_mode (READ_NOW);
else if (result == IO_WRITE) set_watch_mode (WRITE_NOW);
}
@@ -326,6 +514,10 @@ GIOChannelSocket :: gio_func (GIOChannel * channel,
return false; // set_watch_now(IGNORE) cleared the tag that called this func
}
+namespace
+{
+ const unsigned int TIMEOUT_SECS (30);
+}
void
GIOChannelSocket :: set_watch_mode (WatchMode mode)
@@ -404,6 +596,8 @@ GIOChannelSocket :: Creator :: create_socket (const StringView & host,
WorkerPool & threadpool,
Listener * listener)
{
+ ensure_module_inited ();
+
ThreadWorker * w = new ThreadWorker (host, port, listener);
threadpool.push_work (w, w, true);
}
diff --git a/pan/tasks/socket-impl-gio.h b/pan/tasks/socket-impl-gio.h
index 165ff53..95a3854 100644
--- a/pan/tasks/socket-impl-gio.h
+++ b/pan/tasks/socket-impl-gio.h
@@ -21,8 +21,7 @@
#define __SocketGIO_h__
#include <string>
-#include <glib/giochannel.h>
-#include <glib/gstring.h>
+#include <glib.h>
#include <pan/tasks/socket.h>
namespace pan
diff --git a/pan/usenet-utils/mime-utils.h b/pan/usenet-utils/mime-utils.h
index fbfa71c..d2aa101 100644
--- a/pan/usenet-utils/mime-utils.h
+++ b/pan/usenet-utils/mime-utils.h
@@ -21,7 +21,7 @@
#define _UtilMime_h_
#include <vector>
-#include <glib/gtypes.h>
+#include <glib.h>
#include <gmime/gmime-filter.h>
#include <gmime/gmime-stream.h>
#include <gmime/gmime-message.h>
diff --git a/pan/usenet-utils/text-massager.cc b/pan/usenet-utils/text-massager.cc
index 56fe1f9..468631e 100644
--- a/pan/usenet-utils/text-massager.cc
+++ b/pan/usenet-utils/text-massager.cc
@@ -25,7 +25,6 @@
extern "C" {
#include <glib/gi18n.h>
}
-#include <glib/gunicode.h>
#include "text-massager.h"
#include <pan/general/log.h>
using namespace pan;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]