Skip to content

Commit

Permalink
wslink 2017-07-18 (4c61940a)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://github.com/Kitware/wslink.git

at commit 4c61940a85496b0fd4e567f62d6b32f490156fa6 (master).
  • Loading branch information
kwrobot authored and aronhelser committed Jul 18, 2017
1 parent f079029 commit 721af5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/src/wslink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
wslink.server creates the python server
wslink.websocket handles the communication
"""
__version__ = '0.1.1'
__version__ = '0.1.2'
__license__ = 'BSD-3-Clause'

from .uri import checkURI
Expand Down
10 changes: 9 additions & 1 deletion python/src/wslink/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from __future__ import absolute_import, division, print_function

import logging
import logging, sys

# from vtk.web import testing
from wslink import upload
Expand All @@ -25,6 +25,12 @@
from twisted.internet.endpoints import serverFromString
from twisted.python import log

def print_ready():
# Emit an expected log message so launcher.py knows we've started up.
log.msg("wslink: Starting factory", logLevel=logging.CRITICAL)
# We've seen some issues with stdout buffering - be conservative.
sys.stdout.flush()

# =============================================================================
# Setup default arguments to be parsed
# -s, --nosignalhandlers
Expand Down Expand Up @@ -220,6 +226,8 @@ def start_webserver(options, protocol=wsl.ServerProtocol, disableLogging=False):
# Initialize testing: checks if we're doing a test and sets it up
# testing.initialize(options, reactor, stop_webserver)

reactor.callWhenRunning(print_ready)

# Start the reactor
if options.nosignalhandlers:
reactor.run(installSignalHandlers=0)
Expand Down
13 changes: 11 additions & 2 deletions python/src/wslink/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def __init__(self, *args, **kwargs):
WebSocketServerFactory.__init__(self, *args, **kwargs)
WebSocketServerFactory.protocol = TimeoutWebSocketServerProtocol

def startFactory(self):
# this is only called if the WsSite factory isn't created first.
log.msg("wslink: Starting factory", logLevel=logging.CRITICAL)

def connectionMade(self):
if self._reaper:
log.msg("Client has reconnected, cancelling reaper", logLevel=logging.DEBUG)
Expand All @@ -172,12 +176,18 @@ def setServerProtocol(self, newServerProtocol):
def getServerProtocol(self):
return self._protocolHandler

### Does not seem to work to print a "ready line"
# def startFactory(self):
# sys.stdout.write("wslink: Starting factory\n")
# sys.stdout.flush()
# WebSocketServerFactory.startFactory(self)

def getClientCount(self):
return self.clientCount

# =============================================================================

class TimeoutWebSocketServerProtocol(WebSocketServerProtocol):
class TimeoutWebSocketServerProtocol(WebSocketServerProtocol, object):

def connectionMade(self):
WebSocketServerProtocol.connectionMade(self)
Expand All @@ -202,7 +212,6 @@ def connectionLost(self, reason):

class WslinkWebSocketServerProtocol(TimeoutWebSocketServerProtocol):
def __init__(self):
super(WslinkWebSocketServerProtocol, self).__init__()
self.functionMap = {}
self.attachmentMap = {}
self.attachmentId = 0
Expand Down

0 comments on commit 721af5c

Please sign in to comment.