winsock and dup() dup2() 
Author Message
 winsock and dup() dup2()

It's sometimes handy to use dup2 with BSD sockets.

For example if I've got an application that is waiting for data to come
across on a socket I would call select on the file descriptor associated
with that socket.

There may however be times be times when I want that application to wait
on one of two sockets but for some reason the application is only
allowed to know about a single file descriptor.

What I would do in this situation is use the dup2() function to
associate the file descriptor that the application knows about with the
file descriptor that describes the appropriate socket.  For example say
I have two file descriptors sock1 and sock2.  First I make a duplicate
of the file descriptor on sock1 and make the application aware of it.

app_sock = dup(sock1);

The application does a select on app_sock which will fire when there is
data in the first socket.  Now I want the application to wait until
information is available in the second socket.

dup2(sock2, app_sock).

When the application calls select (on the same file descriptor as
before) it will now fire only when data is available in the second

Is it even remotely possible to do this using winsock?  Since sockets
are represented by integers rather than file descriptors I imagine some
sort of itermediate step is needed.

I'd appreciate any replies via email if someone has experience with


Mon, 29 May 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Dup or Dup2 call in VC++ for socket handle?

2. Dup or Dup2 call in VC++ for socket handle?

3. Dup or Dup2 call in VC++ for socket handle?

4. Winsock Winsock Winsock !!!

5. Winsock OXC vs.Winsock DLL

6. Need urgent help with this (fork, dup, pipes)

7. fork(), pipe(), dup()

8. problem redirecting stdout/stderr using dup2

9. flushing file with dup and close...

10. dup()'ed pipe()'s to stdio

11. Socketpair() and dup2() question

12. DUP Preprocessor Directive


Powered by phpBB® Forum Software