Browse Source

- Use cPickle instead of pickle. cPickle can be up to 1000 times faster

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@379 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 18 years ago
parent
commit
b5abd7f2f2
  1. 6
      client/csocket.py
  2. 6
      server/ssocket.py

6
client/csocket.py

@ -24,7 +24,7 @@ __date__ = "$Date$"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
import socket, pickle
import socket, cPickle
class CSocket:
@ -40,7 +40,7 @@ class CSocket:
def send(self, msg):
# Convert every list member to string
obj = pickle.dumps(map(str, msg))
obj = cPickle.dumps(map(str, msg))
self.__csock.send(obj + CSocket.END_STRING)
ret = self.receive(self.__csock)
self.__csock.close()
@ -53,4 +53,4 @@ class CSocket:
if chunk == '':
raise RuntimeError, "socket connection broken"
msg = msg + chunk
return pickle.loads(msg)
return cPickle.loads(msg)

6
server/ssocket.py

@ -25,7 +25,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
from threading import Thread
import socket, time, logging, pickle, os, os.path
import socket, time, logging, cPickle, os, os.path
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban.comm")
@ -109,7 +109,7 @@ class SocketWorker(Thread):
logSys.debug("Connection closed")
def __send(self, socket, msg):
obj = pickle.dumps(msg)
obj = cPickle.dumps(msg)
socket.send(obj + SSocket.END_STRING)
def __receive(self, socket):
@ -119,7 +119,7 @@ class SocketWorker(Thread):
if chunk == '':
raise RuntimeError, "socket connection broken"
msg = msg + chunk
return pickle.loads(msg)
return cPickle.loads(msg)
class SSocketErrorException(Exception):

Loading…
Cancel
Save