示例#1
0
main() 
{
	int s, t;
	if ((s = establish(PORTNUM)) < 0) 
	{													 				/* plug in the phone */
		perror("establish");
		exit(1);
	} 
																		/* how a concurrent server looks like */
	for (;;) 
	{																	/* loop for phone calls */
		if ((t= get_connection(s)) < 0) 
		{																/* get a connection */
			perror("accept"); 											/* bad */
			exit(1);	
		}
		switch( fork() ) 
		{																/* try to handle connection */
			case -1 : 													/* bad news. scream and die */
				perror("fork");
				close(s);
				close(t);
				exit(1);
			case 0 : 													/* we're the child, do something */
				close(s);
				do_something(t);
				close(t);
				exit(0);
			default : 													/* we're the parent so look for */
				close(t); 												/* another connection */
				continue;
		}
	}
}														 				/* end of main */
示例#2
0
 void connect() {
     if (disconnected || connected) {
         establish();
         disconnected = false;
         connecting = true;
     }
 }
示例#3
0
文件: srftp.c 项目: nogamann/os
int main(int argc, char **argv)
{
    int s, ns;
    unsigned short portnum;
    pthread_t junk;

    if (argc != 3 || strtol(argv[1], NULL, 0) < 1 || strtol(argv[1], NULL, 0) > 65535 ||
        strtol(argv[2], NULL, 0) < 0 || errno)
    {
        usage();
    }

    portnum = (unsigned short)strtol(argv[1], NULL, 0);
    gMaxFileSize = (size_t)strtol(argv[2], NULL, 0);

    s = establish(portnum);

    while (1)
    {
        if ((ns = accept(s, NULL, NULL)) < 0)
        {
            MAIN_ERROR("accept");
        }

        if (pthread_create(&junk, NULL, handleConnection, &ns))
        {
            MAIN_ERROR("pthread_create");
        }
    }

    return 0;
}
示例#4
0
main()
{
 int s, t, i; 
 if ((s= establish(34835)) < 0) { /* plug in the phone */ 
 	perror("establish error");
 	exit(-1); 
 } 
  //signal(SIGCHLD, fireman); /* this eliminates zombies */ 

   for (i=0;i=1;i++)   { /* loop for phone calls */ 
	  if ((t= get_connection(s)) < 0) { /* get a connection */ 
	  	if (errno == EINTR) /* EINTR might happen on accept(), */ 
	  	continue; /* try again */ 
	  	perror("accept"); /* bad */ 
	  	exit(1);
	  } 
	   switch(fork()) { /* try to handle connection */ 
	  	  case -1 : /* bad news. scream and die */ 
	   		perror("fork");
	   		close(s);
	  		close(t); 
	   		exit(1); 
	 	  case 0 : /* we're the child, do something */ 
		   close(s); 
		   do_something(t); 
		   exit(0); 
	  	  default : /* we're the parent so look for */ 
		   close(t); /* another connection */ 
		  continue; 
        } 
   } 
} 
示例#5
0
文件: gm.c 项目: carriercomm/ix
void Setup(ArgStruct *p)
{
  if(gm_open(&gm_p,0,5,"port2",(enum gm_api_version) GM_API_VERSION) != GM_SUCCESS)
  {
    printf(" Couldn't open board 0 port 2\n");
    exit(-1);
  }
  else
    printf("Opened board 0 port2\n");
  
  if( p->tr )
    p->prot.host_id = gm_host_name_to_node_id(gm_p, p->host);

  gm_free_send_tokens(gm_p, GM_LOW_PRIORITY, gm_num_send_tokens(gm_p));
  ltime = gm_dma_malloc(gm_p, sizeof(unsigned long));
  lrpt  = gm_dma_malloc(gm_p, sizeof(unsigned long)); 
  sync  = gm_dma_malloc(gm_p, 64); 
  sync1 = gm_dma_malloc(gm_p, 64);
  sprintf(sync, "Syncme");   

  establish(p);

  p->prot.num_stokens = gm_num_send_tokens(gm_p);

}   
示例#6
0
文件: isockstream.cpp 项目: YPCC/mfem
isockstream::isockstream(int port)
{
   portnum = port;

   if ( (portID = establish()) < 0)
      cout << "Server couldn't be established on port "
           << portnum << endl;
   Buf = NULL;
}
示例#7
0
文件: vms_cli.c 项目: FMayzek/gawk
/*		  qualifier is present on the [already parsed] command line */
U_Long
Cli_Present( const char *item )
{
    Dsc item_dsc;
    (void)lib$establish(lib$sig_to_ret);

    item_dsc.len = strlen(item_dsc.adr = (char *)item);
    return cli$present(&item_dsc);
}
void
Setup(ArgStruct *p)
{
    p->prot.mytid = pvm_mytid();
#ifdef DEBUG
    printf("My task id is %d \n",p->prot.mytid);
#endif

    establish(p);
}   
示例#9
0
文件: misc.c 项目: SysMan-One/netlib
/*
**++
**  ROUTINE:	netlib___find_symbol
**
**  FUNCTIONAL DESCRIPTION:
**
**  	tbs
**
**  RETURNS:	cond_value, longword (unsigned), write only, by value
**
**  PROTOTYPE:
**
**  	tbs
**
**  IMPLICIT INPUTS:	None.
**
**  IMPLICIT OUTPUTS:	None.
**
**  COMPLETION CODES:
**
**
**  SIDE EFFECTS:   	None.
**
**--
*/
unsigned int netlib___find_symbol (char *imgnam, char *symnam, void *symptr) {

    struct dsc$descriptor imgdsc, symdsc;

    lib$establish(lib$sig_to_ret);

    INIT_SDESC(imgdsc, strlen(imgnam), imgnam);
    INIT_SDESC(symdsc, strlen(symnam), symnam);
    return find_image_symbol(&imgdsc, &symdsc, symptr);

} /* netlib___find_symbol */
示例#10
0
int main(void) {
   int s = establish();
 
  /*  Block with accept() until a client connects  */
 
   switch (fork()) {
      case -1 :  /* Error, clean up and quit */
      case  0 :  /* This is the child, handle the client */
      default :  /* This is the parent, continue blocking */
   }
}
示例#11
0
void udp_readable_cb(EV_P_ ev_io *w, int revents)
{
  char b;
  struct sockaddr src;
  socklen_t len;
  struct Peer *p;
  (void) loop;
  (void) w;
  (void) revents;
  len = sizeof(src);
  recvfrom(sock, &b, 1, 0, &src, &len);
  p = get_peer(&src, len);
  switch (b)
  {
    case CON:
      printf("client wants to connect\n");
      if (!p)
      {
        p = new_peer();
        memcpy(&p->addr, &src, len);
        p->state = ACKNOWLEDGING;
        acknowledge(p);
      }
      else if (p->state == DEAD)
      {
        acknowledge(p);
        p->state = ACKNOWLEDGING;
      }  
      return;
    case ACK:
      if (p && (p->state == CONNECTING || p->state == ESTABLISHED))
      {
        establish(p);
        p->state = ESTABLISHED;
        printf("established\n");
      }
      return;
    case EST:
      if (p && p->state == ACKNOWLEDGING)
      {
        printf("established\n");
        p->state = ESTABLISHED;
        return;
      }
    case DIE:
      if (p)
      {
        printf("peer disconected\n");
        remove_peer(p);
      }
  }
}
示例#12
0
文件: dso_vms.c 项目: 274914765/C
/* We must do this in a separate function because of the way the exception
   handler works (it makes this function return */
static int do_find_symbol (DSO_VMS_INTERNAL * ptr,
                           struct dsc$descriptor_s *symname_dsc, void **sym, unsigned long flags)
{
    /* Make sure that signals are caught and returned instead of
       aborting the program.  The exception handler gets unestablished
       automatically on return from this function.  */
    lib$establish (lib$sig_to_ret);

