mirror of
https://github.com/balkian/SWCM.git
synced 2024-11-22 04:32:29 +00:00
Displays number of threads in use
This commit is contained in:
parent
ad903e0124
commit
a98bedad40
@ -1,7 +1,15 @@
|
||||
require 'socket'
|
||||
|
||||
numCon = 0
|
||||
maxCon = 10
|
||||
maxCon=10
|
||||
port = 8080
|
||||
if(ARGV.length>0)
|
||||
port = ARGV[0].to_i #Extrae el puerto del primer argumento
|
||||
end
|
||||
if(ARGV.length>1)
|
||||
if((c=ARGV[1].to_i)>0) then maxCon=c end #Cambia las conexiones si es
|
||||
#un número mayor que cero
|
||||
end
|
||||
|
||||
def respond(socket, code, body) # Genera respuestas
|
||||
socket.puts "HTTP/1.0 #{ code }"
|
||||
@ -13,16 +21,17 @@ def respond(socket, code, body) # Genera respuestas
|
||||
end
|
||||
|
||||
server = TCPServer.open(8080)
|
||||
puts "web server created at port 8080"
|
||||
puts "web server created at port #{ port } and #{ maxCon } connection"
|
||||
loop do
|
||||
if(numCon < maxCon) # Si no se ha superado el número máximo de hebras
|
||||
puts "#{ numCon } threads running!"
|
||||
sock = server.accept # Acepta conexión del cliente
|
||||
t = Thread.new(sock) do |socket|
|
||||
numCon=numCon+1
|
||||
request = socket.gets # Lee la primera línea
|
||||
o = socket.gets until ( o != "") # cabecera acaba con línea vacía
|
||||
|
||||
unless request =~ /^GET/ # Si el comando no esta soportado
|
||||
unless request =~ /^GET/ # Si el comando no está soportado
|
||||
respond socket, "400 Bad Request", "<html><body><h1>Comando desconocido</h1></body></html>"
|
||||
next # Acaba el ciclo
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user