I am trying to implement a simple web server in Linux that connects to a client (browser), receives some requests from the client (e.g. GET), and then sends a response with the desired file. I am using a socket connection. I want to create a pool of workflows (children) when starting a server whose task is to process incoming requests. The parent process needs an accept()incoming request and sends its file descriptor to one of the work processes to process it and sends a response to the client with the requested file.
The problem that I encountered is that when I accept()request and sends it to the workflow, the functions recv()either read()return -1, which means an error has occurred:
Socket operation on a non-socket
But when I try to use functions recv()or read()in the parent process, they work very well and return the number of bytes received.
How can I solve this problem?
PS: I use shared memory to transfer the descriptor file from the parent process to the workflow (child process), and I use semaphores to control which workflow will process the request
EDIT:
Actually, this is the purpose of the project, and one of the specifications is to send the file descriptor through shared memory. However, can I send a file descriptor pointer?