Author: cazfi
Date: Thu Feb 11 13:00:30 2016
New Revision: 31871

URL: http://svn.gna.org/viewcvs/freeciv?rev=31871&view=rev
Log:
Added client Heartbeat feature to see that the server connection remains.

See bug #19561

Modified:
    trunk/client/client_main.c
    trunk/client/options.c
    trunk/client/options.h
    trunk/common/packets.def
    trunk/fc_version
    trunk/server/sernet.c
    trunk/server/sernet.h
    trunk/server/srv_main.c

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Thu Feb 11 13:00:30 2016
@@ -1194,6 +1194,16 @@
     }
   }
 
+  {
+    static long counter = 0;
+
+    counter++;
+
+    if (gui_options.heartbeat_enabled && (counter % (20 * 10) == 0)) {
+      send_packet_client_heartbeat(&client.conn);
+    }
+  }
+
   /* Make sure we wait at least 50 ms, otherwise we may not give any other
    * code time to run. */
   return MAX(time_until_next_call, 0.05);

Modified: trunk/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.c?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/client/options.c      (original)
+++ trunk/client/options.c      Thu Feb 11 13:00:30 2016
@@ -85,6 +85,7 @@
   .save_options_on_exit = TRUE,
 
   .use_prev_server = FALSE,
+  .heartbeat_enabled = FALSE,
 
 /** Migrations **/
   .first_boot = FALSE,
@@ -1843,6 +1844,12 @@
                     "this from its default value unless you know what "
                     "you're doing."),
                  COC_NETWORK, GUI_STUB, DEFAULT_METASERVER_OPTION, NULL, 0),
+  GEN_BOOL_OPTION(heartbeat_enabled, N_("Send heartbeat messages to server."),
+                  N_("Regularly send empty heartbeat message to the server "
+                     "to make sure that the connection is still up. This "
+                     "can be useful if the client otherwise may sit for a "
+                     "long time with no data being sent or received at all."),
+                  COC_NETWORK, GUI_STUB, NULL, NULL),
   GEN_STR_LIST_OPTION(default_sound_set_name,
                       N_("Soundset"),
                       N_("This is the soundset that will be used.  Changing "

Modified: trunk/client/options.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.h?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/client/options.h      (original)
+++ trunk/client/options.h      Thu Feb 11 13:00:30 2016
@@ -94,6 +94,7 @@
   char default_server_host[512];
   int  default_server_port;
   bool use_prev_server;
+  bool heartbeat_enabled;
   char default_metaserver[512];
   char default_tileset_overhead_name[512];
   char default_tileset_iso_name[512];

Modified: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Thu Feb 11 13:00:30 2016
@@ -3,7 +3,7 @@
 Max used id:
 ============
 
-Max id: 253
+Max id: 254
 
 Packets are not ordered by their id, but by their category. New packet
 with higher id may get added to existing category, and not to the end of file.
@@ -1190,6 +1190,9 @@
 PACKET_CONN_PONG = 89; cs, handle-per-conn
 end
 
+PACKET_CLIENT_HEARTBEAT = 254; cs, handle-per-conn
+end
+
 PACKET_CLIENT_INFO = 119; cs, handle-per-conn
   GUI_TYPE gui;
   STRING distribution[MAX_LEN_NAME];

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Thu Feb 11 13:00:30 2016
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Feb.09"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Feb.11"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/sernet.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/sernet.c?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/server/sernet.c       (original)
+++ trunk/server/sernet.c       Thu Feb 11 13:00:30 2016
@@ -1406,6 +1406,14 @@
 }
 
 /**************************************************************************
+  Handle client's regular hearbeat
+**************************************************************************/
+void handle_client_heartbeat(struct connection *pconn)
+{
+  log_debug("Received heartbeat");
+}
+
+/**************************************************************************
   Send ping time info about all connections to all connections.
 **************************************************************************/
 static void send_ping_times_to_all(void)

Modified: trunk/server/sernet.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/sernet.h?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/server/sernet.h       (original)
+++ trunk/server/sernet.h       Thu Feb 11 13:00:30 2016
@@ -40,6 +40,7 @@
 int server_make_connection(int new_sock,
                            const char *client_addr, const char *client_ip);
 void handle_conn_pong(struct connection *pconn);
+void handle_client_heartbeat(struct connection *pconn);
 
 #ifdef __cplusplus
 }

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=31871&r1=31870&r2=31871&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Thu Feb 11 13:00:30 2016
@@ -1789,6 +1789,7 @@
       || type == PACKET_REPORT_REQ
       || type == PACKET_CLIENT_INFO
       || type == PACKET_CONN_PONG
+      || type == PACKET_CLIENT_HEARTBEAT
       || type == PACKET_SAVE_SCENARIO
       || is_client_edit_packet(type)) {
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to