logo
down
shadow

in socket programming, can accept() the same listening socket in multi-process(thread)?


in socket programming, can accept() the same listening socket in multi-process(thread)?

By : leesin
Date : January 10 2021, 01:57 PM
With these it helps In general, it's not a good idea to have multiple threads performing IO on the same socket without some kind of synchronization between them. In your scenario, it's possible you'd see something like:
incoming connection request wakes up epoll_wait in all N child threads all N threads call accept, 1 call succeeds, N-1 block (or fail, if your listening socket is non-blocking)
code :


Share : facebook icon twitter icon
Accept connection on a Listening socket on the Listening socket (and no longer listen)?

Accept connection on a Listening socket on the Listening socket (and no longer listen)?


By : user3661297
Date : March 29 2020, 07:55 AM
This might help you One-time listening sockets are not that unusual. The FTP protocol uses them, for instance. Simply create a new listening socket on the desired port (or let the socket decide its own port that you can then retrieve), set its backlog to 1, then call accept() on it just once and close it. If accept() accepts a client connection, it returns a new socket handle that you use to communicate with that client. You don't need to keep the listening socket alive during that time.
I don't know what the ICS equivilent of that operation would be, but in Indy there is a TIdSimpleServer component for exactly this purpose (incidentally, Skype on Windows uses Indy).
Is the new connected socket returned by accept() always bound to the same port as the listening socket?

Is the new connected socket returned by accept() always bound to the same port as the listening socket?


By : Diego
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , When you are listening, all connections will have the same port in the accept end of the connection (that is what is used as an identifier initially in order to establish the connection).
The local port number for the connecting part if not defined with a bind() can be anything. For the localhost device, the numbers can probably be recycled very fast on some OS, since there is no real need for lingering state of the TCP.
Cannot close listening socket to abort accept()/select() from a separate thread

Cannot close listening socket to abort accept()/select() from a separate thread


By : bmroyal
Date : March 29 2020, 07:55 AM
seems to work fine close() won't do what you want in the multithreaded case. Use one of the other mechanisms you describe instead.
In the single-threaded case, control returns to the select(), which is restarted and notices EBADF on the now-dismissed file descriptor. (This is highly dangerous, of course, because fd #3 might be recycled by any other thread, or even a complex signal handler, at any time, though your toy program appears safe.) In the multi-threaded case, close() just doesn't wake up your select()ing thread.
Best approach to non blocking server/listening socket in a multi-thread application on Windows?

Best approach to non blocking server/listening socket in a multi-thread application on Windows?


By : Lucas Rego
Date : March 29 2020, 07:55 AM
I wish this help you As Gary says, I/O Completion Ports are the most efficient way to manage multiple network connections in a non-blocking/async manner on Windows platforms.
With IOCP you get notified when your networking operations complete and you can process these completions with a small number of threads. You get to decide how many threads you allocate to process the completions and the kernel decides when to use the threads that you're providing. It uses them in a LIFO order, to reduce context switching, so that if you are only using the minimal number of threads required at any point and you're reusing the same threads rather than cycling through all of the threads that you have available for use.
Are socket options inherited across accept() from the listening socket?

Are socket options inherited across accept() from the listening socket?


By : Anubhav
Date : March 29 2020, 07:55 AM
will help you Several of the socket options are handled at lower levels of the system. While most of the socket options could be set using the setsockopt. Reference:man setsockopt And since you are mentioning only POSIX on any Linux, in general, as your scope. The accept() (Reference: man accept) does have a certain amount of discretion on what socket options should be inherited and what options to reject from the listening fd.
accept() does not modify the original socket passed to it as argument. The new socket returned by accept() does not inherit file status flags such as O_NONBLOCK,O_ASYNC from the listening socket.
Related Posts Related Posts :
shadow
Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk