tags:

views:

44

answers:

1

how do i change the socket id/FD after i use accept() ? lets say i bind() on sockfd 3 and the accepted client is on sockfd 4, how do i change/move that sockfd to 1000?

OS : Ubuntu

+1  A: 

Still you didn't specify the OS so I will go with *nix :)

http://linux.die.net/man/2/dup2

tyranid
that helps alot, but next - how do i release the resources associated with the original FD without closing the connection - usually close() ? or dup2() makes it always automatically?
tenev
Hi, i just tested dup2(), works perfectly for what i needed!
tenev
here is something very basic of what i did: //my acceptsock=accpet(); if(check is admin ip) { int oldsock=acceptsock; //copy from receiving sockfd (accept-lowest free) to custom sockfd acceptsock=dup2(oldsock,800+serverconnections); //add acceptsock to my fd_set in the thread where admin data //is processed //release the resources of the accept() sockfd //close - does not not close the connection! perfect! close(oldsock); } else { //normal client connection } i can now easily distinguish types of clients :)
tenev