sockets dup()ed to stdin and stdout of a process

sockets dup()ed to stdin and stdout of a process

Post by jay du » Thu, 25 Apr 1991 04:01:20



   I am posting this for a friend of mine who doesn't have access

   Is it possible to use dup() to assign a socket to be the input
*and* the output of a process? I did this (to a process which uses the
stdio functions like gets(), etc.), in the hopes of then using
select() in another program to know when this process wants to read
and when it wants to write. The reading works fine, especially when
the other process does no input. If the other process does read()s, it
works also. But if it uses gets(), it doesn't work (it hangs, etc.).
select() also thinks the connection is writable, even though the stuff
that the other process printf()ed before it issued the gets() hasn't
been seen on the other end yet. My question is: what am I missing?
What should I know about the stdio functions when they've been dup()ed
to a socket? What is the right way to write EOF to such a process?
Will this work, in general, or do I need two separate sockets, one for
input and one for output?  Any help will be greatly appreciated.


 
 
 

1. dup'd socket to stdin, problem...

I have a(n apparantly obscure) problem with sockets.

---- What I am doing, in outline ------------------------------------------

bind ( main_sock, (struct sockaddr*) &server, sizeof (struct sockaddr_in))
listen ( main_sock, 10 )

while ( 1 )
{
   request_socket = accept ( main_sock, (struct sockaddr*) &source, &i ) ;
   socketStream   = fdopen ( request_socket, "r+b" );

   fgets ( request, BUFSIZ, socketStream );
   fscanf ( socketStream, "%20s", &j );

   i = fileno ( socketStream );
   dup2   ( i, 0 );
   dup2   ( i, 1 );
   close  ( request_socket );
   fclose ( socketStream );

   if ( fork () == 0 )
      execl ( fullFilename, file + (*file == '/'), (char*)0 );
----------------------------------------------------------------------------
The fork'd child process will not read from stdin.  I fdopen the socket
because I want to use formated io.

Prior to having the i=fileno, and dup'ing from i, I dup'ed the request_socket.
When I put in the 'i' line, it worked for the afternoon.   That evening, it
no longer worked.  Is there anything I should be aware of that I obviously
am not :)  I am absolutely certain I changed nothing that could possibly impact
on io.

I know about having to seek after a write to avoiid undefined results, so I
tried seeking the socketSream (which seems stupid thing to do) and nothing
happened.

Thanks in advance,

Mark.

2. signal 11 when switching VC

3. shutdown() for dup'ed socket

4. top for normal users ?

5. Redirecting stdout/stdin to socket

6. password rules

7. Controlling forked processes stdin/stdout

8. Q: How to NFS-export local cdrom

9. Using separate window child process for stdin/stdout

10. HOW TO RE-DIRECT THE STDIN/STDOUT FOR A PROCESS RUNNING IN THE BACKGROUND

11. redirecting stdin & stdout of a running process

12. Managing stdin and stdout of new processes

13. Taking over a child process's stdin/stdout