Beispiel #1
0
void traceEnter(const char * szFunction,const char * szFormat,...)
{
	debugIndent ();

	fprintf(stderr,"[>> %s][at %lu] ",szFunction,getInputLineNumber());

	va_list va;
	va_start(va,szFormat);
	vfprintf(stderr,szFormat,va);
	va_end(va);

	fprintf(stderr,"\n");

	debugInc();
}
int socketNew(BOOL fTCP)
{
  int        iSock;
  int        iType, iProtocol;

  if ( xplMutexLock( hmtxSockets, XPL_INDEFINITE_WAIT ) != XPL_NO_ERROR )
  {
    debug( "xplMutexLock() failed" );
    return -1;
  }

  if ( fTCP )
  {
    iType = SOCK_STREAM;
    iProtocol = IPPROTO_TCP;
  }
  else
  {
    iType = SOCK_DGRAM;
    iProtocol = IPPROTO_UDP;
  }

  iSock = socket( PF_INET, iType, iProtocol );
/*  debug( "socket(PF_INET,%s,%s): %d",
         iType == SOCK_STREAM ? "SOCK_STREAM" : "SOCK_DGRAM",
         iProtocol == IPPROTO_TCP ? "IPPROTO_TCP" : "IPPROTO_UDP", iSock );*/
  if ( iSock == -1 )
  {
    debug( "Cannot create socket, error: %d", sock_errno() );
  }
  else if ( cSockets == _MAX_SOCKETS )
  {
    debug( "Too many sockets" );
  }
  else
  {
    aSockets[cSockets].aiSocket = iSock;
    xplThreadId( &aSockets[cSockets].ulTID );
    cSockets++;
    debugInc( "sockets" );
  }

  xplMutexUnlock( hmtxSockets );
  return iSock;
}