Reputation: 2053
How can I send accepted socket to a function as argument here is the code:
//accept connection
accept_sock = accept(sock_con,(struct sockaddr *)&info,&sizeof_accept);
//Create a new process
int pid = fork();
if (pid == 0)
{
//close the socket
close(sock_con);
request_handle(accept_sock); ** here i wanna send the socket to that function*
}
What is the datatype of that socket when declaring this function?
function request_handle(what is the datatype pointed here){
}
Upvotes: 0
Views: 183
Reputation: 394099
The socket is a handle usually an int
or unsigned int
(depends on implementation), this will be used by the socket dll to uniquely identify the socket you are referring to when you pass this as an argument to send
recv
etc..
So you just need to do this:
function request_handle(int socketHandle){
}
Upvotes: 0
Reputation: 3082
function request_handle(int socket);
Sockets file descriptors are integers associated with the socket that was opened in the kernel to distinguish between each socket, just like file descriptors are integers to distinguish between opened files and get the appropriate one, some says everything in a Unix is a file, that's because of the integer associated or the file descriptor concept.
Upvotes: 0