[gnet] problem with g_io_add_watch on UDP socket



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). Is it possible to use read/write functions
for the GIOChannel or not (as mentionned in documentation)?

I look at the example with async connections and the code doesn't seem
much different, but I probably missed something.

So if anybody can help me...


Thank you in advance





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