TipcEventCreateSocket


Name

TipcEventCreateSocket — create a socket event

Synopsis

T_IPC_EVENT TipcEventCreatSocket(dispatcher, socket, check_mode, event_func, 
event_arg) 
T_IPC_DISPATCHER dispatcher; 
T_INT4 socket; 
T_IO_CHECK_MODE check_mode; 
T_IPC_EVENT_FUNC event_func; 
T_PTR event_arg; 

Arguments

dispatcher — the dispatcher on which to invoke the event

socket — the socket to wait for availability on

check_mode — the type of availability to wait on: T_IO_CHECK_READ or T_IO_CHECK_WRITE

event_func — the function to be invoked

event_arg — an optional argument to pass to the event_func

Return Values

A new event if successful, NULL otherwise.

Diagnostics

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

Description

TipcEventCreateSocket creates a socket event of type T_IPC_EVENT_SOCKET to be invoked when socket is available for reading or writing, depending on the value of check_mode.

Caution

When an event is created or destroyed from a thread other than the thread dispatching the events, a user event is added to the dispatcher to perform the actual creation or destruction. To ensure that event data, such as a socket or a connection, is not destroyed before the event is removed from the dispatcher, create a user event to destroy the event and to perform any necessary cleanup. See the example for TipcEventCreate.

See Also

TipcEventGetType, TipcEventGetCheckMode, TipcEventGetSocket

Examples

This example creates a socket event:

void T_ENTRY socketFunc(T_IPC_EVENT event, T_IPC_EVENT_DATA data, 
                        T_PTR arg) 
{ 
  T_IO_CHECK_MODE check_mode; 
  T_INT4 socket; 
 
  if (!TipcEventGetCheckMode(event, &check_mode)) { 
    return;  /* error */ 
  } 
 
  if (!TipcEventGetSocket(event, &socket)) { 
    return;  /* error */ 
  } 
 
  if (check_mode == T_IO_CHECK_READ) { 
    read(socket); 
  } 
  else if (check_mode == T_IO_CHECK_WRITE) { 
    write(socket); 
  } 
} 
 
/* =========================================================== */ 
/*...code from main program is below */ 
 
read_event = TipcEventCreateSocket(dispatcher, socket, 
T_IO_CHECK_READ, 
                                   socketFunc, T_NULL); 
if (read_event == NULL) { 
  return;  /* error */ 
} 
 
write_event = TipcEventCreateSocket(dispatcher, socket, 
                                   T_IO_CHECK_WRITE, socketFunc, 
T_NULL); 
if (write_event == NULL) { 
  return;  /* error */ 
} 

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