Skip to content

Commit

Permalink
Add support for user-defined server timeout setting (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
blitzmann committed Feb 14, 2016
1 parent d85f8c0 commit 969952c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
19 changes: 18 additions & 1 deletion gui/builtinPreferenceViews/pyfaCrestPreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import service
from service.crest import CrestModes

from wx.lib.intctrl import IntCtrl

class PFCrestPref ( PreferenceView):
title = "CREST"

Expand Down Expand Up @@ -46,14 +48,26 @@ def populatePanel( self, panel ):

mainSizer.Add(rbSizer, 1, wx.ALL|wx.EXPAND, 0)

timeoutSizer = wx.BoxSizer(wx.HORIZONTAL)

self.stTimout = wx.StaticText( panel, wx.ID_ANY, u"Timeout (seconds):", wx.DefaultPosition, wx.DefaultSize, 0 )
self.stTimout.Wrap( -1 )

timeoutSizer.Add( self.stTimout, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5 )

self.intTimeout = IntCtrl(panel, max=300000, limited=True, value=self.settings.get('timeout'))
timeoutSizer.Add(self.intTimeout, 0, wx.ALL, 5 )
self.intTimeout.Bind(wx.lib.intctrl.EVT_INT, self.OnTimeoutChange)

mainSizer.Add(timeoutSizer, 0, wx.ALL|wx.EXPAND, 0)

detailsTitle = wx.StaticText( panel, wx.ID_ANY, "CREST client details", wx.DefaultPosition, wx.DefaultSize, 0 )
detailsTitle.Wrap( -1 )
detailsTitle.SetFont( wx.Font( 12, 70, 90, 90, False, wx.EmptyString ) )

mainSizer.Add( detailsTitle, 0, wx.ALL, 5 )
mainSizer.Add( wx.StaticLine( panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND, 5 )


fgAddrSizer = wx.FlexGridSizer( 2, 2, 0, 0 )
fgAddrSizer.AddGrowableCol( 1 )
fgAddrSizer.SetFlexibleDirection( wx.BOTH )
Expand Down Expand Up @@ -87,6 +101,9 @@ def populatePanel( self, panel ):
panel.SetSizer( mainSizer )
panel.Layout()

def OnTimeoutChange(self, event):
self.settings.set('timeout', event.GetEventObject().GetValue())

def OnModeChange(self, event):
self.settings.set('mode', event.GetInt())
self.ToggleProxySettings(self.settings.get('mode'))
Expand Down
8 changes: 6 additions & 2 deletions service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import thread
import wx
from service.settings import CRESTSettings

import logging

Expand Down Expand Up @@ -55,8 +56,11 @@ class StoppableHTTPServer(BaseHTTPServer.HTTPServer):

def server_bind(self):
BaseHTTPServer.HTTPServer.server_bind(self)
# Allow listening for 60 seconds
sec = 60
self.settings = CRESTSettings.getInstance()

# Allow listening for x seconds
sec = self.settings.get('timeout')
logger.debug("Running server for %d seconds", sec)

self.socket.settimeout(0.5)
self.max_tries = sec / self.socket.gettimeout()
Expand Down
2 changes: 1 addition & 1 deletion service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def __init__(self):
# mode
# 0 - Implicit authentication
# 1 - User-supplied client details
serviceCRESTDefaultSettings = {"mode": 0, "server": 0, "clientID": "", "clientSecret": ""}
serviceCRESTDefaultSettings = {"mode": 0, "server": 0, "clientID": "", "clientSecret": "", "timeout": 60}

self.serviceCRESTSettings = SettingsProvider.getInstance().getSettings("pyfaServiceCRESTSettings", serviceCRESTDefaultSettings)

Expand Down

0 comments on commit 969952c

Please sign in to comment.