Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone suggest me how can i stop accept method for accepting connection .i need to stop accept because i want to execute my callback function in between.
Posted

1 solution

Very strange question.
You can close the socket of course then you don't have your server listening anymore either.
You can specify in listen that you want to service only 1 connection like this
listen(sock,1).
Other than that I think your application is written entirely wrong because it should not be a problem to execute your callback before returning your processing to accept. Because normally you do something like this :

while(1){
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
execute your callback
}

while your callback is executing you cannot accept a new connection.
You should keep the code of your callback as small as possible.
TCP applications are actually meant to handle multiple connections at a time, which makes them quite complicated. Either you end up using select on multiple sockets or using several threads.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900