I have some questions about C++ socket programming. please help to dig deep, and help to correct, if the way I asked is wrong.
- Are there one file descriptor per each port in OS level.
- How do multiple ports use same network interface? is it switching like
threads in processor? so, if number of using ports increase, can it be
delayed data for specific port? - What happens in OS level when creates a socket? does is create any reference to IO file descriptors?
- Then what happens in OS level when calls bind(). how it interconnect socket and NIC address?
- What happens when use reusable socket? How multiple sockets bind to one port? do those switching on one port like threads?
- when sending or receiving without bind() to specific address or port?
How and what is the logic OS select a address and a port.
No. If you’re a server accepting connections on a listening socket you might have 10,000 file descriptors all referring to the same local port number.
Too complex to answer here.
They are very similar things, in some operating systems they are even the same thing. One refers to a socket, the other refers to an open file.
A port and IP address are allocated to the socket. The IP address can be 0.0.0.0. If the specified port was zero, the system chooses one for you from the free ports.
See above.
There is no such thing as a ‘reusable socket’. Are you talking about reusing the port?
A
bind()is executed behind the scenes if you haven’t already executed one yourself. So the same rules apply forbind()as above.