git-svn-id: http://svn.code.sf.net/p/netboot65/code@20 93682198-c243-4bdb-bd91-e943c89aac3b

This commit is contained in:
jonnosan 2009-01-23 10:54:06 +00:00
parent e1dd101b7a
commit cb09f0e4fd
2 changed files with 15 additions and 11 deletions

View File

@ -11,14 +11,17 @@ def log_msg(msg)
puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} #{msg}"
end
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
require 'netboot65_tftp'
lib_path=File.expand_path(File.dirname(__FILE__)+'/../lib')
$:.unshift(lib_path) unless $:.include?(lib_path)
require 'tftp_server'
require 'tndp_server'
bootfile_dir=File.expand_path(File.dirname(__FILE__)+"//..//boot")
bootfile_dir=File.expand_path(File.dirname(__FILE__)+'/../boot')
tftp_server=Netboot65TFTPServer.new(bootfile_dir)
tftp_server.start
tndp_server=TNDPServer.new(File.dirname(__FILE__)+"/../test_images")
tndp_server.start
begin
loop do
sleep(1) #wake up every second to get keyboard input, so we break on ^C
@ -27,4 +30,5 @@ rescue Interrupt
log_msg "got interrupt signal - shutting down"
end
tftp_server.shutdown
tndp_server.shutdown
log_msg "shut down complete."

View File

@ -27,15 +27,15 @@ class TNDPServer
@server_thread=Thread.start do
@socket=UDPSocket.open
@socket.bind("",port)
log("serving #{root_directory} on UDP port #{port}")
log_msg("serving #{root_directory} on UDP port #{port}")
loop do
data,addr_info=@socket.recvfrom(4096)
client_port=addr_info[1]
client_ip=addr_info[3]
log "#{data.length} bytes received from #{client_ip}:#{client_port}"
log_msg "#{data.length} bytes received from #{client_ip}:#{client_port}"
begin
request=TNDP.message_from_buffer(data)
log(request.to_s)
log_msg(request.to_s)
case request.opcode
when TNDP::CapabilitiesRequestMessage::OPCODE
supported_architectures={}
@ -60,15 +60,15 @@ class TNDPServer
rescue Exception=>e
response=TNDP::ErrorResponseMessage.create_error_response(data,TNDP::ErrorCodes::INTERNAL_SERVER_ERROR,e.to_s)
end
log("Response:")
log(response.to_s)
log_msg("Response:")
log_msg(response.to_s)
@socket.send(response.to_buffer,0,client_ip,client_port)
end
end
end
def shutdown
log("TNDP server on UDP port #{port} shutting down")
log_msg("TNDP server on UDP port #{port} shutting down")
@server_thread.kill
end