Package DebTorrent :: Module SocketHandler :: Class SingleSocket
[hide private]
[frames] | no frames]

Class SingleSocket

source code

Manage a single socket.

Instance Methods [hide private]
 
__init__(self, socket_handler, sock, handler, dns=None) source code
string
get_ip(self, real=True)
Get the IP address of the socket.
source code
(string, int)
getpeername(self, real=True)
Get the IP address and port of the socket.
source code
 
close(self)
Close the socket.
source code
 
shutdown(self, val)
Shutdown the socket.
source code
boolean
is_flushed(self)
Check if the socket is flushed (no data is waiting to be sent).
source code
 
write(self, s)
Write data out on the socket.
source code
 
try_write(self)
Try to write waiting data on the socket.
source code
 
set_handler(self, handler)
Set the handler to use for this socket.
source code
Instance Variables [hide private]
list of string buffer
the list of data waiting to be written on the socket
boolean connected
whether this socket has received an event yet
(string, int) dns
the IP address and port to use if one can't be obtained from the socket
int fileno
the file number of the socket
unknown handler
the handler to use for all communications on the socket
float last_hit
the last time data was received on the socket
int skipped
the number of consecutive writes to the socket that have failed
socket.socket socket
the socket to manage
SocketHandler socket_handler
the collection of all sockets
Method Details [hide private]

__init__(self, socket_handler, sock, handler, dns=None)
(Constructor)

source code 
Parameters:
  • socket_handler (SocketHandler) - the collection of all sockets
  • sock (socket.socket) - the socket to manage
  • handler (unknown) - the handler to use for all communications on the socket
  • dns ((string, int)) - the IP address and port to use if one can't be obtained from the socket (optional, defaults to 'unknown')

get_ip(self, real=True)

source code 
Get the IP address of the socket.
Parameters:
  • real (boolean) - whether to try and get the IP address directly from the socket or trust the one supplied when the instance was created (optional, defaults to False)
Returns: string
the IP address

getpeername(self, real=True)

source code 
Get the IP address and port of the socket.
Parameters:
  • real (boolean) - whether to try and get the IP address directly from the socket or trust the one supplied when the instance was created (optional, defaults to False)
Returns: (string, int)
the IP address and port of the remote connection

shutdown(self, val)

source code 
Shutdown the socket.
Parameters:
  • val (int) - the type of event to shutdown the socket for. 0 = reading, 1 = writing, 2 = reading and writing.

is_flushed(self)

source code 
Check if the socket is flushed (no data is waiting to be sent).
Returns: boolean
whether the socket is flushed

write(self, s)

source code 

Write data out on the socket.

Adds the data to the buffer of data waiting to be written, then tries to write the waiting data out.
Parameters:
  • s (string) - the data to write

try_write(self)

source code 

Try to write waiting data on the socket.

Will try to write all buffered data on the socket. If a send fails, the attempt will stop. 3 consecutive failed attempts will cause the socket to be declared dead.

set_handler(self, handler)

source code 
Set the handler to use for this socket.
Parameters:
  • handler (unknown) - the handler to use for all communications on the socket