From: Alex P. <ale...@ie...> - 2010-02-28 05:50:49
|
Index: terrasync.cxx =================================================================== RCS file: /var/cvs/FlightGear-0.9/source/utils/TerraSync/terrasync.cxx,v retrieving revision 1.28 diff -u -r1.28 terrasync.cxx --- terrasync.cxx 23 Jan 2010 22:27:38 -0000 1.28 +++ terrasync.cxx 28 Feb 2010 05:49:01 -0000 @@ -35,6 +35,7 @@ #endif #include <stdlib.h> // atoi() atof() abs() system() +#include <signal.h> // signal() #include <simgear/compiler.h> @@ -270,8 +271,23 @@ } +bool terminating = false; +sighandler_t prior_signal_handlers[32]; +int termination_triggering_signals[] = + {SIGHUP, SIGINT, SIGQUIT, SIGKILL, 0}; // zero terminated + +void terminate_request_handler(int param) { + cout << "\nReceived signal " << param << ", " + << "intend to terminate soon, " + << "repeat to force an immediate effect.\n"; + terminating = true; + signal(param, prior_signal_handlers[param]); +} + + const int nowhere = -9999; + // parse message static void parse_message( const string &msg, int *lat, int *lon ) { double dlat, dlon; @@ -281,8 +297,8 @@ string::size_type pos = text.find( "$GPGGA" ); if ( pos == string::npos ) { - *lat = -9999.0; - *lon = -9999.0; + *lat = nowhere; + *lon = nowhere; return; } string tmp = text.substr( pos + 7 ); @@ -408,7 +424,8 @@ void getWaitingTile() { while ( !waitingTiles.empty() ) { - CompletedTiles::iterator ii = completedTiles.find( waitingTiles.front() ); + CompletedTiles::iterator ii = + completedTiles.find( waitingTiles.front() ); time_t now = time(0); if ( ii == completedTiles.end() || ii->second + 600 < now ) { sync_tree(waitingTiles.front().c_str()); @@ -422,7 +439,7 @@ int main( int argc, char **argv ) { int port = 5501; - char host[256] = ""; // accept messages from anyone + char host[256] = "localhost"; bool testing = false; bool do_checkout(true); int verbose(0); @@ -485,7 +502,6 @@ // Must call this before any other net stuff netInit( &argc,argv ); - netSocket s; if ( ! s.open( false ) ) { // open a UDP socket @@ -524,7 +540,14 @@ } - while ( true ) { // main loop + for (int* sigp=termination_triggering_signals; *sigp; sigp++) { + prior_signal_handlers[*sigp] = + signal(*sigp, *terminate_request_handler); + if (verbose) cout << "Intercepted signal " << *sigp << endl; + } + + while ( !terminating ) { + // main loop recv_msg = false; if ( testing ) { // No FGFS communications @@ -532,6 +555,9 @@ lon = -123; recv_msg = (lat != last_lat) || (lon != last_lon); } else { + if (verbose && waitingTiles.empty()) { + cout << "Idle; waiting for FlightGear position\n"; + } s.setBlocking(waitingTiles.empty()); len = s.recv(msg, maxlen, 0); if (len >= 0) { @@ -584,11 +610,11 @@ } else if ( testing ) { - exit( 0 ); + terminating = true; } else ulSleep( 1 ); - } // while true + } // while !terminating return 0; } |
From: Frederic B. <fre...@fr...> - 2010-02-28 08:17:26
|
Hi Alex, Please resend this patch gzip and attached. I can't use it as it is. -Fred |
From: Alex P. <ale...@ie...> - 2010-02-28 08:28:44
Attachments:
terrasync-signals.patch.gz
terrasync.cxx
|
Done. Also added the modified source file. On Sun, Feb 28, 2010 at 12:09 AM, Frederic Bouvier <fre...@fr...> wrote: > Hi Alex, > Please resend this patch gzip and attached. I can't use it as it is. > > -Fred > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > Flightgear-devel mailing list > Fli...@li... > https://lists.sourceforge.net/lists/listinfo/flightgear-devel > |
From: Frederic B. <fre...@fr...> - 2010-02-28 09:11:55
|
Commited. Thanks -Fred Le 28/02/2010 09:28, Alex Perry a écrit : > Done. Also added the modified source file. > > On Sun, Feb 28, 2010 at 12:09 AM, Frederic Bouvier <fre...@fr...> wrote: > >> Hi Alex, >> Please resend this patch gzip and attached. I can't use it as it is. >> |
From: Tim M. <tim...@gm...> - 2010-02-28 11:59:16
|
Whoops, I'm a bit late with my comments, but all the same... You can't safely use C++ stream functions in a signal handler. Why does terrasync need to be protected from interruption like this? Does the SVN update really get corrupted if it is interrupted? Tim On Sun, Feb 28, 2010 at 6:50 AM, Alex Perry <ale...@ie...> wrote: > Index: terrasync.cxx > =================================================================== > RCS file: /var/cvs/FlightGear-0.9/source/utils/TerraSync/terrasync.cxx,v > retrieving revision 1.28 > diff -u -r1.28 terrasync.cxx > --- terrasync.cxx 23 Jan 2010 22:27:38 -0000 1.28 > +++ terrasync.cxx 28 Feb 2010 05:49:01 -0000 > @@ -35,6 +35,7 @@ > #endif > > #include <stdlib.h> // atoi() atof() abs() system() > +#include <signal.h> // signal() > > #include <simgear/compiler.h> > > @@ -270,8 +271,23 @@ > } > > > +bool terminating = false; > +sighandler_t prior_signal_handlers[32]; > +int termination_triggering_signals[] = > + {SIGHUP, SIGINT, SIGQUIT, SIGKILL, 0}; // zero terminated > + > +void terminate_request_handler(int param) { > + cout << "\nReceived signal " << param << ", " > + << "intend to terminate soon, " > + << "repeat to force an immediate effect.\n"; > + terminating = true; > + signal(param, prior_signal_handlers[param]); > +} > + > + > const int nowhere = -9999; > > + > // parse message > static void parse_message( const string &msg, int *lat, int *lon ) { > double dlat, dlon; > @@ -281,8 +297,8 @@ > string::size_type pos = text.find( "$GPGGA" ); > if ( pos == string::npos ) > { > - *lat = -9999.0; > - *lon = -9999.0; > + *lat = nowhere; > + *lon = nowhere; > return; > } > string tmp = text.substr( pos + 7 ); > @@ -408,7 +424,8 @@ > > void getWaitingTile() { > while ( !waitingTiles.empty() ) { > - CompletedTiles::iterator ii = completedTiles.find( > waitingTiles.front() ); > + CompletedTiles::iterator ii = > + completedTiles.find( waitingTiles.front() ); > time_t now = time(0); > if ( ii == completedTiles.end() || ii->second + 600 < now ) { > sync_tree(waitingTiles.front().c_str()); > @@ -422,7 +439,7 @@ > > int main( int argc, char **argv ) { > int port = 5501; > - char host[256] = ""; // accept messages from anyone > + char host[256] = "localhost"; > bool testing = false; > bool do_checkout(true); > int verbose(0); > @@ -485,7 +502,6 @@ > > // Must call this before any other net stuff > netInit( &argc,argv ); > - > netSocket s; > > if ( ! s.open( false ) ) { // open a UDP socket > @@ -524,7 +540,14 @@ > } > > > - while ( true ) { // main loop > + for (int* sigp=termination_triggering_signals; *sigp; sigp++) { > + prior_signal_handlers[*sigp] = > + signal(*sigp, *terminate_request_handler); > + if (verbose) cout << "Intercepted signal " << *sigp << endl; > + } > + > + while ( !terminating ) { > + // main loop > recv_msg = false; > if ( testing ) { > // No FGFS communications > @@ -532,6 +555,9 @@ > lon = -123; > recv_msg = (lat != last_lat) || (lon != last_lon); > } else { > + if (verbose && waitingTiles.empty()) { > + cout << "Idle; waiting for FlightGear position\n"; > + } > s.setBlocking(waitingTiles.empty()); > len = s.recv(msg, maxlen, 0); > if (len >= 0) { > @@ -584,11 +610,11 @@ > } > > else if ( testing ) { > - exit( 0 ); > + terminating = true; > } else > > ulSleep( 1 ); > - } // while true > + } // while !terminating > > return 0; > } > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > Flightgear-devel mailing list > Fli...@li... > https://lists.sourceforge.net/lists/listinfo/flightgear-devel > |
From: Alex P. <ale...@ie...> - 2010-02-28 17:54:12
|
On Sun, Feb 28, 2010 at 3:59 AM, Tim Moore <tim...@gm...> wrote: > Whoops, I'm a bit late with my comments, but all the same... > > You can't safely use C++ stream functions in a signal handler. Drat, true. A simple write() would be fine, given what I'm using it for. > Why does terrasync need to be protected from interruption like this? Does > the SVN update really get corrupted if it is interrupted? Yep. If we think the individual update could take a long time, we could go to the extra effort and use the svn internal interruption handlers. |
From: Alex P. <ale...@ie...> - 2010-02-28 16:52:03
Attachments:
terrasync-signals.patch.gz
|
Attached patch replaces the stream with a single direct call to write() inside the signal handler; someone Windows based might want to give it a look before committing. I also removed references to std:: which are they're superfluous after "using namespace" directive at the top. On Sun, Feb 28, 2010 at 8:16 AM, Alex Perry <ale...@ie...> wrote: > On Sun, Feb 28, 2010 at 3:59 AM, Tim Moore <tim...@gm...> wrote: >> Whoops, I'm a bit late with my comments, but all the same... >> >> You can't safely use C++ stream functions in a signal handler. > > Drat, true. A simple write() would be fine, given what I'm using it for. > >> Why does terrasync need to be protected from interruption like this? Does >> the SVN update really get corrupted if it is interrupted? > > Yep. If we think the individual update could take a long time, we > could go to the extra effort and use the svn internal interruption > handlers. > |
From: Frederic B. <fre...@fr...> - 2010-02-28 19:34:20
|
Alex, Terrasync doesn't stop itself if nothing comes from the socket. I am going to make it global and close it in the handler. -Fred Le 28/02/2010 17:51, Alex Perry a écrit : > Attached patch replaces the stream with a single direct call to > write() inside the signal handler; someone Windows based might want to > give it a look before committing. I also removed references to std:: > which are they're superfluous after "using namespace" directive at the > top. > > On Sun, Feb 28, 2010 at 8:16 AM, Alex Perry <ale...@ie...> wrote: > >> On Sun, Feb 28, 2010 at 3:59 AM, Tim Moore <tim...@gm...> wrote: >> >>> Whoops, I'm a bit late with my comments, but all the same... >>> >>> You can't safely use C++ stream functions in a signal handler. >>> >> Drat, true. A simple write() would be fine, given what I'm using it for. >> >> >>> Why does terrasync need to be protected from interruption like this? Does >>> the SVN update really get corrupted if it is interrupted? >>> >> Yep. If we think the individual update could take a long time, we >> could go to the extra effort and use the svn internal interruption >> handlers. >> >> |
From: Jari H. <ja...@fl...> - 2010-03-03 19:24:39
Attachments:
terrasync.jh.diff
|
Great, I haven't had an opportunity to run the new version yet. I took time to compile though, and there is a problem compiling terrasync.cxx on mac because of Apples typedef of the signal handler. I attached a small fix. Jari On 2/28/10 5:51 PM, Alex Perry wrote: > Attached patch replaces the stream with a single direct call to > write() inside the signal handler; someone Windows based might want to > give it a look before committing. I also removed references to std:: > which are they're superfluous after "using namespace" directive at the > top. > > On Sun, Feb 28, 2010 at 8:16 AM, Alex Perry<ale...@ie...> wrote: >> On Sun, Feb 28, 2010 at 3:59 AM, Tim Moore<tim...@gm...> wrote: >>> Whoops, I'm a bit late with my comments, but all the same... >>> >>> You can't safely use C++ stream functions in a signal handler. >> >> Drat, true. A simple write() would be fine, given what I'm using it for. >> >>> Why does terrasync need to be protected from interruption like this? Does >>> the SVN update really get corrupted if it is interrupted? >> >> Yep. If we think the individual update could take a long time, we >> could go to the extra effort and use the svn internal interruption >> handlers. >> >> >> >> ------------------------------------------------------------------------------ >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev >> >> >> _______________________________________________ >> Flightgear-devel mailing list >> Fli...@li... >> https://lists.sourceforge.net/lists/listinfo/flightgear-devel |
From: Frederic B. <fre...@fr...> - 2010-03-03 19:41:11
|
Hi Jari, ----- "Jari Häkkinen" a écrit : > Great, I haven't had an opportunity to run the new version yet. I took > time to compile though, and there is a problem compiling terrasync.cxx > on mac because of Apples typedef of the signal handler. I attached a > small fix. Your mail remind me I had a fix to commit. Your patch and the fix for the naming problem are commited now Thanks, -Fred -- Frédéric Bouvier http://my.fotolia.com/frfoto/ Photo gallery - album photo http://fgsd.sourceforge.net/ FlightGear Scenery Designer |
From: Martin S. <Mar...@mg...> - 2010-03-01 10:40:10
|
I'm expieriencing difficulties to compile 'terrasync' after the latest patch. While PLIB's socket seems to be the target, the type "socket" interferes with the system headers: g++ -g -O3 -march=opteron -DHAVE_CONFIG_H -I. -I../../src/Include -I/usr/include/subversion-1 -I/usr/include/apr-1.0 -I/opt/gnu/include -I/usr/local/include -I/opt/Boost/include/boost-1_37 -I/opt/FlightGear/include -g -O2 -I/opt/FlightGear -D_REENTRANT -c -o terrasync.o terrasync.cxx terrasync.cxx:118: error: 'netSocket socket' redeclared as different kind of symbol /usr/include/sys/socket.h:101: error: previous declaration of 'int socket(int, int, int)' terrasync.cxx: In function 'void terminate_request_handler(int)': terrasync.cxx:298: error: request for member 'close' in 'socket', which is of non-class type 'int ()(int, int, int)throw ()' [...] The following simple patch at least permits to compile - is this the way it's meant to be ? --- terrasync.cxx.original 2010-03-01 08:44:20.000000000 +0100 +++ terrasync.cxx 2010-03-01 11:35:55.975624335 +0100 @@ -115,7 +115,7 @@ deque<string> waitingTiles; typedef map<string,time_t> CompletedTiles; CompletedTiles completedTiles; -netSocket socket; +netSocket netSocket; #ifdef HAVE_SVN_CLIENT_H @@ -295,7 +295,7 @@ write(1, msg, sizeof(msg) - 1); terminating = true; signal(param, prior_signal_handlers[param]); - socket.close(); + netSsocket.close(); } @@ -517,12 +517,12 @@ // Must call this before any other net stuff netInit( &argc,argv ); - if ( ! socket.open( false ) ) { // open a UDP socket + if ( ! netSocket.open( false ) ) { // open a UDP socket printf("error opening socket\n"); return -1; } - if ( socket.bind( host, port ) == -1 ) { + if ( netSocket.bind( host, port ) == -1 ) { printf("error binding to port %d\n", port); return -1; } @@ -571,8 +571,8 @@ if (verbose && waitingTiles.empty()) { cout << "Idle; waiting for FlightGear position\n"; } - socket.setBlocking(waitingTiles.empty()); - len = socket.recv(msg, maxlen, 0); + netSocket.setBlocking(waitingTiles.empty()); + len = netSocket.recv(msg, maxlen, 0); if (len >= 0) { msg[len] = '\0'; recv_msg = true; Cheers, Martin. -- Unix _IS_ user friendly - it's just selective about who its friends are ! -------------------------------------------------------------------------- |
From: Alex P. <ale...@ie...> - 2010-03-01 10:57:20
|
I sent much the same thing in a patch to Fred. I suspect that he didn't notice because it is called winsocket on Windows. On Mon, Mar 1, 2010 at 2:38 AM, Martin Spott <Mar...@mg...> wrote: > I'm expieriencing difficulties to compile 'terrasync' after the latest > patch. While PLIB's socket seems to be the target, the type "socket" > interferes with the system headers: > > g++ -g -O3 -march=opteron -DHAVE_CONFIG_H -I. -I../../src/Include -I/usr/include/subversion-1 -I/usr/include/apr-1.0 -I/opt/gnu/include -I/usr/local/include -I/opt/Boost/include/boost-1_37 -I/opt/FlightGear/include -g -O2 -I/opt/FlightGear -D_REENTRANT -c -o terrasync.o terrasync.cxx > terrasync.cxx:118: error: 'netSocket socket' redeclared as different kind of symbol > /usr/include/sys/socket.h:101: error: previous declaration of 'int socket(int, int, int)' > terrasync.cxx: In function 'void terminate_request_handler(int)': > terrasync.cxx:298: error: request for member 'close' in 'socket', which is of non-class type 'int ()(int, int, int)throw ()' > [...] > > > The following simple patch at least permits to compile - is this the > way it's meant to be ? > > --- terrasync.cxx.original 2010-03-01 08:44:20.000000000 +0100 > +++ terrasync.cxx 2010-03-01 11:35:55.975624335 +0100 > @@ -115,7 +115,7 @@ > deque<string> waitingTiles; > typedef map<string,time_t> CompletedTiles; > CompletedTiles completedTiles; > -netSocket socket; > +netSocket netSocket; > > #ifdef HAVE_SVN_CLIENT_H > > @@ -295,7 +295,7 @@ > write(1, msg, sizeof(msg) - 1); > terminating = true; > signal(param, prior_signal_handlers[param]); > - socket.close(); > + netSsocket.close(); > } > > > @@ -517,12 +517,12 @@ > // Must call this before any other net stuff > netInit( &argc,argv ); > > - if ( ! socket.open( false ) ) { // open a UDP socket > + if ( ! netSocket.open( false ) ) { // open a UDP socket > printf("error opening socket\n"); > return -1; > } > > - if ( socket.bind( host, port ) == -1 ) { > + if ( netSocket.bind( host, port ) == -1 ) { > printf("error binding to port %d\n", port); > return -1; > } > @@ -571,8 +571,8 @@ > if (verbose && waitingTiles.empty()) { > cout << "Idle; waiting for FlightGear position\n"; > } > - socket.setBlocking(waitingTiles.empty()); > - len = socket.recv(msg, maxlen, 0); > + netSocket.setBlocking(waitingTiles.empty()); > + len = netSocket.recv(msg, maxlen, 0); > if (len >= 0) { > msg[len] = '\0'; > recv_msg = true; > > > Cheers, > Martin. > -- > Unix _IS_ user friendly - it's just selective about who its friends are ! > -------------------------------------------------------------------------- > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > Flightgear-devel mailing list > Fli...@li... > https://lists.sourceforge.net/lists/listinfo/flightgear-devel > |
From: Frederic B. <fre...@fr...> - 2010-03-01 11:39:49
|
Hi Martin, ----- "Martin Spott" a écrit : > I'm expieriencing difficulties to compile 'terrasync' after the > latest > patch. While PLIB's socket seems to be the target, the type "socket" > interferes with the system headers: > > g++ -g -O3 -march=opteron -DHAVE_CONFIG_H -I. -I../../src/Include > -I/usr/include/subversion-1 -I/usr/include/apr-1.0 > -I/opt/gnu/include -I/usr/local/include > -I/opt/Boost/include/boost-1_37 -I/opt/FlightGear/include -g -O2 > -I/opt/FlightGear -D_REENTRANT -c -o terrasync.o terrasync.cxx > terrasync.cxx:118: error: 'netSocket socket' redeclared as different > kind of symbol > /usr/include/sys/socket.h:101: error: previous declaration of 'int > socket(int, int, int)' > terrasync.cxx: In function 'void terminate_request_handler(int)': > terrasync.cxx:298: error: request for member 'close' in 'socket', > which is of non-class type 'int ()(int, int, int)throw ()' > [...] > > > The following simple patch at least permits to compile - is this the > way it's meant to be ? Sorry I created a name conflict under unix. Obviously, the variable name should be changed, but I am surprised you could name a variable with its type name. I didn't want the original 's' be in the global namespace, and that's why I renamed it. I am inclined to name the variable theSocket or something like that. Anyway, I won't be able to commit anything until this evening (CET time). Regards, -Fred -- Frédéric Bouvier http://my.fotolia.com/frfoto/ Photo gallery - album photo http://fgsd.sourceforge.net/ FlightGear Scenery Designer |
From: Martin S. <Mar...@mg...> - 2010-03-01 11:55:10
|
Frederic Bouvier wrote: > Anyway, I won't be able to commit anything until this evening (CET time). No problem, Martin. -- Unix _IS_ user friendly - it's just selective about who its friends are ! -------------------------------------------------------------------------- |
From: Martin S. <Mar...@mg...> - 2010-03-01 10:52:42
|
.... ooops ! Martin Spott wrote: > @@ -295,7 +295,7 @@ > write(1, msg, sizeof(msg) - 1); > terminating = true; > signal(param, prior_signal_handlers[param]); > - socket.close(); > + netSsocket.close(); ^^ Sorry, Martin. -- Unix _IS_ user friendly - it's just selective about who its friends are ! -------------------------------------------------------------------------- |