# # Copyright(C) 2008 Litesim Ltd # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # litesim-specific IPC handling # This one is cross-platform (IronPython or the snake itself (CPython)) import sys if sys.platform=='cli': import utils from sockfix import * from utils import * from System import * from socket import * else: old_path = sys.path sys.path.remove('') from socket import * sys.path = old_path import Queue import thread import random import time def parse_it(it): # parse it, whatever "it" is f = {} cf = 0 i = 0 l = len(it) while i1: if (parsed_pack[0] == 'ACK') and self.pending_ack.has_key(parsed_pack[1]): del self.pending_ack[parsed_pack[1]] elif parsed_pack[0].startswith('+') or parsed_pack[0].startswith('-'): if self.packet_handlers.has_key(parsed_pack[1]): params = parsed_pack[2:len(parsed_pack)-2] self.packet_handlers[parsed_pack[1]](addr=pack_addr,id=parsed_pack[0].strip('+').strip('-'),params=params) if pack_data.startswith('+'): server_sock.sendto('ACK:' + parsed_pack[0].strip('+').strip('-')) except Exception, e: print str(e) def start_server(self,thread_count=1): self.running = True for i in range(thread_count): self.worker_threads.append(thread.start_new_thread(self.process_pack_loop,())) self.dispatcher = thread.start_new_thread(self.dispatch_pack_loop,()) ~