/* This file is part of Lcrzo.
*/

/*-------------------------------------------------------------*/
int lcrzo_priv_wait_ipc_wait(lcrzo_ipc *pipc, 
			     lcrzo_time *pmaxwaitingtime, 
			     lcrzo_bool *pevent)
#if defined LCRZODEF_SYSTEM_Unix
{ if (pipc->side!=0&&pipc->side!=1) return(LCRZO_ERR_LOIPCSIDENOTSET);
  return(lcrzo_priv_wait_fd_wait(pipc->readpipe[pipc->side], 
				 pmaxwaitingtime, pevent));
}
#elif defined LCRZODEF_SYSTEM_Windows
{ DWORD readbytes, bytesavail;
  BOOL err;
  lcrzo_bool event;

  if (pipc->side!=0&&pipc->side!=1) return(LCRZO_ERR_LOIPCSIDENOTSET);

  err=PeekNamedPipe(pipc->readhandle[pipc->side], 
		    NULL, 0xFFFF, &readbytes, &bytesavail, NULL);
  if (!err)
  { pipc->dataend=LCRZO_TRUE;
    if (pevent!=NULL) *pevent=LCRZO_TRUE;
    return(LCRZO_ERR_OK);
  }

  if ( readbytes || bytesavail ) event=LCRZO_TRUE;
  else event=LCRZO_FALSE;

  if (pevent!=NULL) *pevent=event;
  return(LCRZO_ERR_OK);
  /* just for the compiler warning */
  pmaxwaitingtime=pmaxwaitingtime;
}
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

