Glib::IOChannel monitoring socket connection - problem with closing connection.
- From: Christopher Vogl <gisch sol at>
- To: gtkmm-list gnome org
- Subject: Glib::IOChannel monitoring socket connection - problem with closing connection.
- Date: Sat, 01 Oct 2011 22:33:42 +0200
Hi everyone,
in my application I need to connect to a server (IP & port are known) to
get the IP-address and port of the second one.
A class called ConnHandler sets up the connections to the servers. When
the connection to the second server is established an object of Processor
"registers" a receiving method with the ConnHandler by calling
setRecvFunc().
When I receive IP & port of the second server from the first one I need
to disconnect from the first one to set up a new connection to the second.
My problem is that I don't know how to do it the right way. I think I
have tried every combination of closing and resetting of _rpSockConn,
_rpInStream, _rpOutStream and _rpIoCh (see the following code),
but I get always get one of the following errors:
GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT
(object)' failed
(only calling _rpSockConn->close() )
or
GLib-WARNING **: Invalid file descriptor.
or
glibmm-CRITICAL **:
unhandled exception (type Glib::Error) in signal handler:
domain: g-io-channel-error-quark
code : 8
what : Bad file descriptor
Sorry but I cannot run the application right now and I don't remember in
which case the errors occured.
Closing SocketConnection should close the underlying Streams, but what
about the IOChannel?
class ConnHandler
{
public:
void sigc::slot<bool, const Glib::IOCondition&> slot )
{
Glib::signal_io().connect( slot, _rpIoCh, Glib::IO_IN |
Glib::IO_HUP );
}
Glib::RefPtr<Gio::DataInputStream> getInStream()
{
return _rpInStream;
}
Glib::RefPtr<Gio::DataOutputStream> getOutStream()
{
return _rpOutStream;
}
void connect( std::string& host, guint16 port )
{
Glib::RefPtr<Gio::SocketClient> rpSockClient =
Gio::SocketClient::create();
_rpSockConn = rpSockClient->connect_to_host( host, Port );
_rpInStream = Gio::DataInputStream::create(
_rpSockConn->get_input_stream() );
_rpOutStream = Gio::DataOutputStream::create(
_rpSockConn->get_output_stream() );
_rpIoCh = Glib::IOChannel::create_from_fd(
_rpSockConn->get_socket()->get_fd() );
}
...
private:
Glib::RefPtr<Glib::IOChannel> _rpIoCh;
Glib::RefPtr<Gio::SocketConnection> _rpSockConn;
void closeConnection
{
// ???
}
...
}
I would really appreciate any help!
Thanks!
Chris
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]