/tutorial/storable/example3/repository_connection.e

http://github.com/tybor/Liberty · Specman e · 55 lines · 44 code · 7 blank · 4 comment · 2 complexity · 447942ec321cbb0c1e5937c8f125db53 MD5 · raw file

  1. class REPOSITORY_CONNECTION
  2. --
  3. -- Handle one connection to the REPOSITORY_SERVER.
  4. --
  5. inherit
  6. CONNECTION
  7. redefine
  8. set_io
  9. end
  10. create {REPOSITORY_SERVER}
  11. make
  12. feature {LOOP_ITEM}
  13. continue is
  14. do
  15. server.update_from_stream(ios)
  16. if not ios.is_connected then
  17. if ios.error /= Void then
  18. std_error.put_line(ios.error)
  19. end
  20. std_error.put_line(once "Client disconnected")
  21. end
  22. end
  23. feature {SERVER}
  24. set_io (a_io: like ios) is
  25. do
  26. Precursor(a_io)
  27. a_io.when_disconnect(agent handle_disconnect)
  28. -- Start by sending the repository
  29. std_error.put_line(once "Sending repository")
  30. server.write_to_stream(a_io)
  31. a_io.flush
  32. std_error.put_line(once "Repository sent")
  33. end
  34. feature {}
  35. server: REPOSITORY_SERVER
  36. handle_disconnect (a_io: like ios) is
  37. require
  38. a_io = ios
  39. done
  40. do
  41. server.connection_done(Current)
  42. end
  43. make (a_server: like server) is
  44. do
  45. std_error.put_line(once "New connection")
  46. server := a_server
  47. end
  48. end