This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about select function [code of probe.c]


#include <stdio.h>
#include <sys/errno.h>
#include <rpc/rpc.h>

void
probe ( rqstp, transp )
    struct svc_req *rqstp;
    SVCXPRT *transp;
{
  switch ( rqstp->rq_proc )
  {
    case NULLPROC:
      svc_sendreply ( transp, xdr_void, (void *)NULL );
    return;
    default:
      svcerr_noproc ( transp );
    return;
  };
};

int
main ( argc, argv )
  int argc;
  char *argv[];
{
  SVCXPRT *transp = NULL;
  fd_set readfds;
  int size = getdtablesize ( );

  if ( ( transp = svctcp_create ( RPC_ANYSOCK, 0, 0 ) ) == NULL )
  {
    perror ( "1" );
    exit ( 1 );
  };

  svc_unregister ( 0x2A000001, 1 );

  if ( !svc_register ( transp, 0x2A000001, 1, probe, IPPROTO_TCP ) )
  {
    perror ( "2" );
    exit ( 1 );
  };

  if ( argc > 1 ) while ( 1 )
  {
    readfds = svc_fdset;

    switch ( select ( size, &readfds, NULL, NULL, NULL ) )
    {
      case -1:
        if ( errno == EINTR )
          continue;
        else
        {
          perror ( "3" );
          exit ( 1 );
        };
      break;
      case 0:
        continue;
      break;
      default:
        if ( !bcmp ( &readfds, &svc_fdset, sizeof ( fd_set ) ) )
          continue;
        svc_getreqset ( transp );
      break;
    };
  }
  else
    svc_run ( );

  exit ( 0 );
};


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]