Close sideband socket if there's a trigger #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We now have an extra parameter that tells whether to close the sideband socket or not.
As accept, is a blocking call, we can't just check the variable for the trigger, as it will remain blocked until a connection is established.
Hence, I've updated it to use select. The select function monitors multiple file descriptors to see if any of them are ready.
It returns the number of file descriptors that are ready for the requested I/O, or -1 if an error occurs.
If it's greater than 0, it means that one or more file descriptors are ready for reading. The code then checks if the sockfd file descriptor is ready using the FD_ISSET macro. If sockfd is ready, it indicates that there is an incoming connection and we do the remaining operation accordingly.
Tested it, when the boolean is set to true, the loop breaks and the socket closes.