Re: [gnet] problem with g_io_add_watch on UDP socket
- From: Hubert Sokołowski <h sokolowski wsisiz edu pl>
- To: gnet lists gnetlibrary org
- Subject: Re: [gnet] problem with g_io_add_watch on UDP socket
- Date: Sat, 16 Apr 2005 18:22:00 +0200
Hi!
On Sat, 16 Apr 2005 17:03:17 +0200
tc6 <tc6 free fr> wrote:
> Hello,
>
> I'm experiencing problems to make g_io_add_watch works with an udp
> socket.
>
> Here is my code :
> GIOChannel *ioC_;
> ioC_ = gnet_udp_socket_get_io_channel(socket_);
> g_io_add_watch(ioC_, G_IO_IN, greceive, socket_);
>
> where greceive is defined as follows:
>
> static gboolean greceive(GIOChannel *source, GIOCondition cond, void
> *data)
> {
> char buffer[100];
> gsize bytesRead = 0;
> GInetAddr* addr;
> GUdpSocket *sock = (GUdpSocket *)data;
>
> std::cout<<"Received something "<<std::endl;
> if (cond & (G_IO_IN))
> {
> gnet_udp_socket_receive(sock, buffer, sizeof(buffer), &addr);
> std::cout<<"Received buffer: "<<buffer<<std::endl;
> }
> else if (cond & (G_IO_ERR | G_IO_NVAL | G_IO_HUP))
> {
> std::cout<<"Error received"<<std::endl;
> return false;
> }
> }
>
> The problem is here that the callback is never called (indeed
> "Received
> something" is never printed).
do you run g_main_loop_run in the begining of your program?
g_io_add_watch requires glib main loop to be running.
I am not sure whether you can use glib/gnet in a C++ program.
> Is it possible to use read/write
> functions
> for the GIOChannel or not (as mentionned in documentation)?
you can use g_io_channel_unix_get_fd to get the file handle, but
you should use g_io_channel_* set of functions to read and write.
hs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]