Refactor Request handling into thread. Profiling.

md5sum a.out
2516cdefcb423ae9f77531e8d3c7a411  a.out

Moved the socket reading into the thread so the main one isn't blocked
up by processing a request.

Added -pg flags to makefile (not committed) in order to run gprof to
profile the heatmap PUT endpoint as it is fairly important. Results are
as shown:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 56.76      0.21     0.21        1   210.02   210.02  parseRequest
 43.25      0.37     0.16        1   160.02   160.02  run_network
  0.00      0.37     0.00     2097     0.00     0.00  get_pair
  0.00      0.37     0.00     2097     0.00     0.00  hash
  0.00      0.37     0.00      932     0.00     0.00  createDecimalFromString
  0.00      0.37     0.00      699     0.00     0.00  sm_exists
  0.00      0.37     0.00      699     0.00     0.00  sm_get
  0.00      0.37     0.00      699     0.00     0.00  sm_put
  0.00      0.37     0.00      466     0.00     0.00  gs_heatmap_ZeroStruct
  0.00      0.37     0.00      466     0.00     0.00  gs_heatmap_setIntensity
  0.00      0.37     0.00      466     0.00     0.00  gs_heatmap_setScopeId
  0.00      0.37     0.00      235     0.00     0.00  sm_delete
  0.00      0.37     0.00      235     0.00     0.00  sm_new
  0.00      0.37     0.00      233     0.00     0.00  create_node
  0.00      0.37     0.00      233     0.00     0.00  db_insertHeatmap
  0.00      0.37     0.00      233     0.00     0.00  gs_heatmap_setCreatedTime
  0.00      0.37     0.00      233     0.00     0.00  gs_heatmap_setId
  0.00      0.37     0.00      233     0.00     0.00  gs_heatmap_setLatitude
  0.00      0.37     0.00      233     0.00     0.00  gs_heatmap_setLongitude
  0.00      0.37     0.00       13     0.00     0.00  strnstr
  0.00      0.37     0.00        2     0.00     0.00  _getMySQLConnection
  0.00      0.37     0.00        1     0.00     0.00  createResponse
  0.00      0.37     0.00        1     0.00     0.00  createSocket
  0.00      0.37     0.00        1     0.00     0.00  db_end_transaction
  0.00      0.37     0.00        1     0.00     0.00  db_getScopeById
  0.00      0.37     0.00        1     0.00     0.00  db_start_transaction
  0.00      0.37     0.00        1     0.00     0.00  destroy_list
  0.00      0.37     0.00        1     0.00     0.00  determineController
  0.00      0.37     0.00        1     0.00   160.02  green_serv
  0.00      0.37     0.00        1     0.00     0.00  gs_scope_ZeroStruct
  0.00      0.37     0.00        1     0.00     0.00  gs_scope_setDesc
  0.00      0.37     0.00        1     0.00     0.00  gs_scope_setId
  0.00      0.37     0.00        1     0.00     0.00  heatmap_controller
  0.00      0.37     0.00        1     0.00     0.00  heatmap_put
  0.00      0.37     0.00        1     0.00     0.00  parseArgs
  0.00      0.37     0.00        1     0.00     0.00  parseURL
  0.00      0.37     0.00        1     0.00     0.00  setupSockAndBind
  0.00      0.37     0.00        1     0.00     0.00  validateJSON

		     Call graph
granularity: each sample hit covers 2 byte(s) for 2.70% of 0.37 seconds

index % time    self  children    called     name
                0.21    0.00       1/1           doNetWork [2]
[1]     56.8    0.21    0.00       1         parseRequest [1]
                0.00    0.00       6/13          strnstr [23]
-----------------------------------------------
                                                 <spontaneous>
[2]     56.8    0.00    0.21                 doNetWork [2]
                0.21    0.00       1/1           parseRequest [1]
                0.00    0.00       7/13          strnstr [23]
                0.00    0.00       1/1           determineController[30]
                0.00    0.00       1/1           heatmap_controller [34]
                0.00    0.00       1/1           createResponse [24]
-----------------------------------------------
                0.00    0.16       1/1           main [5]
[3]     43.2    0.00    0.16       1         green_serv [3]
                0.16    0.00       1/1           run_network [4]
                0.00    0.00       1/2           _getMySQLConnection[131]
                0.00    0.00       1/1           db_getScopeById [27]
                0.00    0.00       1/1           parseArgs [36]
-----------------------------------------------
                0.16    0.00       1/1           green_serv [3]
[4]     43.2    0.16    0.00       1         run_network [4]
                0.00    0.00       1/1           createSocket [25]
                0.00    0.00       1/1           setupSockAndBind [38]
-----------------------------------------------
                                                 <spontaneous>
[5]     43.2    0.00    0.16                 main [5]
                0.00    0.16       1/1           green_serv [3]
