Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Cat7373/XX-Net
Browse files Browse the repository at this point in the history
  • Loading branch information
xxnet committed Nov 22, 2015
2 parents cf89485 + 725a699 commit a423f3f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
21 changes: 19 additions & 2 deletions gae_proxy/local/simple_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,39 @@ def do_CONNECT(self):

class HTTPServer():
def __init__(self, address, handler, args=()):
self.socket = None
self.running = True
self.server_address = address
self.handler = handler
self.args = args
self.init_socket()
xlog.info("server %s:%d started.", address[0], address[1])

def init_socket(self):
if self.socket is not None:
self.server_close()
self.socket = None

self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)
self.socket.listen(200)
xlog.info("server %s:%d started.", address[0], address[1])

def serve_forever(self):
fdset = [self.socket, ]
while self.running:
r, w, e = select.select(fdset, [], [], 1)
if self.socket in r:
(sock, address) = self.socket.accept()
try:
(sock, address) = self.socket.accept()
except IOError as e:
xlog.warn("socket(%s:%s) accept fail(errno: %s).", self.server_address[0], self.server_address[1], e.args[0])
if e.args[0] == 10022:
xlog.info("server %s:%d restarted.", self.server_address[0], self.server_address[1])
self.init_socket()
fdset = [self.socket, ]
return

self.process_connect(sock, address)

def process_connect(self, sock, address):
Expand Down
25 changes: 25 additions & 0 deletions launcher/web_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ def handle_error(self, *args):
del etype, value
SocketServer.ThreadingTCPServer.handle_error(self, *args)

def _handle_request_noblock(self):
try:
request, client_address = self.get_request()
except IOError as e:
launcher_log.warn("socket(%s:%s) accept fail(errno: %s).", self.server_address[0], self.server_address[1], e.args[0])
if e.args[0] == 10022:
launcher_log.info("server %s:%d restarted.", self.server_address[0], self.server_address[1])
self.init_socket()
return

if self.verify_request(request, client_address):
try:
self.process_request(request, client_address)
except:
self.handle_error(request, client_address)
self.shutdown_request(request)

def init_socket(self):
self.server_close()
self.socket = None

self.socket = socket.socket(self.address_family, self.socket_type)
self.server_bind()
self.server_activate()

module_menus = {}
class Http_Handler(BaseHTTPServer.BaseHTTPRequestHandler):
deploy_proc = None
Expand Down

0 comments on commit a423f3f

Please sign in to comment.