Re: Windows binaries for GLib-2.2.2, GTK+-2.2.2, GIMP-1.2.5 etc



--- Tor Lillqvist <tml iki fi> wrote:
> Herman Bloggs writes:
>  > g_io_channel_unix_new is broken in GLib-2.2.2:
>  > 
>  > (glib_io_demo.exe:1096): GLib-WARNING **: giowin32.c:1500: 520 is
>  > neither a file descriptor or a socket
> 
> Hmm. Do you have a simple test program I could have so that I can
> debug this? Also give me some information about what Windows version
> you are running.
> 
Yes, I'm using the same test program I sent you some time ago for a
different bug. Find it attached. I'm using Win2k SP2.

> You could as a workaround call g_io_channel_win32_new_socket()
> instead
> of g_io_channel_unix_new().
That is what I'm doing at the moment.

- Herman

> 
> --tml
> 
> 
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
/*
 *  glib_io_demo.c
 * 
 *  Author: Herman Bloggs <hermanator12002 yahoo com>
 *  Date: October 18, 2002
 *  Description: Demonstrates glib io bug.
 */
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

u_long imode=0;
GtkWidget *hentry=0;
GtkWidget *pentry=0;
char* hostname=0;
char* port=0;
int timed_out=0;

static void my_io_destroy(gpointer data) {
	printf("my_io_destroy called\n");
}

static gboolean my_io_read(GIOChannel *source, GIOCondition condition, gpointer data) {
	int size;
	char buf[1024];
	int fd = g_io_channel_unix_get_fd(source);

	printf("my_io_read called\n");

	size = recv(fd, buf, sizeof(buf), 0);
	if(size == SOCKET_ERROR) {
		printf("Error reading socket: %d\n", WSAGetLastError());
	}
	else
		printf("Received from server:\n%s\n", buf);

	printf("Closing connection..\n");
	closesocket(fd);
	/* reset timed_out */
	timed_out=0;
	return FALSE;
}

static void connected(int fd) {
	GIOChannel *channel;

	printf("connected() called..\n");

	channel = g_io_channel_unix_new(fd);
	g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN,
			    my_io_read, NULL, my_io_destroy);
	printf("fd read watch created..\n");
}

static gboolean connect_wblock(GIOChannel *source, GIOCondition condition, gpointer data) {
	unsigned int len;
	int error = WSAETIMEDOUT;
	int fd = g_io_channel_unix_get_fd(source);

	printf("Connected..\n");

	len = sizeof(error);
	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len) == SOCKET_ERROR) {
		printf("no_one_calls: getsockopt error: %d\n", WSAGetLastError());
		closesocket(fd);
		return FALSE;
	}
	imode = 0;
	ioctlsocket(fd, FIONBIO, &imode);

	/* call this to set the read fd watch */
	connected(fd);
	return FALSE;
}

static gboolean connect_nblock(gpointer data)
{
	int fd = (int)data;
	/* call this to set the read fd watch */
	connected(fd);
	return FALSE;
}

int my_async_connect(char* hostname, int port) {
	int sockfd;
	struct sockaddr_in sin;
	struct hostent* hp=NULL;
	
	printf("Call to my_async_connect\n"); 
	/* Host lookup */
	if( strlen(hostname) <= 0 ) {
		printf("Host name lookup needs a host to look up..\n");
		return -1;
	}
	
	hp = gethostbyname( hostname );
	if( hp == NULL ) {
		printf( "Error doing host lookup for %s, error: %d", 
			hostname, WSAGetLastError());    
		return -1;
	}
	memset(&sin, 0, sizeof(struct sockaddr_in));
	memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
	sin.sin_family = hp->h_addrtype;
	sin.sin_port = htons(port);

	/* Create socket */
	if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET ) {
		printf( "Error creating socket, error: %d", WSAGetLastError() );
		return -1;
	}

	/* Non blocking socket */
	imode = 1;
	ioctlsocket(sockfd, FIONBIO, &imode);

	/* Connect */
	if (connect(sockfd, (struct sockaddr *)&sin, sizeof(sin)) == SOCKET_ERROR) {
		int error = WSAGetLastError();
		if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR)) {
			GIOChannel *channel;
			printf("Connect would have blocked..\n");

			channel = g_io_channel_unix_new(sockfd);
			g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_OUT,
					    connect_wblock, NULL, my_io_destroy);
			printf("fd write watch created..\n");

		} else {
			printf("Connect failed (errno %d)\n", error);
			closesocket(sockfd);
			return -1;
		}
	} else {
		unsigned int len;
		int error = WSAETIMEDOUT;

		printf("Connect didn't block\n");
		len = sizeof(error);
		if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (char*)&error, &len) == SOCKET_ERROR) {
			printf("getsockopt failed, error: %d\n", WSAGetLastError());
			closesocket(sockfd);
			return -1;
		}
		imode = 0;
		ioctlsocket(sockfd, FIONBIO, &imode);

		g_timeout_add(50, connect_nblock, (gpointer)sockfd);
	}
	return sockfd;
}