-----------------------------------------------
                0.00    0.00     699/2097        sm_get [10]
                0.00    0.00     699/2097        sm_exists [9]
                0.00    0.00     699/2097        sm_put [11]
[6]      0.0    0.00    0.00    2097         get_pair [6]
-----------------------------------------------
                0.00    0.00     699/2097        sm_get [10]
                0.00    0.00     699/2097        sm_exists [9]
                0.00    0.00     699/2097        sm_put [11]
[7]      0.0    0.00    0.00    2097         hash [7]
-----------------------------------------------
                0.00    0.00     466/932         db_insertHeatmap [18]
                0.00    0.00     466/932         heatmap_put [35]
[8]      0.0    0.00    0.00     932         createDecimalFromString [8]
-----------------------------------------------
                0.00    0.00     699/699         heatmap_put [35]
[9]      0.0    0.00    0.00     699         sm_exists [9]
                0.00    0.00     699/2097        hash [7]
                0.00    0.00     699/2097        get_pair [6]
-----------------------------------------------
                0.00    0.00     699/699         heatmap_put [35]
[10]     0.0    0.00    0.00     699         sm_get [10]
                0.00    0.00     699/2097        hash [7]
                0.00    0.00     699/2097        get_pair [6]
-----------------------------------------------
                0.00    0.00     699/699         heatmap_put [35]
[11]     0.0    0.00    0.00     699         sm_put [11]
                0.00    0.00     699/2097        hash [7]
                0.00    0.00     699/2097        get_pair [6]
-----------------------------------------------
                0.00    0.00     233/466         db_insertHeatmap [18]
                0.00    0.00     233/466         heatmap_put [35]
[12]     0.0    0.00    0.00     466         gs_heatmap_ZeroStruct [12]
-----------------------------------------------
                0.00    0.00     233/466         db_insertHeatmap [18]
                0.00    0.00     233/466         heatmap_put [35]
[13]     0.0    0.00    0.00     466         gs_heatmap_setIntensity[13]
-----------------------------------------------
                0.00    0.00     233/466         db_insertHeatmap [18]
                0.00    0.00     233/466         heatmap_put [35]
[14]     0.0    0.00    0.00     466         gs_heatmap_setScopeId [14]
-----------------------------------------------
                0.00    0.00       1/235         heatmap_controller [34]
                0.00    0.00     234/235         heatmap_put [35]
[15]     0.0    0.00    0.00     235         sm_delete [15]
-----------------------------------------------
                0.00    0.00       1/235         heatmap_controller [34]
                0.00    0.00     234/235         heatmap_put [35]
[16]     0.0    0.00    0.00     235         sm_new [16]
-----------------------------------------------
                0.00    0.00     233/233         heatmap_put [35]
[17]     0.0    0.00    0.00     233         create_node [17]
-----------------------------------------------
                0.00    0.00     233/233         heatmap_put [35]
[18]     0.0    0.00    0.00     233         db_insertHeatmap [18]
                0.00    0.00     466/932         createDecimalFromString[8]
                0.00    0.00     233/466         gs_heatmap_ZeroStruct[12]
                0.00    0.00     233/233         gs_heatmap_setId [20]
                0.00    0.00     233/466         gs_heatmap_setIntensity[13]
                0.00    0.00     233/466         gs_heatmap_setScopeId[14]
                0.00    0.00     233/233         gs_heatmap_setCreatedTime [19]
-----------------------------------------------
                0.00    0.00     233/233         db_insertHeatmap [18]
[19]     0.0    0.00    0.00     233         gs_heatmap_setCreatedTime [19]
-----------------------------------------------
                0.00    0.00     233/233         db_insertHeatmap [18]
[20]     0.0    0.00    0.00     233         gs_heatmap_setId [20]
-----------------------------------------------
                0.00    0.00     233/233         heatmap_put [35]
[21]     0.0    0.00    0.00     233         gs_heatmap_setLatitude [21]
-----------------------------------------------
                0.00    0.00     233/233         heatmap_put [35]
[22]     0.0    0.00    0.00     233         gs_heatmap_setLongitude [22]
-----------------------------------------------
                0.00    0.00       6/13          parseRequest [1]
                0.00    0.00       7/13          doNetWork [2]
[23]     0.0    0.00    0.00      13         strnstr [23]
-----------------------------------------------
                0.00    0.00       1/1           doNetWork [2]
[24]     0.0    0.00    0.00       1         createResponse [24]
-----------------------------------------------
                0.00    0.00       1/1           run_network [4]
[25]     0.0    0.00    0.00       1         createSocket [25]
-----------------------------------------------
                0.00    0.00       1/1           heatmap_put [35]
[26]     0.0    0.00    0.00       1         db_end_transaction [26]
-----------------------------------------------
                0.00    0.00       1/1           green_serv [3]