    if (ptr->imagename_dsc.dsc$w_length)
        return lib$find_image_symbol (&ptr->filename_dsc, symname_dsc, sym, &ptr->imagename_dsc, flags);
    else
        return lib$find_image_symbol (&ptr->filename_dsc, symname_dsc, sym, 0, flags);
}
示例#13
0
文件: vms_cli.c 项目: FMayzek/gawk
/*		    parameter or qualifier from the command line   */
U_Long
Cli_Get_Value( const char *item, char *result, int size )
{
    Dsc item_dsc, res_dsc;
    U_Long sts;
    short len = 0;
    (void)lib$establish(lib$sig_to_ret);

    item_dsc.len = strlen(item_dsc.adr = (char *)item);
    res_dsc.len = size,  res_dsc.adr = result;
    sts = cli$get_value(&item_dsc, &res_dsc, &len);
    result[len] = '\0';
    return sts;
}
示例#14
0
long SslFilterBase::write(const void *data, unsigned long size){
	if(!m_established){
		if(!establish()){
			LOG_POSEIDON_DEBUG("Waiting for SSL handshake...");
			errno = EAGAIN;
			return -1;
		}
		m_established = true;
	}
	const long ret = ::SSL_write(m_ssl.get(), data, size);
	if(ret < 0){
		setErrnoBySslRet(m_ssl.get(), ret);
	}
	return ret;
}
static unsigned long
check_cli (struct dsc$descriptor_s *qual)
{
/*
**  Routine:    check_cli
**
**  Function:   Check to see if a CLD was used to invoke the program.
**
**  Formal parameters:
**
**      qual    - Address of descriptor for qualifier name to check.
**
*/
    lib$establish(lib$sig_to_ret);      /* Establish condition handler */
    return (cli$present(qual));         /* Just see if something was given */
}
示例#16
0
/*Main - establishes connection to server and sets up client. Partially from source above*/
main(int argc, char *argv[])
{
	if (argc != 2) {
		printf("Port number not specified.\n");
		exit(0);
	}
	portNum = atoi(argv[1]);
	if (portNum < 5000 || portNum > 65536) {
		printf("Port number out of range.\n");
		exit(0);
	}
        int s, t;
        if ((s = establish(portNum)) < 0)
        {                                    
                perror("establish");
                exit(1);
        }
                                             
        for (;;)
        {                                    
                if ((t= get_connection(s)) < 0)
                {                            /* get a connection */
                        perror("accept");    /* bad */
                        exit(1);
                }
                switch( fork() )
                {                       /* try to handle connection */
                        case -1 :      /* bad news. scream and die */
                                perror("fork");
                                close(s);
                                close(t);
                                exit(1);
                        case 0 :              /* we're the child, do something */
                                close(s);
                                do_something(t);
                                close(t);
                                exit(0);
                        default :              /* we're the parent so look for */
                                close(t);      /* another connection */
                                continue;
                }
        }
}
示例#17
0
int SOCKConnect_Private(int portnumber)
{
  struct sockaddr_in isa;
#if defined(PETSC_HAVE_ACCEPT_SIZE_T)
  size_t             i;
#else
  int                i;
#endif
  int                t;

/* open port*/
  listenport = establish((u_short) portnumber);
  if (listenport == -1) PETSC_MEX_ERRORQ("RECEIVE: unable to establish port\n");

/* wait for someone to try to connect */
  i = sizeof(struct sockaddr_in);
  if ((t = accept(listenport,(struct sockaddr*)&isa,(socklen_t*)&i)) < 0) PETSC_MEX_ERRORQ("RECEIVE: error from accept\n");
  close(listenport);
  return(t);
}
示例#18
0
文件: vms_cli.c 项目: FMayzek/gawk
/*			CLI$DCL_PARSE to parse it using specified tables */
U_Long
Cli_Parse_Command( const void *cmd_tables, const char *cmd_verb )
{
    struct { short len, code; void *adr; } fscn[2];
    struct { char rqtype, rqindx, rqflags, rqstat; unsigned :32;
	     Dsc rdesc; unsigned :32; unsigned :32; unsigned :32; } cmd;
    U_Long sts;
    int    ltmp;
    char   longbuf[8200];
    (void)lib$establish(lib$sig_to_ret);

    memset(&cmd, 0, sizeof cmd);
    cmd.rqtype = CLI$K_GETCMD;		/* command line minus the verb */
    sts = sys$cli(&cmd, (void *)0, (void *)0);	/* get actual command line */

    if (vmswork(sts)) {		/* ok => cli available & verb wasn't "RUN" */
	/* invoked via symbol => have command line (which might be empty) */
	/*    [might also be invoked via mcr or dcl; that's ok]		  */
	if (cmd.rqstat == CLI$K_VERB_MCR) {
	    /* need to strip image name from MCR invocation   */
	    memset(fscn, 0, sizeof fscn);
	    fscn[0].code = FSCN$_FILESPEC;	/* full file specification */
	    (void)sys$filescan(&cmd.rdesc, fscn, (long *)0);
	    cmd.rdesc.len -= fscn[0].len;	/* shrink size */
	    cmd.rdesc.adr += fscn[0].len;	/* advance ptr */
	}
	/* prepend verb and then parse the command line */
	strcat(strcpy(longbuf, cmd_verb), " "),  ltmp = strlen(longbuf);
	if (cmd.rdesc.len + ltmp > sizeof longbuf)
	    cmd.rdesc.len = sizeof longbuf - ltmp;
	strncpy(&longbuf[ltmp], cmd.rdesc.adr, cmd.rdesc.len);
	cmd.rdesc.len += ltmp,	cmd.rdesc.adr = longbuf;
	sts = cli$dcl_parse(&cmd.rdesc, cmd_tables);
    }

    return sts;
}
示例#19
0
/*----------------------------------------------------------------------------*\
  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  io_sLocal 		*local;
  pwr_tInt16		data = 0;
  pwr_sClass_Ai_AI32uP	*op;
  int			i;
  pwr_tFloat32		actvalue;
  io_sChannel		*chanp;
  pwr_sClass_ChanAi	*cop;
  pwr_sClass_Ai		*sop;
  int			sts;
  qbus_io_read 		rb;

  local = (io_sLocal *) cp->Local;
  op = (pwr_sClass_Ai_AI32uP *) cp->op;

  chanp = &cp->chanlist[0];
  for ( i = 0; i < cp->ChanListSize; i++)
  { 
    if ( !chanp->cop)
    {
      chanp++;
      continue;
    }
    cop = (pwr_sClass_ChanAi *) chanp->cop;
    sop = (pwr_sClass_Ai *) chanp->sop;

    if ( cop->CalculateNewCoef)
      AiRangeToCoef( chanp);

    if ( cop->ConversionOn)
    {
      if ( local->ScanCount[i] <= 1)
      {

#if defined(OS_ELN)
        vaxc$establish(machfailread);
#endif
        rb.Address = local->Address + 2*i;
        sts = read( local->Qbus_fp, &rb, sizeof(rb));
        data = (unsigned short) rb.Data;
        if ( sts == -1)
        {
#if 0
          /* Exceptionhandler was called */
          if ( io_fatal_error)
          {
            /* Activate emergency break */
            errh_Error( "Fatal read error, card '%s', IO is stopped", cp->Name);
            ctx->Node->EmergBreakTrue = 1;
            return IO__ERRDEVICE;
          }
