aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2024-01-01 22:26:43 +0100
committerJeremias Stotter <jeremias@stotter.eu>2024-01-01 22:26:43 +0100
commit3cf277161a376bf3257731edcf9981be413d2df2 (patch)
tree63f684c309351a6e9ade0d0354ae44ca754c3512
parentb225dcc82101a4237932b37b93f559cd3cbf0c02 (diff)
downloadnetwork-simulator-3cf277161a376bf3257731edcf9981be413d2df2.tar.gz
network-simulator-3cf277161a376bf3257731edcf9981be413d2df2.tar.bz2
network-simulator-3cf277161a376bf3257731edcf9981be413d2df2.zip
Some http work
-rw-r--r--templates/genericdev/device.lua13
-rw-r--r--templates/tcplib/tcplib.lua21
2 files changed, 20 insertions, 14 deletions
diff --git a/templates/genericdev/device.lua b/templates/genericdev/device.lua
index c5cb6be..9662173 100644
--- a/templates/genericdev/device.lua
+++ b/templates/genericdev/device.lua
@@ -93,7 +93,8 @@ end
htget_socket = nil
-function htget(sock, addr)
+function htget(sock)
+ nsprint("Now trying to send HTTP request on sock no."..sock)
send_tcp(sock, "GET / HTTP/1.1\r\nUser-Agent: htget\r\n\r\n", "http")
htget_socket = sock
end
@@ -166,7 +167,7 @@ function cmdline(cmdline)
nsprint("htget requires a host")
end
sock = socket_tcp(nil, ip_addr[0][0])
- connect_tcp(sock, 80, parse_ip(argt[2]), htget, {sock, parse_ip(argt[2])})
+ connect_tcp(sock, 80, parse_ip(argt[2]), htget, {sock})
end
if(argt[1] == "httpserver") then
@@ -411,9 +412,11 @@ function timestamp()
for k,v in pairs(http_accepted) do
data = read_tcp(v, 65535)
- nsprint("Recvd http request: "..data)
- close_tcp(v)
- table_uninsert(http_accepted, v)
+ if(#data > 0) then
+ nsprint("Recvd http request: "..data)
+ close_tcp(v)
+ table_uninsert(http_accepted, v)
+ end
end
for k,v in pairs(communicating_sockets) do
diff --git a/templates/tcplib/tcplib.lua b/templates/tcplib/tcplib.lua
index 8b9315c..4a1b255 100644
--- a/templates/tcplib/tcplib.lua
+++ b/templates/tcplib/tcplib.lua
@@ -220,6 +220,8 @@ function connect_waiting(r_addr, header_fields, sock, after_connect, after_conne
send_ip(header, tcp_sockets[sock]["r_addr"], tcp_sockets[sock]["addr"], iptypes["tcp"], 0, "tcp")
after_connect(table.unpack(after_connect_vals))
+ tcp_sockets[sock]["recv_func"] = nil
+ tcp_sockets[sock]["recv_func_vals"] = nil
end
-- @todo Value the window field here
@@ -383,15 +385,16 @@ function handle_tcp(interface_index, data, source, dest)
-- Call the handler function
if(tcp_sockets[sock]["recv_func"]) then
- tcp_sockets[sock]["recv_func"](source, {["port_s"] = port_s,
- ["r_port"] = port_s,
- ["seq"] = seq,
- ["ack"] = ack,
- ["header_size"] = header_size,
- ["flags"] = flags,
- ["window"] = window,
- ["cksum"] = cksum,
- ["urg"] = urg}, table.unpack(tcp_sockets[sock]["recv_func_vals"]))
+ tcp_sockets[sock]["recv_func"](source, { ["sock"] = sock,
+ ["port_s"] = port_s,
+ ["r_port"] = port_s,
+ ["seq"] = seq,
+ ["ack"] = ack,
+ ["header_size"] = header_size,
+ ["flags"] = flags,
+ ["window"] = window,
+ ["cksum"] = cksum,
+ ["urg"] = urg}, table.unpack(tcp_sockets[sock]["recv_func_vals"]))
end
--tcp_sockets[sock]["recv_func"] = nil
Jeremias Stotters git repositories generated by CGIT