Network programming noob here,
I'm confused by behavior of accept and connect socket functions. In most programming languages, wrappers of those functions return different types of values: accept returns a new descriptor that we can use to send/receive data, but connect returns nothing(or returns an error code).
To me it looks like connect should also return a descriptor. They both open a channel between two sockets, but only one of the functions return something useful to communicate with the remote socket.
This effects the way I structure my program. For example, I can easily spawn a new worker/thread/etc. for every incoming connection, but it's not easily possible for every connections that I create using connect, because I don't have a new descriptor in this case.(so I can't use recv and send without doing some bookkeeping)
Can anyone explain me why is this working this way?
I think the reason is that because socket wrappers in programming languages follow the BSD API closely and in this case my question is: Why BSD sockets work this way? Current implementation leads to unnecessarily complex programs or redundant sockets. I either need to do more bookkeping(leads to more complex programs) or create a new socket for every out-going connection(leads to redundant sockets).
Thanks.