Help with C programming

for a question like this

Assume you have a server with two clients and two child processes. The server retrieves data from the
children through a pipe (one each) and writes data to the clients through a socket (one each). child1
produces data for client1, and child2 for client2.
Write a C loop that performs the above actions, making sure that at no time will the server sit and wait
for data from one child when the other child has data to pass. If either child dies, exit the loop.
You need to write only the loop transferring the data. Assume that all connections to pipes and sockets
have been established, and no more clients will try to connect to this server.
The pipes are declared in arrays p1 and p2, respectively. The sockets are s1, and s2.
You may use this function (you do not have to write it):
int transfer(int p, int s)
which gets data from pipe p and puts it into socket s, and returns the number of bytes read from the pipe.
is this correct?

while(1) {
    rset = allset;
    nready = select(maxfd+1, &rset, NULL, NULL, NULL);
    if (nready < 0) {
        perror("ERROR select error");
    }
    else if (FD_ISSET(p1[0], &rset)) {
        if ((bytes = transfer(p1[0], s1)) < 0) {
            perror("ERROR read error");
        }
        else if (bytes==0) {
            break;
        }
    }
    else if (FD_ISSET(p2[0], &rset)) {
        if ((bytes = transfer(p2[0], s2)) < 0) {
            perror("ERROR read error");
        }
        else if (bytes==0) {
            break;
        }
    }
}

Post your complete code. You're using all sorts of things which aren't defined in the snippet you posted.

For this question, this code isn't from a program, i am just assuming the other parts are there, i just want to get the loop right. So just assume the rest is there. The question says just to write the loop part. By the way you did read the question right?

Just noticed something:

I'm not helping you with your homework. And now I'm forced to suspect that everything you've posted so far is homework. It'd explain your bizzare reluctance to post all your code -- maybe it's not all yours.

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.