Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy we cannot accept() a socket on some process and recv() data from its child?
    primarykey
    data
    text
    <p>I'm trying to implement a simple web server on Linux that connects to the client (the browser) ,receives some requests from the client (e.g GET), and then sends back the response with desired file. I am using a socket communication. I want to create a pool of worker processes (children) at server startup whose job is to deal with the incoming requests. The parent process has to <code>accept()</code> the incoming request and sends their file-desciptor to one of the worker processes to deal with it and sends the response to the client with the requested file.</p> <p>The problem that I have faced is that when I <code>accept()</code> the request and send it to the worker process, <code>recv()</code> or <code>read()</code> functions return <code>-1</code> which means an error occurs:</p> <blockquote> <p>Socket operation on non-socket</p> </blockquote> <p>But when I try to use <code>recv()</code> or <code>read()</code> functions at the parent process, they work very well and return the number of received bytes.</p> <p>How can I solve this issue?</p> <p><sup> PS: I am using the shared memory to pass the file-desciptor from the parent process to the worker process (the child process), and I am using semaphores to manage which worker process will handle the request</sup></p> <hr> <p><strong>EDIT:</strong></p> <p>Actually, it's a project assignment and one of the specification is to send the file-descriptor via the shared memory. However, can I send a pointer of the file-descriptor?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload