[Flightgear-devel] Checking if there is a connection with netChannel
Hi, I have got the netChannel figured (thanks Bernie) out and the server is accepting multiple clients. The problem is if a client flightgear program is shut down the server still tries to send it information and the server crashes. I tried using netChannel::isConnected() but it returns true even if there is no client. On the client side I thought about using netChannel::close to inform the server that the socket is closed but the function is never called. netChannel::close is called in the clients destructor but the destructor is never called because FGGlobals *globals is never deleted (from what I can tell) which in turn would delete my client. Any thoughts on the matter? Would putting delete globals somewhere in the code which down the line would call netChannel::close() be the solution? Seamus ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
RE: [Flightgear-devel] Checking if there is a connection with netChannel
Seamus Thomas Carroll writes: On the client side I thought about using netChannel::close to inform the server that the socket is closed but the function is never called. netChannel::close is called in the clients destructor but the destructor is never called because FGGlobals *globals is never deleted (from what I can tell) which in turn would delete my client. Any thoughts on the matter? Would putting delete globals somewhere in the code which down the line would call netChannel::close() be the solution? Easy enough to test try moving globals = new FGGlobals; out of main,cxx fgMainInit( int argc, char **argv ) { into bootstrap.cxx main(int argc, char **argv) { ... globals = new FGGlobals; // FIXME: add other, more specific // exceptions. try { fgMainInit(argc, argv); } catch (sg_throwable t) { // We must use cerr rather than // logging, since logging may be // disabled. cerr Fatal error: t.getFormattedMessage() \n (received from t.getOrigin() ')' endl; exit(1); } delete globals; } Norman ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
RE: [Flightgear-devel] Checking if there is a connection with netChannel
I put a cerr delete globals endl; where you have delete globals; in the code below and when I exit flightgear delete globals is not printed. Does the same happen for you? Seamus On Tue, 2 Dec 2003, Norman Vine wrote: Seamus Thomas Carroll writes: On the client side I thought about using netChannel::close to inform the server that the socket is closed but the function is never called. netChannel::close is called in the clients destructor but the destructor is never called because FGGlobals *globals is never deleted (from what I can tell) which in turn would delete my client. Any thoughts on the matter? Would putting delete globals somewhere in the code which down the line would call netChannel::close() be the solution? Easy enough to test try moving globals = new FGGlobals; out of main,cxx fgMainInit( int argc, char **argv ) { into bootstrap.cxx main(int argc, char **argv) { ... globals = new FGGlobals; // FIXME: add other, more specific // exceptions. try { fgMainInit(argc, argv); } catch (sg_throwable t) { // We must use cerr rather than // logging, since logging may be // disabled. cerr Fatal error: t.getFormattedMessage() \n (received from t.getOrigin() ')' endl; exit(1); } delete globals; } Norman ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] Checking if there is a connection with netChannel
On Tue, 02 Dec 2003 20:40:51 -0500 Norman Vine [EMAIL PROTECTED] wrote: Seamus Thomas Carroll writes: On the client side I thought about using netChannel::close to inform the server that the socket is closed but the function is never called. netChannel::close is called in the clients destructor but the destructor is never called because FGGlobals *globals is never deleted (from what I can tell) which in turn would delete my client. Any thoughts on the matter? Would putting delete globals somewhere in the code which down the line would call netChannel::close() be the solution? Easy enough to test try moving globals = new FGGlobals; out of main,cxx fgMainInit( int argc, char **argv ) { into bootstrap.cxx main(int argc, char **argv) { ... globals = new FGGlobals; // FIXME: add other, more specific // exceptions. try { fgMainInit(argc, argv); } catch (sg_throwable t) { // We must use cerr rather than // logging, since logging may be // disabled. cerr Fatal error: t.getFormattedMessage() \n (received from t.getOrigin() ')' endl; exit(1); } delete globals; } globals will not be deleted if an exception is caught. This is a good case for using std::auto_ptr. Alternatively if globals was an object and not a pointer it would be destroyed automatically at exit. Bernie ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] Checking if there is a connection with netChannel
Found the solution. When the client is shutdown the server netChannel still thinks the connection is valid and has a handle != -1. This causes a SIGPIPE errors on a send or recieve making an assert to fail. To avoid this problem MSG_NOSIGNAL is passed into the send or recv with this description from man 2 send: MSG_NOSIGNAL: Requests not to send SIGPIPE on errors on stream oriented sockets when the other end breaks the connection. The EPIPE error is still returned. The handle is then set to -1 and connected to false in netChannel. No need to worry about FGGlobals *globals for now. Seamus On Wed, 3 Dec 2003, Bernie Bright wrote: On Tue, 02 Dec 2003 20:40:51 -0500 Norman Vine [EMAIL PROTECTED] wrote: Seamus Thomas Carroll writes: On the client side I thought about using netChannel::close to inform the server that the socket is closed but the function is never called. netChannel::close is called in the clients destructor but the destructor is never called because FGGlobals *globals is never deleted (from what I can tell) which in turn would delete my client. Any thoughts on the matter? Would putting delete globals somewhere in the code which down the line would call netChannel::close() be the solution? Easy enough to test try moving globals = new FGGlobals; out of main,cxx fgMainInit( int argc, char **argv ) { into bootstrap.cxx main(int argc, char **argv) { ... globals = new FGGlobals; // FIXME: add other, more specific // exceptions. try { fgMainInit(argc, argv); } catch (sg_throwable t) { // We must use cerr rather than // logging, since logging may be // disabled. cerr Fatal error: t.getFormattedMessage() \n (received from t.getOrigin() ')' endl; exit(1); } delete globals; } globals will not be deleted if an exception is caught. This is a good case for using std::auto_ptr. Alternatively if global,s was an object and not a pointer it would be destroyed automatically at exit. Bernie ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel