File: find-connect-limit

package info (click to toggle)
luasocket 3.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,264 kB
  • sloc: ansic: 4,845; makefile: 337; sh: 116
file content (32 lines) | stat: -rwxr-xr-x 582 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env lua
--[[
Find out how many TCP connections we can make.

Use ulimit to increase the max number of descriptors:

ulimit -n 10000
ulimit -n

You'll probably need to be root to do this.
]]

socket = require "socket"

host = arg[1] or "google.com"
port = arg[2] or 80

connections = {}

repeat
	c = assert(socket.connect(hostip or host, 80))
	table.insert(connections, c)

        if not hostip then
            hostip = c:getpeername()
            print("resolved", host, "to", hostip)
        end

	print("connection #", #connections, c, "fd", c:getfd())

until false