Re: [gnet] problem with g_io_add_watch on UDP socket
- From: tc6 <tc6 free fr>
- Cc: gnet lists gnetlibrary org
- Subject: Re: [gnet] problem with g_io_add_watch on UDP socket
- Date: Sun, 17 Apr 2005 23:44:25 +0200
Here is what I did (it still doesn't work, but I can compile and the
callback is called):
int fd = g_io_channel_unix_get_fd(gnet_udp_socket_get_io_channel(socket_));
ioChannel_ = Glib::IOChannel::create_from_fd(fd);
ioSource_ = Glib::IOSource::create(ioChannel_, Glib::IO_IN|Glib::IO_OUT|
Glib::IO_HUP|Glib::IO_ERR|Glib::IO_NVAL);
ioSource_->connect(sigc::mem_fun(*this, &netConnect::client));
ioSource_->attach(Glib::MainContext::get_default());
The problem now is that the callback: netConnect::client is called but
only IO_OUT condition is true and never IO_IN (the server is sending
string on the other side of the channel, so that the client should
normally receive something).
I try both read/write functions (of IOChannel) and gnet receive/send
method and none of them works. Is it possible that the IOChannel is
write or read protected?
fd is the same for both client and server (which is a pretty good thing
I guess)
If someone has an idea on how this could work (or if it will work one
day...)
I had another question about using a non blocking "receive" function (I
thing it is in documentation but can't remember where...).
Thank you
Hubert Sokołowski wrote:
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
_______________________________________________
gnet mailing list
gnet lists gnetlibrary org
http://lists.gnetlibrary.org/mailman/listinfo/gnet
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]