Fixing issue #9, removing blksize option from client if not supplied.
parent
a43773e26c
commit
949c998648
|
@ -25,8 +25,7 @@ def main():
|
|||
help='filename to upload')
|
||||
parser.add_option('-b',
|
||||
'--blksize',
|
||||
help='udp packet size to use (default: 512)',
|
||||
default=512)
|
||||
help='udp packet size to use (default: 512)')
|
||||
parser.add_option('-o',
|
||||
'--output',
|
||||
help='output file, - for stdout (default: same as download)')
|
||||
|
|
|
@ -19,15 +19,11 @@ class TftpClient(TftpSession):
|
|||
self.iport = port
|
||||
self.filename = None
|
||||
self.options = options
|
||||
# FIXME: If the blksize is DEF_BLKSIZE, we should just skip sending
|
||||
# it.
|
||||
if self.options.has_key('blksize'):
|
||||
size = self.options['blksize']
|
||||
tftpassert(types.IntType == type(size), "blksize must be an int")
|
||||
if size < MIN_BLKSIZE or size > MAX_BLKSIZE:
|
||||
raise TftpException, "Invalid blksize: %d" % size
|
||||
else:
|
||||
self.options['blksize'] = DEF_BLKSIZE
|
||||
|
||||
def download(self, filename, output, packethook=None, timeout=SOCK_TIMEOUT):
|
||||
"""This method initiates a tftp download from the configured remote
|
||||
|
|
|
@ -98,6 +98,10 @@ class TftpContext(object):
|
|||
# Count the number of retry attempts.
|
||||
self.retry_count = 0
|
||||
|
||||
def getBlocksize(self):
|
||||
"""Fetch the current blocksize for this session."""
|
||||
return int(self.options.get('blksize', 512))
|
||||
|
||||
def __del__(self):
|
||||
"""Simple destructor to try to call housekeeping in the end method if
|
||||
not called explicitely. Leaking file descriptors is not a good
|
||||
|
@ -506,7 +510,7 @@ class TftpState(object):
|
|||
self.context.metrics.resent_bytes += len(dat.data)
|
||||
self.context.metrics.add_dup(dat)
|
||||
else:
|
||||
blksize = int(self.context.options['blksize'])
|
||||
blksize = self.context.getBlocksize()
|
||||
buffer = self.context.fileobj.read(blksize)
|
||||
log.debug("Read %d bytes into buffer" % len(buffer))
|
||||
if len(buffer) < blksize:
|
||||
|
@ -590,7 +594,7 @@ class TftpState(object):
|
|||
self.context.fileobj.write(pkt.data)
|
||||
self.context.metrics.bytes += len(pkt.data)
|
||||
# Check for end-of-file, any less than full data packet.
|
||||
if len(pkt.data) < int(self.context.options['blksize']):
|
||||
if len(pkt.data) < self.context.getBlocksize():
|
||||
log.info("End of file detected")
|
||||
return None
|
||||
|
||||
|
|
Reference in New Issue