#endif
          /* Increase error count and check error limits */
          op->ErrorCount++;

          if ( op->ErrorCount == op->ErrorSoftLimit)
            errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
          if ( op->ErrorCount >= op->ErrorHardLimit)
          {
            errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name);
            ctx->Node->EmergBreakTrue = 1;
            return IO__ERRDEVICE;
          }
	  chanp++;
          continue;
        }
	/* Convert rawvalue to sigvalue and actualvalue */
	sop->RawValue = data;
        sop->SigValue = data * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
	switch ( chanp->ChanClass)
        {
          case pwr_cClass_ChanAi:
	    io_ConvertAi( cop, data, &actvalue);
	    break;
          case pwr_cClass_ChanAit:
	    io_ConvertAit( (pwr_sClass_ChanAit *) cop, data, &actvalue);
	    break;
	}

        /* Filter */
	if ( sop->FilterType == 1 &&
	     sop->FilterAttribute[0] > 0 &&
	     sop->FilterAttribute[0] > ctx->ScanTime)
        {
	  actvalue = *(pwr_tFloat32 *)chanp->vbp +
		ctx->ScanTime / sop->FilterAttribute[0] *
		(actvalue - *(pwr_tFloat32 *)chanp->vbp);
        }

	*(pwr_tFloat32 *) chanp->vbp = actvalue;
        local->ScanCount[i] = cop->ScanInterval + 1;
      }
      local->ScanCount[i]--;
    }
    chanp++;
  }
  return 1;
}
示例#20
0
文件: server.c 项目: broglek/a2
int main() 
{
  
  int s, t, i;
  //pthread_mutex_init(&circmutex,NULL);
  workpointer = 0;
  dispatchpointer = 0;
  slotfill = 0;
  //struct worker_thread worker_threads[MAXWORKERS];
  pthread_t dispatcher;
  struct worker_data thread_data[MAXWORKERS];
  pthread_mutex_init(&fullbuf_mutex,NULL);
  pthread_cond_init(&fullbuf_cv,NULL);
  pthread_mutex_init(&dispatch_mutex,NULL);
  pthread_cond_init(&dispatch_cv,NULL);

  for (i=0;i<MAXWORKERS;i++)
    {
      pthread_mutex_init(&worker_mutex[i],NULL);
      pthread_cond_init(&worker_cv[i],NULL);
    }
  if(pthread_create(&dispatcher,NULL,dispatch_routine,NULL))
    {
      printf("pthread_create failed on dispatcher.\n");
      exit(1);
    }
  for(i=0;i<WORKERS;i++)
    {
      //thread_data[i] = (struct worker_data *)malloc(sizeof(int));
      thread_data[i].id = i;
      thread_data[i].active = 0;
      
      if (pthread_create(&(thread_data[i].thread), NULL, worker_routine, (void *)&thread_data[i]))
        {
          printf("pthread_create failed on thread %d.\n",i);
          exit(1);
        }
    }

  if ((s = establish(PORTNUM)) < 0)
  {
    perror("establish");
    exit(1);
  }
  for (;;)
 {             
   struct sockaddr * cliaddr = malloc(10000);
   socklen_t clilen = 10000;
    /* get a connection */
   if ((t= get_connection(s,cliaddr,&clilen)) < 0)
    {          
      perror("accept");          /* bad */
      exit(1);
    }
    char ip[46];
    unsigned short port;
 
    switch (cliaddr->sa_family) {
    case AF_INET:
      inet_ntop (AF_INET, &(((struct sockaddr_in *)cliaddr)->sin_addr), ip, sizeof (ip));
      port = ntohs (((struct sockaddr_in *)cliaddr)->sin_port);
      break;
    case AF_INET6:
      inet_ntop (AF_INET6, &(((struct sockaddr_in6 *)cliaddr)->sin6_addr), ip, sizeof (ip));
      port = ntohs (((struct sockaddr_in6 *)cliaddr)->sin6_port);
      break;
    default:
      snprintf (ip, sizeof (ip), "UNKNOWN FAMILY: %d", cliaddr->sa_family);
      port = 0;
      break;
    }
    printf("connection from %s, port %hu\n", ip, port);
    //client_address =  &(((struct sockaddr_in *)cliaddr)->sin_addr);
    int f;
    for(f=0;f<MAXWORKERS;f++)
      {
	if(&thread_data[f] != NULL)
	  {
	    if(thread_data[f].active == 0)
	      {
		pthread_mutex_lock(&worker_mutex[f]);
		thread_data[f].t = t;
		thread_data[f].active = 1;
		printf("thread %d takes it\n",f);
		//while(slotfill == MAXSLOTS);
		pthread_cond_signal(&worker_cv[f]);
		pthread_mutex_unlock(&worker_mutex[f]);
		break;
	      }
	  }
      }
    
 }
}
示例#21
0
/*----------------------------------------------------------------------------*\
  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  io_sLocal 		*local = (io_sLocal *) cp->Local;
  io_sRackLocal		*r_local = (io_sRackLocal *)(rp->Local);
  pwr_tUInt16		data = 0;
  pwr_tUInt16		invmask;
  pwr_tUInt16		testmask;
  pwr_tUInt16		testvalue;
  int			i;
  qbus_io_write		wb;
  int			sts;
  pwr_tTime             now;
  pwr_sClass_Do_HVDO32	*op = (pwr_sClass_Do_HVDO32 *) cp->op;
  int 			words = op->MaxNoOfChannels <= 16 ? 1 : 2;


#if defined(OS_ELN)
  vaxc$establish(machfailwrite);
#endif

  for ( i = 0; i < words; i++)
  { 
    if ( i == 1 && op->MaxNoOfChannels <= 16)
      break;

    if ( ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT)
    {
      if ( i == 0)
        data = op->FixedOutValue1;
      else
        data = op->FixedOutValue2;
    }
    else
      io_DoPackWord( cp, &data, i);

    if ( i == 0)
    {
      testmask = op->TestMask1;
      invmask = op->InvMask1;
    }
    else
    {
      testmask = op->TestMask2;
      invmask = op->InvMask2;
      if ( op->MaxNoOfChannels == 16)
        break;
    }

    /* Invert */
    data = data ^ invmask;

    /* Filter Po signals */
    if ( local->Filter[i].Found)
      io_PoFilter( local->Filter[i].sop, &data, local->Filter[i].Data);

    /* Testvalues */
    if ( testmask)
    {
      if ( i == 0)
        testvalue = op->TestValue1;
      else
        testvalue = op->TestValue2;
      data = (data & ~ testmask) | (testmask & testvalue);
    }

    if (r_local->Qbus_fp != 0 && r_local->s == 0) {
      /* Write to local Q-bus */
      wb.Data = data;
      wb.Address = local->Address[i];
      sts = write( local->Qbus_fp, &wb, sizeof(wb));
    }
    else {
      /* Ethernet I/O, Request a write to current address */
      bfbeth_set_write_req(r_local, (pwr_tUInt16) local->Address[i], data);
      sts = 1;      
    }

    if ( sts <= 0)
    {
#if 0
      /* Exceptionhandler was called */
      if ( io_fatal_error)
      {
        /* Activate emergency break */
        errh_Error( "Fatal write error, card '%s', IO is stopped", cp->Name);
        ctx->Node->EmergBreakTrue = 1;
        return IO__ERRDEVICE;
      }
#endif
      /* Increase error count and check error limits */
      time_GetTime(&now);

      if (op->ErrorCount > op->ErrorSoftLimit) {
        /* Ignore if some time has expired */
        if (now.tv_sec - local->ErrTime.tv_sec < 600)
          op->ErrorCount++;
      }
      else
        op->ErrorCount++;
      local->ErrTime = now;

      if ( op->ErrorCount == op->ErrorSoftLimit)
        errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
      if ( op->ErrorCount >= op->ErrorHardLimit)
      {
        errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name);
        ctx->Node->EmergBreakTrue = 1;
        return IO__ERRDEVICE;
      }
      continue;
    }
  }
  return 1;
}
示例#22
0
/*----------------------------------------------------------------------------*\
  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  io_sLocal 		*local;
  pwr_tUInt16		data = 0;
  pwr_sClass_Do_HVDO32	*op;
  pwr_tUInt16		invmask;
  pwr_tUInt16		testmask;
  pwr_tUInt16		testvalue;
  int			i;
  qbus_io_write		wb;
  int			sts;

  local = (io_sLocal *) cp->Local;
  op = (pwr_sClass_Do_HVDO32 *) cp->op;

#if defined(OS_ELN)
  vaxc$establish(machfailwrite);
#endif

  for ( i = 0; i < 2; i++)
  { 
    if ( ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT)
    {
      if ( i == 0)
        data = op->FixedOutValue1;
      else
        data = op->FixedOutValue2;
    }
    else
      io_DoPackWord( cp, &data, i);

    if ( i == 0)
    {
      testmask = op->TestMask1;
      invmask = op->InvMask1;
    }
    else
    {
      testmask = op->TestMask2;
      invmask = op->InvMask2;
      if ( op->MaxNoOfChannels == 16)
        break;
    }

    /* Invert */
    data = data ^ invmask;

    /* Filter Po signals */
    if ( local->Filter[i].Found)
      io_PoFilter( local->Filter[i].sop, &data, local->Filter[i].Data);

    /* Testvalues */
    if ( testmask)
    {
      if ( i == 0)
        testvalue = op->TestValue1;
      else
        testvalue = op->TestValue2;
      data = (data & ~ testmask) | (testmask & testvalue);
    }

    wb.Data = data;
    wb.Address = local->Address[i];
    sts = write( local->Qbus_fp, &wb, sizeof(wb));
    if ( sts == -1)
    {
#if 0
      /* Exceptionhandler was called */
      if ( io_fatal_error)
      {
        /* Activate emergency break */
        errh_Error( "Fatal write error, card '%s', IO is stopped", cp->Name);
        ctx->Node->EmergBreakTrue = 1;
        return IO__ERRDEVICE;
      }
#endif
      /* Increase error count and check error limits */
      op->ErrorCount++;

      if ( op->ErrorCount == op->ErrorSoftLimit)
        errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
      if ( op->ErrorCount >= op->ErrorHardLimit)
      {
        errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name);
        ctx->Node->EmergBreakTrue = 1;
        return IO__ERRDEVICE;
      }
      continue;
    }
  }
  return 1;
}
示例#23
0
void Setup(ArgStruct *p)
{
    int one = 1;
    int sockfd = -1;
    /* ptr to sockaddr_in in ArgStruct */
    struct sockaddr_in6 *lsin1, *lsin2;      
    
    char *host;
    struct hostent *hp;
    struct protoent *proto;
    int send_size, recv_size, sizeofint = sizeof(int);
	
    host = p->host;                           /* copy ptr to hostname */ 
	
    lsin1 = &(p->prot.sin1);
    lsin2 = &(p->prot.sin2);
	
    bzero((char *) lsin1, sizeof(*lsin1));
    bzero((char *) lsin2, sizeof(*lsin2));

    if ((sockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0){
	printf("NetPIPE: can't open stream socket! errno=%d\n", errno);
	exit(-4);
    }

    if(!(proto = getprotobyname("tcp"))){
	printf("NetPIPE: protocol 'tcp' unknown!\n");
	exit(555);
    }

    /* Attempt to set TCP_NODELAY */

    if(setsockopt(sockfd, proto->p_proto, TCP_NODELAY, &one, sizeof(one)) < 0)
    {
	printf("NetPIPE: setsockopt: TCP_NODELAY failed! errno=%d\n", errno);
	exit(556);
    }

    /* If requested, set the send and receive buffer sizes */

    if(p->prot.sndbufsz > 0)
    {
	if(setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &(p->prot.sndbufsz), 
		      sizeof(p->prot.sndbufsz)) < 0)
	{
	    printf("NetPIPE: setsockopt: SO_SNDBUF failed! errno=%d\n", errno);
	    printf("You may have asked for a buffer larger than the system can handle\n");
	    exit(556);
	}
	if(setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &(p->prot.rcvbufsz), 
		      sizeof(p->prot.rcvbufsz)) < 0)
	{
	    printf("NetPIPE: setsockopt: SO_RCVBUF failed! errno=%d\n", errno);
	    printf("You may have asked for a buffer larger than the system can handle\n");
	    exit(556);
	}
    }
    getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF,
	       (char *) &send_size, (void *) &sizeofint);
    getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF,
	       (char *) &recv_size, (void *) &sizeofint);
 
    if(!doing_reset) {
	fprintf(stderr,"Send and receive buffers are %d and %d bytes\n",
		send_size, recv_size);
	fprintf(stderr, "(A bug in Linux doubles the requested buffer sizes)\n");
    }

    if( p->tr ) {                             /* Primary transmitter */

	lsin1->sin6_family = AF_INET6;

	/* First attempt to convert the string to an IPv6 */
	/* address. */
	/* If the user supplied a real host name this will fail and */
  	/* we'll then do a name lookup. */

	if (inet_pton(AF_INET6, host, &lsin1->sin6_addr) == 0)
	{
	    if ((hp = gethostbyname2(host, AF_INET6)) == NULL)
	    {
		printf("NetPIPE: invalid hostname '%s'\n", host);
		exit(-5);
	    }

	    if (hp->h_addrtype != AF_INET6) 
	    {
		printf("NetPIPE: invalid hostname '%s'\n", host);
		exit(-5);
	    }
	    bcopy(hp->h_addr, (char*) &(lsin1->sin6_addr), 
		  hp->h_length);
	}

	lsin1->sin6_port = htons(p->port);
	
	p->commfd = sockfd;
	
    } else if( p->rcv ) {                     /* we are the receiver */
	bzero((char *) lsin1, sizeof(*lsin1));
	lsin1->sin6_family  = AF_INET6;
#if defined(SIN6_LEN)
	lsin1->sin6_len     = sizeof(*lsin1);
#endif
	lsin1->sin6_port    = htons(p->port);
	/* Setting this to all 0 is the "ANY" address. */
	bzero(&lsin1->sin6_addr, sizeof(lsin1->sin6_addr));
   
	if (bind(sockfd, (struct sockaddr *) lsin1, sizeof(*lsin1)) < 0){
	    printf("NetPIPE: server: bind on local address failed! errno=%d", errno);
	    exit(-6);
	}

	p->servicefd = sockfd;
    }
    p->upper = send_size + recv_size;

    establish(p);                               /* Establish connections */

}   
示例#24
0
/*----------------------------------------------------------------------------*\
  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  io_sLocal 		*local;
  pwr_tUInt16		data = 0;
  pwr_sClass_Di_DIX2	*op;
  pwr_tUInt16		invmask;
  pwr_tUInt16		convmask;
  int			i;
  int			sts;
  qbus_io_read 		rb;

  local = (io_sLocal *) cp->Local;
  op = (pwr_sClass_Di_DIX2 *) cp->op;

  for ( i = 0; i < 2; i++)
  { 
    if ( i == 0)
    {
      convmask = op->ConvMask1;
      invmask = op->InvMask1;
    }
    else
    {
      convmask = op->ConvMask2;
      invmask = op->InvMask2;
      if ( !convmask)
        break;
      if ( op->MaxNoOfChannels == 16)
        break;
    }

#if defined(OS_ELN)
    vaxc$establish(machfailread);
#endif
    rb.Address = local->Address[i];
    sts = read( local->Qbus_fp, &rb, sizeof(rb));
    data = (unsigned short) rb.Data;
    if ( sts == -1)
    {
#if 0
      /* Exceptionhandler was called */
      if ( io_fatal_error)
      {
        /* Activate emergency break */
        errh_Error( "Fatal read error, card '%s', IO i stopped", cp->Name);
        ctx->Node->EmergBreakTrue = 1;
        return IO__ERRDEVICE;
      }