gboolean connect_cb( gpointer data ) {
	int portnum;

	if(!timed_out) {
		printf("Timing out in order for you to move your mouse pointer\naway from GTK window\n");
		g_timeout_add(3000, connect_cb, NULL);
		timed_out = 1;
		return TRUE;
	}

	hostname = (gchar*)gtk_entry_get_text(GTK_ENTRY(hentry));
	port = (gchar*)gtk_entry_get_text(GTK_ENTRY(pentry));

	portnum = atoi(port);

	if(!my_async_connect(hostname, portnum)) {
		printf("my_async_connect failed\n");
	}
	else {
		printf("my_async_connect success\n");
	}
	return FALSE;
}


#ifdef __GNUC__
#  ifndef _stdcall
#    define _stdcall  __attribute__((stdcall))
#  endif
#endif

int _stdcall
WinMain (struct HINSTANCE__ *hInstance, 
	 struct HINSTANCE__ *hPrevInstance,
	 char               *lpszCmdLine,
	 int                 nCmdShow)
{
	GtkWidget     *win, *but, *hbox, *vbox, *entry, *label;
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;

	printf("Starting..\n");
 
	wVersionRequested = MAKEWORD( 2, 2 );
 
	err = WSAStartup( wVersionRequested, &wsaData );

	gtk_init( &__argc, &__argv );

	win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (GTK_OBJECT(win), "delete-event", 
			  G_CALLBACK (gtk_true), NULL);
	g_signal_connect (GTK_OBJECT(win), "destroy", 
			  G_CALLBACK (gtk_main_quit), NULL);

	vbox = gtk_vbox_new(FALSE, 18);
	gtk_container_add(GTK_CONTAINER(win), vbox);
	gtk_widget_show (vbox);

	/* host */
	hbox = gtk_hbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(vbox), hbox);
	gtk_widget_show (hbox);

	label = gtk_label_new_with_mnemonic("Host");
	gtk_container_add (GTK_CONTAINER (hbox), label);
	gtk_widget_show (label);

	hentry = entry = gtk_entry_new();
	gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
	gtk_container_add (GTK_CONTAINER (hbox), entry);
	gtk_widget_show (entry);

	/* port */
	hbox = gtk_hbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(vbox), hbox);
	gtk_widget_show (hbox);

	label = gtk_label_new_with_mnemonic("Port");
	gtk_container_add (GTK_CONTAINER (hbox), label);
	gtk_widget_show (label);

	pentry = entry = gtk_entry_new();
	gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
	gtk_container_add (GTK_CONTAINER (hbox), entry);
	gtk_widget_show (entry);

	/* buttons */
	hbox = gtk_hbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(vbox), hbox);
	gtk_widget_show (hbox);
	
	but = gtk_button_new_with_label ("Close yourself. I mean it!");
	g_signal_connect_swapped (GTK_OBJECT (but), "clicked", 
				  G_CALLBACK (gtk_object_destroy), (gpointer) win);
	gtk_container_add (GTK_CONTAINER (hbox), but);
	gtk_widget_show (but);
	
	but = gtk_button_new_with_label ("Connect");
	g_signal_connect_swapped (GTK_OBJECT (but), "clicked", 
				  G_CALLBACK (connect_cb), (gpointer) win);
	gtk_container_add (GTK_CONTAINER (hbox), but);
	gtk_widget_show (but);
	

	gtk_widget_show_all (win);
	gtk_main ();

	WSACleanup();
	return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]