tcp-getoptions 597 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env lua
  2. require"socket"
  3. port = 8765
  4. function options(o)
  5. print("options for", o)
  6. for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do
  7. print("getoption", opt, o:getoption(opt))
  8. end
  9. print("getoption", "linger",
  10. "on", o:getoption("linger").on,
  11. "timeout", o:getoption("linger").timeout)
  12. end
  13. local m = socket.tcp()
  14. options(m)
  15. assert(m:bind("*", port))
  16. assert(m:listen())
  17. options(m)
  18. m:close()
  19. local m = socket.bind("*", port)
  20. options(m)
  21. local c = socket.connect("localhost", port)
  22. options(c)
  23. local s = m:accept()
  24. options(s)