#endif

      /* Increase error count and check error limits */
      op->ErrorCount++;

      if ( op->ErrorCount == op->ErrorSoftLimit)
        errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
      if ( op->ErrorCount >= op->ErrorHardLimit)
      {
        errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name);
        ctx->Node->EmergBreakTrue = 1;
        return IO__ERRDEVICE;
      }
      continue;
    }

    /* Invert */
    data = data ^ invmask;

    /* Filter ... */
    if ( local->Filter[i].Found)
      io_DiFilter( local->Filter[i].sop, &data, local->Filter[i].Data);

    /* Move data to valuebase */
    io_DiUnpackWord( cp, data, convmask, i);
  }
  return 1;
}
示例#25
0
gtcm_server()
{
	static readonly int4	reptim[2] = {-100000, -1};	/* 10ms */
       	static readonly int4	wait[2] =  {-1000000, -1};	/* 100ms */
	void		gtcm_ch(), gtcm_exi_handler(), gtcm_init_ast(), gtcm_int_unpack(), gtcm_mbxread_ast(),
			gtcm_neterr(), gtcm_read_ast(), gtcm_remove_from_action_queue(), gtcm_shutdown_ast(), gtcm_write_ast(),
			la_freedb();
	bool		gtcm_link_accept();
	bool		alid;
	char		buff[512];
	char		*h = NULL;
	char		*la_getdb();
	char		nbuff[256];
	char		*pak = NULL;
	char		reply;
	unsigned short	outlen;
	int4		closewait[2] = {0, -1};
	int4		inid = 0, mdl = 0, nid = 0, days = 0;
	int4		lic_status;
	int4		lic_x;
	int4		lm_mdl_nid();
	uint4		status;
	int		i, receive(), value;
	mstr		name1, name2;
	struct NTD	*cmu_ntdroot();
	connection_struct *prev_curr_entry;
	struct	dsc$descriptor_s	dprd;
	struct	dsc$descriptor_s	dver;
	$DESCRIPTOR(node_name, nbuff);
	$DESCRIPTOR(proc_name, "GTCM_SERVER");
	$DESCRIPTOR(timout, buff);
	DCL_THREADGBL_ACCESS;

	GTM_THREADGBL_INIT;
        assert(0 == EMPTY_QUEUE);       /* check so dont need gdsfhead everywhere */
	common_startup_init(GTCM_GNP_SERVER_IMAGE); /* Side-effect: Sets skip_dbtriggers to TRUE for non-trigger platforms */
	gtm_env_init();	/* read in all environment variables */
	name1.addr = "GTCMSVRNAM";
	name1.len = SIZEOF("GTCMSVRNAM") - 1;
	status = trans_log_name(&name1, &name2, nbuff);
	if (SS$_NORMAL == status)
	{
		proc_name.dsc$a_pointer = nbuff;
		proc_name.dsc$w_length = node_name.dsc$w_length = name2.len;
	} else if (SS$_NOLOGNAM == status)
	{
		MEMCPY_LIT(nbuff, "GTCMSVR");
		node_name.dsc$w_length = SIZEOF("GTCMSVR") - 1;
	} else
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status);
	sys$setprn(&proc_name);
	status = lib$get_foreign(&timout, 0, &outlen, 0);
	if ((status & 1) && (6 > outlen))
	{
		for (i = 0;  i < outlen;  i++)
		{
			value = value * 10;
			if (buff[i] <= '9' && buff[i] >= '0')
				value += buff[i] - 48;
			else
				break;
		}
		if (outlen && (i == outlen))
		{
			cm_timeout = TRUE;
			closewait[0] = value * -10000000;
		}
	}
	dprd.dsc$w_length = cm_prd_len;
	dprd.dsc$b_dtype  = DSC$K_DTYPE_T;
	dprd.dsc$b_class  = DSC$K_CLASS_S;
	dprd.dsc$a_pointer= cm_prd_name;
	dver.dsc$w_length = cm_ver_len;
	dver.dsc$b_dtype  = DSC$K_DTYPE_T;
	dver.dsc$b_class  = DSC$K_CLASS_S;
	dver.dsc$a_pointer= cm_ver_name;
	ast_init();
	licensed = TRUE;
	lkid = 2;
