mirror of https://github.com/fail2ban/fail2ban
- 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-b1dcaea8d6050.x
parent
bb6c14bfea
commit
b5abd7f2f2
|
@ -24,7 +24,7 @@ __date__ = "$Date$"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
import socket, pickle
|
import socket, cPickle
|
||||||
|
|
||||||
class CSocket:
|
class CSocket:
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class CSocket:
|
||||||
|
|
||||||
def send(self, msg):
|
def send(self, msg):
|
||||||
# Convert every list member to string
|
# 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)
|
self.__csock.send(obj + CSocket.END_STRING)
|
||||||
ret = self.receive(self.__csock)
|
ret = self.receive(self.__csock)
|
||||||
self.__csock.close()
|
self.__csock.close()
|
||||||
|
@ -53,4 +53,4 @@ class CSocket:
|
||||||
if chunk == '':
|
if chunk == '':
|
||||||
raise RuntimeError, "socket connection broken"
|
raise RuntimeError, "socket connection broken"
|
||||||
msg = msg + chunk
|
msg = msg + chunk
|
||||||
return pickle.loads(msg)
|
return cPickle.loads(msg)
|
||||||
|
|
|
@ -25,7 +25,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
from threading import Thread
|
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.
|
# Gets the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban.comm")
|
logSys = logging.getLogger("fail2ban.comm")
|
||||||
|
@ -109,7 +109,7 @@ class SocketWorker(Thread):
|
||||||
logSys.debug("Connection closed")
|
logSys.debug("Connection closed")
|
||||||
|
|
||||||
def __send(self, socket, msg):
|
def __send(self, socket, msg):
|
||||||
obj = pickle.dumps(msg)
|
obj = cPickle.dumps(msg)
|
||||||
socket.send(obj + SSocket.END_STRING)
|
socket.send(obj + SSocket.END_STRING)
|
||||||
|
|
||||||
def __receive(self, socket):
|
def __receive(self, socket):
|
||||||
|
@ -119,7 +119,7 @@ class SocketWorker(Thread):
|
||||||
if chunk == '':
|
if chunk == '':
|
||||||
raise RuntimeError, "socket connection broken"
|
raise RuntimeError, "socket connection broken"
|
||||||
msg = msg + chunk
|
msg = msg + chunk
|
||||||
return pickle.loads(msg)
|
return cPickle.loads(msg)
|
||||||
|
|
||||||
|
|
||||||
class SSocketErrorException(Exception):
|
class SSocketErrorException(Exception):
|
||||||
|
|
Loading…
Reference in New Issue