Making server exit gracefully.

git-svn-id: https://tftpy.svn.sourceforge.net/svnroot/tftpy/trunk@47 63283fd4-ec1e-0410-9879-cb7f675518da
master
msoulier 2006-12-15 23:35:48 +00:00
parent 16ebbf2d16
commit f79a1e9828
2 changed files with 7 additions and 3 deletions

View File

@ -42,7 +42,10 @@ def main():
tftpy.setLogLevel(logging.INFO)
server = tftpy.TftpServer(options.root)
server.listen(options.ip, options.port)
try:
server.listen(options.ip, options.port)
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()

View File

@ -285,7 +285,7 @@ DATA | 03 | Block # | Data |
"""Encode the DAT packet. This method populates self.buffer, and
returns self for easy method chaining."""
if len(self.data) == 0:
logger.warning("Encoding an empty DAT packet")
logger.debug("Encoding an empty DAT packet")
format = "!HH%ds" % len(self.data)
self.buffer = struct.pack(format,
self.opcode,
@ -570,7 +570,8 @@ class TftpServer(TftpSession):
tftp_factory = TftpPacketFactory()
logger.info("Server requested on ip %s, port %s" % (listenip, listenport))
logger.info("Server requested on ip %s, port %s"
% (listenip if listenip else '0.0.0.0', listenport))
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.bind((listenip, listenport))