Re: what's problem in GIOChannel ?

I thank I get it.
after g_io_channel_unix_new, I call g_io_set_encoding( to NULL)  and g_io_set_flags( add G_IO_FLAG_NONBLOCK 
). it ok now.

----- Original Message ----- 
From: "Martyn Russell" <ginxd btopenworld com>
To: "chen.shengqi" <chen shengqi connet com tw>
Cc: <gtk-app-devel-list gnome org>
Sent: Saturday, September 28, 2002 2:06 AM
Subject: Re: what's problem in GIOChannel ?

chen.shengqi wrote:

dear sirs:
    I use following code to connect to, when read data,recvbytes is  28( include data 
in first packet and 2bytes in second packet ) and ret=1, then recvbytes always return 0,and ret=0, but 
server should send serval packet, first packet is 26bytes,and following packet is large than 26 bytes, 
total are large then 1024 bytes. If I use telnet connect to the port, telnet can receive data correctly. 
How should I use GIOChannel?

int swarefd=-1;
GIOChannel *SwareSocketChannel=NULL;

on_open1_activate                      (GtkMenuItem     *menuitem,
                                       gpointer         user_data)
   printf("open now\n");
   swarefd = connect_to_sware("",9999);
   if (swarefd<0) { printf("connect_to_sware failed\n"); return; }
   printf("connect_to_sware ok swarefd=%d\n",swarefd);
   SwareSocketChannel = g_io_channel_unix_new(swarefd);
   if (SwareSocketChannel==NULL) { printf("g_io_channel_unix_new failed \n"); return; }
   printf("g_io_channel_unix_new ok \n");
   g_io_add_watch(SwareSocketChannel, G_IO_IN | G_IO_PRI | G_IO_HUP, read_data_from_socket,NULL);
   printf("g_io_add_watch ok \n");

/* read data on socket */
gboolean read_data_from_socket(GIOChannel *source, GIOCondition condition, gpointer data)
   gchar recvbuf[2048];
   GError *err=NULL;
   GIOStatus ret;
   int recvbytes=0;
   ret=g_io_channel_read_chars(source, recvbuf,2048,&recvbytes,&err);
   printf("condition=%d,read return %d, recvbytes=%d\n",condition,ret,recvbytes);
   if (recvbytes>0) debug_hex("read_data_from_socket",recvbuf,recvbytes,1);
   return TRUE;

????^介e??fj)b? b藏-??iu朕?X?? ???+?m???j)`???????ē????+-?w棹 dj?]z鳐?+-

Might I suggest you use gtk_input_add. It is better at handling sockets
than g_io_channel. (unless your application is completely GLIB based and
includes NO GTK, but if that was the case you wouldnt be on this list



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