[gnet] gnet_tcp_socket_connect_async() fails.



I have tried as a test case before I use the gnet library to write a quick
test program.  (I am using ver 1.1.8) Code is below:

******************

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <glib.h>
#include <gnet/gnet.h>

gboolean connect(const gchar* host, const gint port,
GTcpSocketConnectAsyncFunc cb);
void connect_cb(GTcpSocket *socket, GInetAddr *ia,
GTcpSocketConnectAsyncStatus status, gpointer data);

int main(int argc, char** argv)
{ 
  gchar *server = NULL;
  gint16 port = 0;

  GMainLoop *ml = NULL;

  /* init gnet */
  gnet_init();
  g_message("initiated GNET");

/*   server = g_strdup_printf("www.google.com");  */
  server = g_strdup_printf("216.239.33.101");
/*   server = g_strdup_printf("jabber.org.uk");  */
/*   server = g_strdup_printf("212.38.79.39"); */
  port = 80;

  g_message("using server:'%s'", server);
  g_message("using port:%d", port);

  connect(server, port, connect_cb);

  /* start main_loop */
  ml = g_main_loop_new(NULL, FALSE);
  g_main_loop_run(ml);

  g_message("exiting...");

  /* clean up */
  if(server != NULL) g_free(server);

  return 0;
}

gboolean connect(const gchar* host, const gint port,
GTcpSocketConnectAsyncFunc cb)
{
  GTcpSocketConnectAsyncID connect_id = 0;

  if(cb == NULL)
  {
      g_warning("connect: callback was NULL");
      return FALSE;
  }

  if(host == NULL)
  {
      g_warning("connect: host was NULL");
      return FALSE;
  }

  g_message("connect: connecting to host:'%s', port:%d with cb:0x%.8x",
host, port, (gint)cb);
  connect_id = gnet_tcp_socket_connect_async(host, port, cb, NULL);

  return TRUE;
}

void connect_cb(GTcpSocket *socket, GInetAddr *ia,
GTcpSocketConnectAsyncStatus status, gpointer data)
{
    g_message("connect_cb: socket:0x%.8x, ia:0x%.8x, status:%d,
data:0x%.8x", (gint)socket, (gint)ia, status, (gint)data);
}

******************

Where GTKPKGS is defined as:
GTKPKGS=glib-2.0 gthread-2.0

I am compiling with the following flags:
-g -Werror -Wall -Wmissing-declarations -Wparentheses -pedantic \
  	$(INCDIR) `pkg-config $(GTKPKGS) --cflags` `gnet-config --cflags`

I am linking with the following flags:
`gnet-config --libs` `pkg-config $(GTKPKGS) --libs`


When I run the application the following output is generated:
[russelm6 coyote Linux2gcc]$ ./gnet-test
Message: initiated GNET
Message: using server:'216.239.33.101'
Message: using port:80
Message: connect: connecting to host:'216.239.33.101', port:80 with
cb:0x080487d6
Segmentation fault

I noticed when I tried the hfetch.c, that it was failing at the function
gnet_tcp_socket_new(addr);

Am I missing something or is this a serious issue?

Regards,
Martyn



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