Coverage for src/lib/python/isc/cc/session : 88%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# Copyright (C) 2009 Internet Systems Consortium. # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
else: self.socket_file = bind10_config.BIND10_MSGQ_SOCKET_FILE else: self.socket_file = socket_file
raise ProtocolError("Could not get local name") raise ProtocolError("Could not get local name") except socket.error as se: raise SessionError(se)
def lname(self):
# Build entire message.
# Send it in the blocking mode. On some systems send() may # actually send only part of the data, so we need to repeat it # until all data have been sent out.
"""Reads a message. If nonblock is true, and there is no message to read, it returns (None, None). If seq is not None, it should be a value as returned by group_sendmsg(), in which case only the response to that message is returned, and others will be queued until the next call to this method. If seq is None, only messages that are *not* responses will be returned, and responses will be queued. The queue is checked for relevant messages before data is read from the socket. Raises a SessionError if there is a JSON decode problem in the message that is read, or if the session has been closed prior to the call of recvmsg()""" else: raise SessionError("Session has been closed.") else: else: return isc.cc.message.from_wire(data[2:header_length+2]), None # TODO: when we have logging here, add a debug # message printing the data that we were unable # to parse as JSON
"""Try to get size bytes of data from the socket. Raises a ProtocolError if the size is 0. Raises any error from recv(). Returns whatever data was available (if >0 bytes). """ raise ProtocolError("Read of 0 bytes: connection closed")
"""Reads self._recv_len_size bytes of data from the socket into self._recv_len_data This is done through class variables so in the case of an EAGAIN we can continue on a subsequent call. Raises a ProtocolError, a socket.error (which may be timeout or eagain), or reads until we have all data we need. """
"""Reads self._recv_size bytes of data from the socket into self._recv_data. This is done through class variables so in the case of an EAGAIN we can continue on a subsequent call. Raises a ProtocolError, a socket.error (which may be timeout or eagain), or reads until we have all data we need. """
else: else:
# we might be in a call following an EAGAIN, in which case # we simply continue. In the first case, either # recv_size or recv_len size are not zero # they may never both be non-zero (we are either starting # a full read, or continuing one of the reads
# both zero, start a new full read
# no EAGAIN, so copy data and reset internal counters
# Only keep data in case of EAGAIN # unknown state otherwise, best to drop data self._recv_len_size = 0 self._recv_size = 0 # ctrl-c can result in EINTR, return None to prevent # stacktrace output if se.errno == errno.EINTR: return None raise se
"type": "subscribe", "group": group, "instance": instance, })
"type": "unsubscribe", "group": group, "instance": instance, })
"type": "send", "from": self._lname, "to": to, "group": group, "instance": instance, "seq": seq, }, isc.cc.message.to_wire(msg))
# return none twice to match normal return value # (so caller won't get a type error on no data) return (None, None)
"type": "send", "from": self._lname, "to": routing["from"], "group": routing["group"], "instance": routing["instance"], "seq": seq, "reply": routing["seq"], }, isc.cc.message.to_wire(msg))
"""Sets the socket timeout for blocking reads to the given number of milliseconds"""
"""Returns the current timeout for blocking reads (in milliseconds)"""
import doctest doctest.testmod() |