I believe, Webserver like Apache uses socket programming only. In TCP connections, we need to call listen(sock_fd, number_of_backlogs); This backlog has a limit, generally in two digits. I am wondering how come a Apache webserver can establish millions of connections to their site. How listen() works there?
number_of_backlogs is not the number of total connections, but the maximum number of connections the OS kernel will establish before the user space process takes control of these connections by calling accept.
listen defines a kind of bucket, where new connections are put into by the OS. If the bucket is full (e.g. depending on the arguments to listen) new connections will be rejected. With accept() the user space application (e.g. web server, mail server...) will take one connection out of the bucket and handle it. These leaves the accepted connection open but makes place in the bucket for another connection. Thus a web server can handle 1000s of connections even if the bucket has only room for 50. In effect the number_of_backlogs defines only how often the user space process has to look into the bucket for new connections, e.g. the more connections come in within a time the more often it should look and take connections out of the bucket or the bigger the bucket should be.