#	ifdef NOLICENSE
	lid = 1;
#	else
	/* this code used to be scattered to discourage reverse engineering, but since it now disabled, that seems pointless */
	lic_status = ((NULL == (h = la_getdb(LMDB))) ? LP_NOCNFDB : SS$_NORMAL);
	lic_status = ((1 == (lic_status & 1)) ? lm_mdl_nid(&mdl, &nid, &inid) : lic_status);
	lic_status = ((1 == (lic_status & 1)) ? lp_licensed(h, &dprd, &dver, mdl, nid, &lid, &lic_x, &days, pak) : lic_status);
	if (LP_NOCNFDB != lic_status)
		la_freedb(h);
	if (1 == (lic_status & 1))
	{
		licensed = TRUE;
		if (days < 14)
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_WILLEXPIRE);
	} else
	{
		licensed = FALSE;
		sys$exit(lic_status);
	}
#	endif
	gtcm_ast_avail = astq_dyn_avail - GTCM_AST_OVRHD;
	stp_init(STP_INITSIZE);
	rts_stringpool = stringpool;
	cache_init();
	procnum = 0;
	get_proc_info(0, TADR(login_time), &image_count);
        memset(proc_to_clb, 0, SIZEOF(proc_to_clb));
	status = cmi_init(&node_name, 0, 0, gtcm_init_ast, gtcm_link_accept);
	if (!(status & 1))
	{
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ((status ^ 3) | 4));
		sys$exit(status);
	}
	ntd_root = cmu_ntdroot();
	ntd_root->mbx_ast =  gtcm_mbxread_ast;
	ntd_root->err = gtcm_neterr;
	gtcm_connection = FALSE;
	lib$establish(gtcm_ch);
	gtcm_exi_blk.exit_hand = &gtcm_exi_handler;
	gtcm_exi_blk.arg_cnt = 1;
	gtcm_exi_blk.cond_val = &gtcm_exi_condition;
	sys$dclexh(&gtcm_exi_blk);
	INVOKE_INIT_SECSHR_ADDRS;
	initialize_pattern_table();
	assert(run_time); /* Should have been set by common_startup_init */
	while (!cm_shutdown)
	{
		if (blkdlist)
			gtcml_chkreg();

		assert(!lib$ast_in_prog());
		status = sys$dclast(&gtcm_remove_from_action_queue, 0, 0);
		if (SS$_NORMAL != status)
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) CMERR_CMSYSSRV, 0, status, 0);
		if (INTERLOCK_FAIL == curr_entry)
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) CMERR_CMINTQUE);
		if (EMPTY_QUEUE != curr_entry)
		{
			switch (*curr_entry->clb_ptr->mbf)
			{
				case CMMS_L_LKCANALL:
					reply = gtcmtr_lkcanall();
					break;
				case CMMS_L_LKCANCEL:
					reply = gtcmtr_lkcancel();
					break;
				case CMMS_L_LKREQIMMED:
					reply = gtcmtr_lkreqimmed();
					break;
				case CMMS_L_LKREQNODE:
					reply = gtcmtr_lkreqnode();
					break;
				case CMMS_L_LKREQUEST:
					reply = gtcmtr_lkrequest();
					break;
				case CMMS_L_LKRESUME:
					reply = gtcmtr_lkresume();
					break;
				case CMMS_L_LKACQUIRE:
					reply = gtcmtr_lkacquire();
					break;
				case CMMS_L_LKSUSPEND:
					reply = gtcmtr_lksuspend();
					break;
				case CMMS_L_LKDELETE:
					reply = gtcmtr_lkdelete();
					break;
				case CMMS_Q_DATA:
					reply = gtcmtr_data();
					break;
				case CMMS_Q_GET:
					reply = gtcmtr_get();
					break;
				case CMMS_Q_KILL:
					reply = gtcmtr_kill();
					break;
				case CMMS_Q_ORDER:
					reply = gtcmtr_order();
					break;
				case CMMS_Q_PREV:
					reply = gtcmtr_zprevious();
					break;
				case CMMS_Q_PUT:
					reply = gtcmtr_put();
					break;
				case CMMS_Q_QUERY:
					reply = gtcmtr_query();
					break;
				case CMMS_Q_ZWITHDRAW:
					reply = gtcmtr_zwithdraw();
					break;
				case CMMS_S_INITPROC:
					reply = gtcmtr_initproc();
					break;
				case CMMS_S_INITREG:
					reply = gtcmtr_initreg();
					break;
				case CMMS_S_TERMINATE:
					reply = gtcmtr_terminate(TRUE);
					break;
				case CMMS_E_TERMINATE:
					reply = gtcmtr_terminate(FALSE);
					break;
				case CMMS_U_LKEDELETE:
					reply = gtcmtr_lke_clearrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf);
					break;
				case CMMS_U_LKESHOW:
					reply = gtcmtr_lke_showrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf);
					break;
				case CMMS_B_BUFRESIZE:
					reply = CM_WRITE;
					value = *(unsigned short *)(curr_entry->clb_ptr->mbf + 1);
					if (value > curr_entry->clb_ptr->mbl)
					{
						free(curr_entry->clb_ptr->mbf);
						curr_entry->clb_ptr->mbf = malloc(value);
					}
					*curr_entry->clb_ptr->mbf = CMMS_C_BUFRESIZE;
					curr_entry->clb_ptr->mbl = value;
					curr_entry->clb_ptr->cbl = 1;
					break;
				case CMMS_B_BUFFLUSH:
					reply = gtcmtr_bufflush();
					break;
				case CMMS_Q_INCREMENT:
					reply = gtcmtr_increment();
					break;
				default:
					reply = FALSE;
					if (SS$_NORMAL == status)
                                                rts_error_csa(CSA_ARG(NULL)
							VARLSTCNT(3) ERR_BADGTMNETMSG, 1, (int)*curr_entry->clb_ptr->mbf);
					break;
			}
			if (curr_entry)		/* curr_entry can be NULL if went through gtcmtr_terminate */
			{
				status = sys$gettim(&curr_entry->lastact[0]);
				if (SS$_NORMAL != status)
					rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status);
				/* curr_entry is used by gtcm_mbxread_ast to determine if it needs to defer the interrupt message */
				prev_curr_entry = curr_entry;
				if (CM_WRITE == reply)
				{	/* if ast == gtcm_write_ast, let it worry */
					curr_entry->clb_ptr->ast = gtcm_write_ast;
					curr_entry = EMPTY_QUEUE;
					cmi_write(prev_curr_entry->clb_ptr);
				} else
				{
					curr_entry = EMPTY_QUEUE;
					if (1 == (prev_curr_entry->int_cancel.laflag & 1))
					{  /* valid interrupt cancel msg, handle in gtcm_mbxread_ast */
						status = sys$dclast(gtcm_int_unpack, prev_curr_entry, 0);
						if (SS$_NORMAL != status)
							rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status);
					} else  if (CM_READ == reply)
					{
						prev_curr_entry->clb_ptr->ast = gtcm_read_ast;
						cmi_read(prev_curr_entry->clb_ptr);
					}
				}
			}
		} else  if (1 < astq_dyn_avail)
		{
#			ifdef GTCM_REPTIM
			/* if reptim is not needed - and smw doesn't know why it would be - remove this	*/
			status = sys$schdwk(0, 0, &wait[0], &reptim[0]);
#			else
			status = sys$schdwk(0, 0, &wait[0], 0);
#			endif
			sys$hiber();
			sys$canwak(0, 0);
		}
		if (cm_timeout && (0 == gtcm_users))
                        sys$setimr(efn_ignore, closewait, gtcm_shutdown_ast, &cm_shutdown, 0);
	}
}
示例#26
0
char *webget(const char *host, unsigned short int portnum, 
	const char *file_requested, int *size)
{
    int fd;
    FILE *socket_read;
    FILE *socket_write;
    char *doc;
    int length;
    char buffer[BUFFERSIZE];
    int position;
    int is_chuncked;

    INFO("Connexion au serveur %s:%d", host, portnum);
    fd = establish(host, portnum);
    if (fd == -1) {
	*size = 0;
	return NULL;
    }

    INFO("Ouverture des flux lecture/écriture");
    socket_read = fdopen(fd, "r");
    if (socket_read == NULL) {
	ERROR("Echec de l'ouverture en lecture");
	*size = 0;
	return NULL;
    }

    socket_write = fdopen(fd, "w");
    if (socket_write == NULL) {
	ERROR("Echec de l'ouverture en écriture");
	*size = 0;
	return NULL;
    }

    INFO("Envoie de la requête HTTP au serveur pour récupérer %s", 
	    file_requested);
    fprintf(socket_write, "GET %s HTTP/1.1\nHost: %s\n\n", //Connection: close\n\n",
	    file_requested, host);
    fflush(socket_write);

    INFO("Lecture de la réponse à la requête HTTP");
    fgets(buffer, BUFFERSIZE, socket_read);
    DEBUG("Réponse : %s", buffer);
    if (strcmp(buffer, "HTTP/1.1 200 OK\r\n") == 0) {
        DEBUG("Transfert fractionné");
        is_chuncked = 1;
    } else {
        DEBUG("Transfert non fractionné");
        is_chuncked = 0;
    }

    INFO("Lecture de l'entête");
    while(fgets(buffer, BUFFERSIZE, socket_read) != NULL && strcmp(buffer, "\r\n") != 0) {
	DEBUG("En-tête : %s", buffer);
    }
    if (buffer == NULL) {
	ERROR("Erreur de lecture : %s", strerror(errno));
	*size = 0;
	return NULL;
    }

    INFO("Lecture du document");
    if (is_chuncked) {
        position = 0;
        doc = malloc(sizeof(char));
        if (doc == NULL) {
            FATAL("Erreur d'allocation mémoire : %s", strerror(errno));
            exit(100);
        }
        *size = 0;
        while (fscanf(socket_read,"%x", &length) == 1 && length > 0) {
            char *newptr;
            DEBUG("Taille du chunk : %d", length);
            fscanf(socket_read,"\r\n");
            *size += length;
            newptr = realloc(doc, *size+1);
            if (newptr == NULL) {
                ERROR("Erreur d'allocation mémoire");
                free(doc);
                *size = 0;
                return NULL;
            } else {
                doc = newptr;
            }
            while(length > 0) {
                int s = fread(doc+position, sizeof(char), length, socket_read);
                if (s == 0) {
                    ERROR("Erreur de lecture d'un chunk : %s", strerror(errno));
                    free(doc);
                    return NULL;
                }
                length -= s;
                position += s;
            }
        }
        doc[*size] = '\0';
    } else {
        char buffer[BUFFERSIZE];
        int s;
        doc = malloc(sizeof(char));
        if (doc == NULL) {
            FATAL("Erreur d'allocation mémoire : %s", strerror(errno));
            exit(100);
        }
        *size = 0;
        while ((s = fread(buffer, sizeof(char), BUFFERSIZE, socket_read)) > 0) {
            int old_size = *size;
            *size += s;
            char *newptr = realloc(doc, *size+1);
            if (newptr == NULL) {
                ERROR("Erreur d'allocation mémoire");
                free(doc);
                *size = 0;
                return NULL;
            } else {
                doc = newptr;
            }
            memcpy(doc + old_size, buffer, s);
        }
        doc[*size] = '\0';
    }

    //doc = extract_raw(socket_read, size, &everything, &stable_transform);
    DEBUG("Réponse : %s", doc);

    INFO("Fermeture des flux de lecture/écriture");
    fclose(socket_read);
    fclose(socket_write);

    INFO("Fermeture de la socket");
    close_socket(fd);

    return doc;
}
示例#27
0
文件: ib.c 项目: carriercomm/ix
void Setup(ArgStruct *p)
{

 int one = 1;
 int sockfd;
 struct sockaddr_in *lsin1, *lsin2;      /* ptr to sockaddr_in in ArgStruct */
 char *host;
 struct hostent *addr;
 struct protoent *proto;
 int send_size, recv_size, sizeofint = sizeof(int);
 struct sigaction sigact1;
 char logfilename[80];

 /* Sanity check */
 if( p->prot.commtype == NP_COMM_RDMAWRITE && 
     p->prot.comptype != NP_COMP_LOCALPOLL ) {
   fprintf(stderr, "Error, RDMA Write may only be used with local polling.\n");
   fprintf(stderr, "Try using RDMA Write With Immediate Data with vapi polling\n");
   fprintf(stderr, "or event completion\n");
   exit(-1);
 }
 
 /* Open log file */
 sprintf(logfilename, ".iblog%d", 1 - p->tr);
 logfile = fopen(logfilename, "w");

 host = p->host;                           /* copy ptr to hostname */ 

 lsin1 = &(p->prot.sin1);
 lsin2 = &(p->prot.sin2);

 bzero((char *) lsin1, sizeof(*lsin1));
 bzero((char *) lsin2, sizeof(*lsin2));

 if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
   printf("NetPIPE: can't open stream socket! errno=%d\n", errno);
   exit(-4);
 }

 if(!(proto = getprotobyname("tcp"))){
   printf("NetPIPE: protocol 'tcp' unknown!\n");
   exit(555);
 }

 if (p->tr){                                  /* if client i.e., Sender */


   if (atoi(host) > 0) {                   /* Numerical IP address */
     lsin1->sin_family = AF_INET;
     lsin1->sin_addr.s_addr = inet_addr(host);

   } else {
      
     if ((addr = gethostbyname(host)) == NULL){
       printf("NetPIPE: invalid hostname '%s'\n", host);
       exit(-5);
     }

     lsin1->sin_family = addr->h_addrtype;
     bcopy(addr->h_addr, (char*) &(lsin1->sin_addr.s_addr), addr->h_length);
   }

   lsin1->sin_port = htons(p->port);

 } else {                                 /* we are the receiver (server) */
   
   bzero((char *) lsin1, sizeof(*lsin1));
   lsin1->sin_family      = AF_INET;
   lsin1->sin_addr.s_addr = htonl(INADDR_ANY);
   lsin1->sin_port        = htons(p->port);

   /* re-use socket, common if netpipe aborts due to busted networks */
   one = 1;
   if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int))) {
       printf("NetPIPE: server: unable to setsockopt -- errno %d\n", errno);
       exit(-7);
   }
   
   if (bind(sockfd, (struct sockaddr *) lsin1, sizeof(*lsin1)) < 0){
     printf("NetPIPE: server: bind on local address failed! errno=%d", errno);
     exit(-6);
   }

 }

 if(p->tr)
   p->commfd = sockfd;
 else
   p->servicefd = sockfd;

 

 /* Establish tcp connections */

 establish(p);

 /* Initialize Mellanox Infiniband */

 if(initIB(p) == -1) {
   CleanUp(p);
   exit(-1);
 }
}   
示例#28
0
/*----------------------------------------------------------------------------*\
  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  io_sLocal 		*local;
  io_sRackLocal		*r_local = (io_sRackLocal *)(rp->Local);
  pwr_tUInt16		data = 0;
  pwr_sClass_Ssab_BaseDoCard *op;
  pwr_tUInt16		invmask;
  pwr_tUInt16		testmask;
  pwr_tUInt16		testvalue;
  int			i;
  qbus_io_write		wb;
  int			sts;
  pwr_tTime             now;
  int			bfb_error = 0;
  pwr_sClass_Ssab_RemoteRack	*rrp;

  local = (io_sLocal *) cp->Local;
  op = (pwr_sClass_Ssab_BaseDoCard *) cp->op;

#if defined(OS_ELN)
  vaxc$establish(machfailwrite);
#endif

  for ( i = 0; i < 2; i++)
  { 
    if ( i == 1 && op->MaxNoOfChannels <= 16)
      break;

    if ( ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT)
    {
      if ( i == 0)
        data = op->FixedOutValue1;
      else
        data = op->FixedOutValue2;
    }
    else
      io_DoPackWord( cp, &data, i);

    if ( i == 0)
    {
      testmask = op->TestMask1;
      invmask = op->InvMask1;
    }
    else
    {
      testmask = op->TestMask2;
      invmask = op->InvMask2;
      if ( op->MaxNoOfChannels == 16)
        break;
    }

    /* Invert */
    data = data ^ invmask;

    /* Filter Po signals */
    if ( local->Filter[i].Found)
      io_PoFilter( local->Filter[i].sop, &data, local->Filter[i].Data);

    /* Testvalues */
    if ( testmask)
    {
      if ( i == 0)
        testvalue = op->TestValue1;
      else
        testvalue = op->TestValue2;
      data = (data & ~ testmask) | (testmask & testvalue);
    }

    if (r_local->Qbus_fp != 0 && r_local->s == 0) {
      /* Write to local Q-bus */
      wb.Data = data;
      wb.Address = local->Address[i];
      sts = write( local->Qbus_fp, &wb, sizeof(wb));
    }
    else {
      /* Ethernet I/O, Request a write to current address */
      sts = 0;
      if ( !local->FirstScan)
	bfbeth_get_write_status(r_local, (pwr_tUInt16) local->Address[i], &sts);

      bfbeth_set_write_req(r_local, (pwr_tUInt16) local->Address[i], data);

      if (sts == -1) {
	/* Error handling for ethernet Qbus-I/O */
  	rrp = (pwr_sClass_Ssab_RemoteRack *) rp->op;
	if (bfb_error == 0) {
          op->ErrorCount++;
	  bfb_error = 1;
          if ( op->ErrorCount == op->ErrorSoftLimit)
            errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
          if ( op->ErrorCount == op->ErrorHardLimit)
            errh_Error( "IO Error hard limit reached on card '%s', stall action %d", cp->Name, rrp->StallAction);
          if ( op->ErrorCount >= op->ErrorHardLimit && rrp->StallAction == pwr_eSsabStallAction_ResetInputs ) {
	    sts = 1;
          }
          if ( op->ErrorCount >= op->ErrorHardLimit && rrp->StallAction == pwr_eSsabStallAction_EmergencyBreak ) {
            ctx->Node->EmergBreakTrue = 1;
            return IO__ERRDEVICE;
          }
	}
	if (sts == -1) continue;
      }
      else if ( sts == 1) {
	op->ErrorCount = 0;
      }
    }
    
    
    /* Error handling for local Qbus-I/O */
    if ( sts == -1)
    {
      /* Increase error count and check error limits */
      time_GetTime( &now);

      if (op->ErrorCount > op->ErrorSoftLimit) {
        /* Ignore if some time has expired */
        if (now.tv_sec - local->ErrTime.tv_sec < 600)
          op->ErrorCount++;
      }
      else
        op->ErrorCount++;
      local->ErrTime = now;


      if ( op->ErrorCount == op->ErrorSoftLimit)
        errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
      if ( op->ErrorCount >= op->ErrorHardLimit)
      {
        errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name);
        ctx->Node->EmergBreakTrue = 1;
        return IO__ERRDEVICE;
      }
      continue;
    }
  }
  if ( local->FirstScan)
    local->FirstScan = 0;
  return 1;
}
示例#29
0
/*----------------------------------------------------------------------------*\
  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  io_sLocal 		*local;
  io_sRackLocal		*r_local = (io_sRackLocal *)(rp->Local);
  pwr_tInt16		data = 0;
  pwr_sClass_Ssab_BaseACard *op;
  pwr_sClass_Ssab_RemoteRack	*rrp;
  int			i;
  pwr_tFloat32		actvalue;
  io_sChannel		*chanp;
  pwr_sClass_ChanAi	*cop;
  pwr_sClass_Ai		*sop;
  int			sts;
  qbus_io_read 		rb;
  int			bfb_error = 0;
  pwr_tTime             now;

  local = (io_sLocal *) cp->Local;
  op = (pwr_sClass_Ssab_BaseACard *) cp->op;

  chanp = &cp->chanlist[0];
  for ( i = 0; i < cp->ChanListSize; i++)
  { 
    if ( !chanp->cop || !chanp->sop)
    {
      chanp++;
      continue;
    }
    cop = (pwr_sClass_ChanAi *) chanp->cop;
    sop = (pwr_sClass_Ai *) chanp->sop;

    if ( cop->CalculateNewCoef)
      AiRangeToCoef( chanp);

    if ( cop->ConversionOn)
    {
      if ( local->ScanCount[i] <= 1)
      {

#if defined(OS_ELN)
        vaxc$establish(machfailread);
#endif
        if (r_local->Qbus_fp != 0 && r_local->s == 0) {
          rb.Address = local->Address + 2*i;
          sts = read( local->Qbus_fp, &rb, sizeof(rb));
          data = (unsigned short) rb.Data;
	}
        else {
          /* Ethernet I/O, Get data from current address */
          data = bfbeth_get_data(r_local, (pwr_tUInt16) (local->Address + 2*i), &sts);
          /* Yes, we want to read this address the next time aswell */
          bfbeth_set_read_req(r_local, (pwr_tUInt16) (local->Address + 2*i));	 

          if (sts == -1) {
	    /* Error handling for ethernet Qbus-I/O */
  	    rrp = (pwr_sClass_Ssab_RemoteRack *) rp->op;
	    if (bfb_error == 0) {
              op->ErrorCount++;
	      bfb_error = 1;
              if ( op->ErrorCount == op->ErrorSoftLimit)
                errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
              if ( op->ErrorCount == op->ErrorHardLimit)
                errh_Error( "IO Error hard limit reached on card '%s', stall action %d", cp->Name, rrp->StallAction);
              if ( op->ErrorCount >= op->ErrorHardLimit && rrp->StallAction == pwr_eSsabStallAction_ResetInputs )
	      {
	        data = 0;
	        sts = 1;
              }
              if ( op->ErrorCount >= op->ErrorHardLimit && rrp->StallAction == pwr_eSsabStallAction_EmergencyBreak )
	      {
                ctx->Node->EmergBreakTrue = 1;
                return IO__ERRDEVICE;
              }
	    }
	    if (sts == -1) {
	      chanp++;
	      continue;
	    }
          }
          else {
	    op->ErrorCount = 0;
          }
        }
	
        if ( sts == -1)
	/* Error handling for local Qbus-I/O */
        {
#if 0
          /* Exceptionhandler was called */
          if ( io_fatal_error)
          {
            /* Activate emergency break */
            errh_Error( "Fatal read error, card '%s', IO is stopped", cp->Name);
            ctx->Node->EmergBreakTrue = 1;
            return IO__ERRDEVICE;
          }
#endif
          /* Increase error count and check error limits */
          time_GetTime( &now);

          if (op->ErrorCount > op->ErrorSoftLimit) {
            /* Ignore if some time has expired */
            if (now.tv_sec - local->ErrTime.tv_sec < 600)
              op->ErrorCount++;
          }
          else
            op->ErrorCount++;
          local->ErrTime = now;

          if ( op->ErrorCount == op->ErrorSoftLimit)
            errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
          if ( op->ErrorCount >= op->ErrorHardLimit)
          {
            errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name);
            ctx->Node->EmergBreakTrue = 1;
            return IO__ERRDEVICE;
          }
	  chanp++;
          continue;
        }
	
        /* Convert rawvalue to sigvalue and actualvalue */
	sop->RawValue = data;
        sop->SigValue = data * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
	switch ( chanp->ChanClass)
        {
          case pwr_cClass_ChanAi:
	    io_ConvertAi( cop, data, &actvalue);
	    break;
          case pwr_cClass_ChanAit:
	    io_ConvertAit( (pwr_sClass_ChanAit *) cop, data, &actvalue);
	    break;
	}

        /* Filter */
	if ( sop->FilterType == 1 &&
	   sop->FilterAttribute[0] > 0 &&
	   sop->FilterAttribute[0] > ctx->ScanTime)
        {
	  actvalue = *(pwr_tFloat32 *)chanp->vbp +
	  ctx->ScanTime / sop->FilterAttribute[0] *
	  (actvalue - *(pwr_tFloat32 *)chanp->vbp);
        }

	*(pwr_tFloat32 *) chanp->vbp = actvalue;
        local->ScanCount[i] = cop->ScanInterval + 1;
	  
      }
      local->ScanCount[i]--;
    }
    chanp++;
  }
  return 1;
}
示例#30
0
/*----------------------------------------------------------------------------*\
  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
  io_tCtx	ctx,
  io_sAgent	*ap,
  io_sRack	*rp,
  io_sCard	*cp  
) 
{
  io_sLocal 		*local;
  io_sRackLocal		*r_local = (io_sRackLocal *)(rp->Local);
  pwr_sClass_Ao_HVAO4	*op;
  int			i;
  io_sChannel		*chanp;
  pwr_sClass_ChanAo	*cop;
  pwr_sClass_Ao		*sop;
  pwr_tFloat32		value;
  int			fixout;
  pwr_tUInt16		data;
  pwr_tFloat32		rawvalue;
  qbus_io_write		wb;
  int			sts;
  pwr_tTime             now;

  local = (io_sLocal *) cp->Local;
  op = (pwr_sClass_Ao_HVAO4 *) cp->op;
  
  fixout = ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT;

  chanp = &cp->chanlist[0];
  for ( i = 0; i < cp->ChanListSize; i++)
  { 
    if ( !chanp->cop)
    {
      chanp++;
      continue;
    }
    cop = (pwr_sClass_ChanAo *) chanp->cop;
    sop = (pwr_sClass_Ao *) chanp->sop;

    if ( *(pwr_tFloat32 *)chanp->vbp != local->OldValue[i] ||
         local->WriteFirst > 0 ||
	 cop->CalculateNewCoef ||
         fixout ||
         cop->TestOn || local->OldTestOn[i] != cop->TestOn)
    {
      if ( fixout)
        value = cop->FixedOutValue;
      else if ( cop->TestOn)
        value = cop->TestValue;
      else
	value = *(pwr_tFloat32 *) chanp->vbp;

      if ( cop->CalculateNewCoef)
        AoRangeToCoef( chanp);


      /* Convert to rawvalue */
      if ( value > cop->ActValRangeHigh)
        value = cop->ActValRangeHigh;
      else if ( value < cop->ActValRangeLow)
        value = cop->ActValRangeLow;

      rawvalue = cop->OutPolyCoef1 * value + cop->OutPolyCoef0;
      if ( rawvalue > 0)
        sop->RawValue = rawvalue + 0.5;
      else
        sop->RawValue = rawvalue - 0.5;
      data = sop->RawValue;

