def recv_wait(self, timeout=60000): """@desc Wait for data""" #Just return True in case of eventlet if not self.__sock: self.__logger.error("Invalid Socket in recv_wait") raise InvalidSocketException("Socket is not created") return True
def recv_wait(self, timeout=60): """@desc Wait for data""" self.__logger.debug("Waiting for data to read on socket") if not self.__sock: self.__logger.error("Invalid socket in recv_wait") raise InvalidSocketException("Socket is not created") events = [] try: READ_ONLY = select.POLLIN | select.POLLPRI | select.POLLHUP | \ select.POLLERR poller = select.poll() poller.register(self.__sock, READ_ONLY) fd_to_socket = {self.__sock.fileno(): self.__sock} events = poller.poll(timeout) except Exception, ex: self.__logger.error("While waiting for data: %s" % ex)
def write(self, data): """ @desc Write data on socket. @param data: Data string which needs to be written. """ if not self.__sock: self.__logger.error("Invalid socket to write") raise InvalidSocketException("Socket is not created") sent = total_sent = 0 while total_sent < len(data): try: sent = self.__sock.send(data) self.__logger.debug("Sent chunk size: %s" % sent) except socket.timeout, ex: self.__logger.error("Socket timeout while writing : %s" % ex) except socket.error, ex: self.__logger.error("While writing Socket error: %s" % ex)
def read(self, size): """ @desc Read data from socket. @param size: number of bytes going to read. @return Read data string """ if not self.__sock: self.__logger.error("Invalid socket in read") raise InvalidSocketException("Socket is not created") self.__logger.debug("reading on socket with buffer size: %s" % size) bytes_read = len(self.__data_bytes) while (bytes_read < size): try: chunk = self.__sock.recv(MAX_READ_SIZE) except socket.error, ex: self.__logger.error("While reading: %s" % ex) raise SocketReadException("Socket read failed") self.__logger.debug("Read chunk size: %s" % len(chunk)) if chunk == '': self.__logger.error("error while reading from socket") raise SocketReadException("Socket read failed") self.__data_bytes = self.__data_bytes + chunk bytes_read = bytes_read + len(chunk)
def read(self, size): """Read data from connection""" if not self.__sock: InvalidSocketException("Socket is not created") self.__sock.get_data_from_buff(size)
def write(self, data): """Write data on connection""" if not self.__sock: InvalidSocketException("Socket is not created") self.__sock.put_data_in_buff(data)