TutSocketCheck


Name

TutSocketCheck — check if data can be read from or written to a socket

Synopsis

T_BOOL TutSocketCheck(socket_fd, check_mode, timeout) 
T_INT4 socket_fd; 
T_IO_CHECK_MODE check_mode; 
T_REAL8 timeout; 

Arguments

socket_fd — socket file descriptor to check

check_mode — how to check the socket availability

timeout — maximum number of seconds to wait for availability

Return Values

TRUE if data can be read/written, FALSE if timeout reached or error occurred.

Diagnostics

If TutSocketCheck fails, it returns FALSE and sets the global SmartSockets error number to one of:

Description

TutSocketCheck is a convenience function that provides a simplified interface to the select function. If check_mode is T_IO_CHECK_READ, then TutSocketCheck checks if data is available to be read from the socket. If check_mode is T_IO_CHECK_WRITE, then TutSocketCheck checks if data can be written to the socket without blocking. TutSocketCheck returns TRUE if the socket is available and FALSE otherwise. The timeout controls how long TutSocketCheck waits for availability. To wait indefinitely, use the constant T_TIMEOUT_FOREVER for the timeout. To poll the socket without blocking, use a timeout of 0.

Server sockets may use TutSocketCheck to check if a client has connected.

Caution

None

See Also

TutSocketRecvTimeout

Examples

This example uses TutSocketCheck to wait for up to 10 seconds for a new client to connect to a server socket, then accepts the new client with TutSocketAccept:

if (!TutSocketCheck(server_fd, T_IO_CHECK_READ, 10.0)) { 
  /* error */ 
}  
else { 
  client_fd = TutSocketAccept(server_fd); 
  if (client_fd == -1) { 
    /* error */ 
  }  
}  

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com