[27]     0.0    0.00    0.00       1         db_getScopeById [27]
                0.00    0.00       1/1           gs_scope_ZeroStruct
[31]
                0.00    0.00       1/1           gs_scope_setId [33]
                0.00    0.00       1/1           gs_scope_setDesc [32]
-----------------------------------------------
                0.00    0.00       1/1           heatmap_put [35]
[28]     0.0    0.00    0.00       1         db_start_transaction [28]
-----------------------------------------------
                                 233             destroy_list [29]
                0.00    0.00       1/1           heatmap_put [35]
[29]     0.0    0.00    0.00       1+233     destroy_list [29]
                                 233             destroy_list [29]
-----------------------------------------------
                0.00    0.00       1/1           doNetWork [2]
[30]     0.0    0.00    0.00       1         determineController [30]
-----------------------------------------------
                0.00    0.00       1/1           db_getScopeById [27]
[31]     0.0    0.00    0.00       1         gs_scope_ZeroStruct [31]
-----------------------------------------------
                0.00    0.00       1/1           db_getScopeById [27]
[32]     0.0    0.00    0.00       1         gs_scope_setDesc [32]
-----------------------------------------------
                0.00    0.00       1/1           db_getScopeById [27]
[33]     0.0    0.00    0.00       1         gs_scope_setId [33]
-----------------------------------------------
                0.00    0.00       1/1           doNetWork [2]
[34]     0.0    0.00    0.00       1         heatmap_controller [34]
                0.00    0.00       1/235         sm_new [16]
                0.00    0.00       1/1           parseURL [37]
                0.00    0.00       1/1           heatmap_put [35]
                0.00    0.00       1/235         sm_delete [15]
-----------------------------------------------
                0.00    0.00       1/1           heatmap_controller [34]
[35]     0.0    0.00    0.00       1         heatmap_put [35]
                0.00    0.00     699/699         sm_put [11]
                0.00    0.00     699/699         sm_exists [9]
                0.00    0.00     699/699         sm_get [10]
                0.00    0.00     466/932         createDecimalFromString[8]
                0.00    0.00     234/235         sm_new [16]
                0.00    0.00     234/235         sm_delete [15]
                0.00    0.00     233/466         gs_heatmap_ZeroStruct
[12]
                0.00    0.00     233/466         gs_heatmap_setScopeId
[14]
                0.00    0.00     233/233         gs_heatmap_setLongitude
[22]
                0.00    0.00     233/233         gs_heatmap_setLatitude
[21]
                0.00    0.00     233/466         gs_heatmap_setIntensity
[13]
                0.00    0.00     233/233         create_node [17]
                0.00    0.00     233/233         db_insertHeatmap [18]
                0.00    0.00       1/1           validateJSON [39]
                0.00    0.00       1/2           _getMySQLConnection
[131]
                0.00    0.00       1/1           db_start_transaction
[28]
                0.00    0.00       1/1           db_end_transaction [26]
                0.00    0.00       1/1           destroy_list [29]
-----------------------------------------------
                0.00    0.00       1/1           green_serv [3]
[36]     0.0    0.00    0.00       1         parseArgs [36]
-----------------------------------------------
                0.00    0.00       1/1           heatmap_controller [34]
[37]     0.0    0.00    0.00       1         parseURL [37]
-----------------------------------------------
                0.00    0.00       1/1           run_network [4]
[38]     0.0    0.00    0.00       1         setupSockAndBind [38]
-----------------------------------------------
                0.00    0.00       1/1           heatmap_put [35]
[39]     0.0    0.00    0.00       1         validateJSON [39]
-----------------------------------------------
                0.00    0.00       1/2           green_serv [3]
                0.00    0.00       1/2           heatmap_put [35]
[131]    0.0    0.00    0.00       2         _getMySQLConnection [131]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.

Index by function name

 [131] _getMySQLConnection    [12] gs_heatmap_ZeroStruct  [36] parseArgs
   [8] createDecimalFromString [19] gs_heatmap_setCreatedTime [1]parseRequest
  [24] createResponse         [20] gs_heatmap_setId       [37] parseURL
  [25] createSocket           [13] gs_heatmap_setIntensity [4]run_network
  [17] create_node            [21] gs_heatmap_setLatitude [38]setupSockAndBind
  [26] db_end_transaction     [22] gs_heatmap_setLongitude [15]sm_delete
  [27] db_getScopeById        [14] gs_heatmap_setScopeId   [9] sm_exists
  [18] db_insertHeatmap       [31] gs_scope_ZeroStruct    [10] sm_get
  [28] db_start_transaction   [32] gs_scope_setDesc       [16] sm_new
  [29] destroy_list           [33] gs_scope_setId         [11] sm_put
  [30] determineController     [7] hash                   [23] strnstr
   [6] get_pair               [34] heatmap_controller     [39]validateJSON
   [3] green_serv             [35] heatmap_put