Scheck
Previous Topic  Next Topic 

Synopsis:

       flag=Scheck(socket,rd_wr_err)


Arguments:

       socket - Socet handle

       rd_wr_err - Specifies whether to check for read, write or error (0,1 or 2) on the socket


Description:  This function allows a socket handle to be checked to see if it is ready to be read from, written to or has an error condition.      The d_wr_err argument should be set to one of the values:  0, 1 or 2 to check for read, write or error repsectively.        The Scheck() function will return 1 if the specified condition has been found, otherwise the function will return 0.


This function is usually used to poll a socket to check that the socket has reached a certain state before continuing to carry out an operation on the socket.    


For example,  after a call to Sconnect() the socket can be polled by checking for write capability which will indicate that the socket has successfully connected to the far end, or otherwise the socket can be checked for error:


       socket=Sconnect("google.com",80);


         // Loop waiting for socket connection or error

       while(1)

               const CHK_WRITE=1;

               const CHK_ERROR=2;

               if(Scheck(socket,CHK_WRITE))

                       applog("Socket connected..");

                       break;

               else if(Scheck(socket,CHK_ERROR)

                       errlog("Error connecting to google.com");

                       stop;

               endif endif


               // Prevent tight loop to allow windows messages to be processed

               sleep(1);

       endwhile



Also after a listening socket has been created by Slisten() the socket can be polled for read capability which will indicate that an inbound connection request has been received.


Returns:   Returns 1 if the specified condition (read, write or error) has been met on the given socket,  otherwise returns 0.     A negative error code is returned if an invalid socket is given.