Author: cazfi
Date: Thu Feb 11 13:00:48 2016
New Revision: 31872

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

See bug #19561

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

Modified: branches/S2_6/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.c?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/client/client_main.c  (original)
+++ branches/S2_6/client/client_main.c  Thu Feb 11 13:00:48 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: branches/S2_6/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/options.c?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/client/options.c      (original)
+++ branches/S2_6/client/options.c      Thu Feb 11 13:00:48 2016
@@ -85,6 +85,7 @@
   .save_options_on_exit = TRUE,
 
   .use_prev_server = FALSE,
+  .heartbeat_enabled = FALSE,
 
 /** Migrations **/
   .first_boot = FALSE,
@@ -1808,6 +1809,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: branches/S2_6/client/options.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/options.h?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/client/options.h      (original)
+++ branches/S2_6/client/options.h      Thu Feb 11 13:00:48 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: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Thu Feb 11 13:00:48 2016
@@ -3,7 +3,7 @@
 Max used id:
 ============
 
-Max id: 250
+Max id: 251
 
 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.
@@ -1184,6 +1184,9 @@
 PACKET_CONN_PONG = 89; cs, handle-per-conn
 end
 
+PACKET_CLIENT_HEARTBEAT = 251; cs, handle-per-conn
+end
+
 PACKET_CLIENT_INFO = 119; cs, handle-per-conn
   GUI_TYPE gui;
   STRING distribution[MAX_LEN_NAME];

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Thu Feb 11 13:00:48 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-2.6-2016.Feb.09"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2016.Feb.11"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/sernet.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/sernet.c?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/server/sernet.c       (original)
+++ branches/S2_6/server/sernet.c       Thu Feb 11 13:00:48 2016
@@ -1412,6 +1412,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: branches/S2_6/server/sernet.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/sernet.h?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/server/sernet.h       (original)
+++ branches/S2_6/server/sernet.h       Thu Feb 11 13:00:48 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: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=31872&r1=31871&r2=31872&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Thu Feb 11 13:00:48 2016
@@ -1832,6 +1832,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