A semantic search engine for source code https://bitshift.benkurtovic.com/
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

37 rindas
862 B

  1. require 'socket'
  2. require File.expand_path('../parser.rb', __FILE__)
  3. def pack_int(i)
  4. bytes = []; mask = 255
  5. while bytes.length < 4
  6. bytes.unshift (i & mask)
  7. i = i >> 8
  8. end
  9. return bytes.pack('cccc')
  10. end
  11. def start_server
  12. server = TCPServer.new 5003
  13. loop do
  14. # Start a new thread for each client accepted
  15. Thread.start(server.accept) do |client|
  16. begin
  17. # Get the amount of data to be read
  18. size = (client.readline).to_i
  19. p = Bitshift::Parser.new client.read(size)
  20. # Get the parsed result
  21. symbols = p.parse
  22. client.puts pack_int(symbols.length)
  23. client.puts symbols
  24. ensure
  25. # Close the socket
  26. client.close
  27. end
  28. end
  29. end
  30. end