|
-
March 29th, 1999, 06:57 AM
#1
Implementing non-blocking sockets
Hi Friends,
By default member functions( e.g. Connect(), Receive() ) of CSocket class operate in blocking mode, how do I change it to non-blocking mode.
Also is there any way I can specify timeout value for such type of functions, especially Receive() function ??
Regards,
Navin.
-
March 29th, 1999, 09:47 AM
#2
Re: Implementing non-blocking sockets
To make it non-blocking, use CAsyncSocket instead. CSocket is derived from CAsyncSocket, and what it adds is the blocking code.
-
March 29th, 1999, 10:54 AM
#3
Re: Implementing non-blocking sockets
Dear navin,
use a derived class from CSocket and try, a sample can be like this
class NavinSocekt: ublic CSocket
{
public:
NavinSocket();
~NavinSocket();
/*all these function are the local implementation of the virtuall callback functions
provided in the CAsyncSocket*/
void OnReceive(int nErrorCode); //this function willbe called when paket arrives
void OnSend(int nErrorCode); // will be called when a packet is sent
void OnConnect(int nErrorCode); // will be called when gets connected
void OnAccept(int nErrorCode); // will be called when accepted
void OnError(int nErrorCode); // will be calle dwhen erro happpends
void OnClose(int nErrorCode); //
}
// all the virtual call back function should be locally implemented depending on your need
void NavinSocekt::OnReceive(int nErrorCode)
{
/*will be called when a packet arrives*/
if(nErrorCode)
printf("error in on receive of NAvin socket" ;
char buffer[max_size];
/* this function call won't be a blocking call*/
int recdBytes = receive(buffer,max_size,.....);
/*received packet is available at buffer*/
return;
}
with this you don't have to poll for the packet arrival, instead it will call back your virtual functions
whenevera packet is arrived.
hope this will solv your issue.
thanks
bsmanoj
-
April 20th, 1999, 10:46 AM
#4
Re: Implementing non-blocking sockets
this makes the socket non-blocking
or else AsyncSocket will do....
ioctl (Socket, FIONBIO, &action);
-
May 23rd, 1999, 04:32 PM
#5
Re: Implementing non-blocking sockets
see Timeout with MFC sockets here
-
May 23rd, 1999, 04:54 PM
#6
Re: Implementing non-blocking sockets
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|