#if defined(OS_ELN)
      vaxc$establish(machfailwrite);
#endif
      if (r_local->Qbus_fp != 0 && r_local->s == 0) {
        wb.Data = data;
        wb.Address = local->Address + 2*i;
        sts = write( local->Qbus_fp, &wb, sizeof(wb));
      }
      else {
      	/* Ethernet I/O, Request a write to current address */
      	bfbeth_set_write_req(r_local, (pwr_tUInt16) (local->Address + 2*i), data);
      	sts = 1;      
      }
      
      if ( sts == -1)
      {
        /* Exceptionhandler was called */
#if 0
        if ( io_fatal_error)
        {
          /* Activate emergency break */
          errh_Error( "Fatal write error, card '%s', IO is stopped", cp->Name);
          ctx->Node->EmergBreakTrue = 1;
          return IO__ERRDEVICE;
        }
#endif
        /* Increase error count and check error limits */
        time_GetTime( &now);

        if (op->ErrorCount > op->ErrorSoftLimit) {
          /* Ignore if some time has expired */
          if (now.tv_sec - local->ErrTime.tv_sec < 600)
            op->ErrorCount++;
        }
        else
          op->ErrorCount++;
        local->ErrTime = now;

        if ( op->ErrorCount == op->ErrorSoftLimit)
          errh_Error( "IO Error soft limit reached on card '%s'", cp->Name);
        if ( op->ErrorCount >= op->ErrorHardLimit)
        {
          errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name);
          ctx->Node->EmergBreakTrue = 1;
          return IO__ERRDEVICE;
        }
	chanp++;
        continue;
      }
      else
        local->OldValue[i] = value;
    }
    local->OldTestOn[i] = cop->TestOn;
    chanp++;
  }
  if ( local->WriteFirst)
    local->WriteFirst--;
  return 1;
}