Esempio n. 1
0
uint32_t ruc_timer_deleteInternalSocket(ruc_timer_t *p)
{

  if (p->internalSocket[RUC_SOC_SEND] != -1)
  {
    close (p->internalSocket[RUC_SOC_SEND]);
    p->internalSocket[RUC_SOC_SEND] = -1;
  }
  if (p->internalSocket[RUC_SOC_RECV] != -1)
  {
    close (p->internalSocket[RUC_SOC_RECV]);
    p->internalSocket[RUC_SOC_SEND] = -1;
  }
  // 64BITS   if (p->intSockconnectionId[RUC_SOC_RECV] != (uint32_t) NULL)
  if (p->intSockconnectionId[RUC_SOC_RECV] != NULL)
  {
    ruc_sockctl_disconnect(p->intSockconnectionId[RUC_SOC_RECV]);
    // 64BITS     p->intSockconnectionId[RUC_SOC_RECV] = (uint32_t) NULL;
    p->intSockconnectionId[RUC_SOC_RECV] = NULL;
  }
  // 64BITS   if (p->intSockconnectionId[RUC_SOC_SEND] != (uint32_t) NULL)
  if (p->intSockconnectionId[RUC_SOC_SEND] != NULL)
  {
    ruc_sockctl_disconnect(p->intSockconnectionId[RUC_SOC_SEND]);
    // 64BITS     p->intSockconnectionId[RUC_SOC_SEND] = (uint32_t) NULL;
    p->intSockconnectionId[RUC_SOC_SEND] = NULL;
  }
  p->active = TRUE;

  return RUC_OK;
}
Esempio n. 2
0
uint32_t ruc_timer_createInternalSocket(ruc_timer_t *p)
{
  int    ret;
  uint32_t retcode = RUC_NOK;
  int    fileflags;


  /*
  **  1 - create the socket pair
  */

  ret = socketpair(  AF_UNIX,
                  SOCK_DGRAM,
                  0,
                  &p->internalSocket[0]);

  if (ret < 0)
  {
    /*
    ** unable to create the sockets
    */
    RUC_WARNING(errno);
    return RUC_NOK;
  }
  while (1)
  {
    /*
    ** change socket mode to asynchronous
    */
    if((fileflags=fcntl(p->internalSocket[RUC_SOC_SEND],F_GETFL,0))==-1)
    {
      RUC_WARNING(errno);
      break;
    }
    if(fcntl(p->internalSocket[RUC_SOC_SEND],F_SETFL,fileflags|O_NDELAY)==-1)
    {
      RUC_WARNING(errno);
      break;
    }
    /*
    ** 2 - perform the connection with the socket controller
    */
    p->intSockconnectionId[RUC_SOC_SEND]=
                 ruc_sockctl_connect(p->internalSocket[RUC_SOC_SEND],
                                     "TMR_SOCK_XMIT",
                                      16,
				     // 64BITS (uint32_t)p,
                                      p,
                                      &ruc_timer_callBack_InternalSock);
    // 64BITS     if (p->intSockconnectionId[RUC_SOC_SEND]== (uint32_t)NULL)
    if (p->intSockconnectionId[RUC_SOC_SEND]== NULL)
    {
      RUC_WARNING(RUC_SOC_SEND);
      break;
    }
    p->intSockconnectionId[RUC_SOC_RECV]=
                 ruc_sockctl_connect(p->internalSocket[RUC_SOC_RECV],
                                     "TMR_SOCK_RECV",
                                      16,
				     // 64BITS (uint32_t)p,
                                      p,
                                      &ruc_timer_callBack_InternalSock);
    // 64BITS     if (p->intSockconnectionId[RUC_SOC_RECV]== (uint32_t) NULL)
    if (p->intSockconnectionId[RUC_SOC_RECV]== NULL)
    {
      RUC_WARNING(RUC_SOC_SEND);
      break;
    }
    /*
    **  done
    */
    retcode = RUC_OK;
    break;

  }
  if (retcode != RUC_OK)
  {
    /*
    ** something wrong: close the sockets and disconnect
    **  from socket controller
    */
    close (p->internalSocket[RUC_SOC_SEND]);
    close (p->internalSocket[RUC_SOC_RECV]);
    // 64BITS     if (p->intSockconnectionId[RUC_SOC_RECV] != (uint32_t) NULL)
    if (p->intSockconnectionId[RUC_SOC_RECV] != NULL)
    {
      ruc_sockctl_disconnect(p->intSockconnectionId[RUC_SOC_RECV]);
      // 64BITS       p->intSockconnectionId[RUC_SOC_RECV] = (uint32_t) NULL;
      p->intSockconnectionId[RUC_SOC_RECV] = NULL;
    }
    // 64BITS     if (p->intSockconnectionId[RUC_SOC_SEND] != (uint32_t) NULL)
    if (p->intSockconnectionId[RUC_SOC_SEND] != NULL)
    {
      ruc_sockctl_disconnect(p->intSockconnectionId[RUC_SOC_SEND]);
      // 64BITS       p->intSockconnectionId[RUC_SOC_SEND] = (uint32_t) NULL;
      p->intSockconnectionId[RUC_SOC_SEND] = NULL;
    }
    return RUC_NOK;
  }
  return RUC_OK;
}
uint32_t af_unix_generic_cli_connectReply_CBK(void * socket_ctx_p,int socketId)
{
   uint32_t ret;
   int error = -1;
   af_unix_ctx_generic_t  *sock_p;
   sock_p = (af_unix_ctx_generic_t*)socket_ctx_p;
   int len =sizeof(int);

  ret = RUC_OK;
  while (1)
  {
    if (getsockopt (socketId,SOL_SOCKET,
                    SO_ERROR,&error,(socklen_t*)&len) == -1)
    {
      ERRLOG " ruc_tcp_client_connectReply_CBK: getsockopt error for context %d errno:%d ",(int)sock_p->index,errno ENDERRLOG
      if (sock_p->connectionId !=  NULL)
      {
	    ruc_sockctl_disconnect(sock_p->connectionId);
	    sock_p->connectionId = NULL;
      }
      close(socketId);
      sock_p->socketRef = -1;

      ret = RUC_NOK;
      break;
    }
    if (error == 0)
    {
      /*
      ** all is fine, perform the connection with the socket
      ** controller
      */
      ruc_sockctl_disconnect(sock_p->connectionId);
      sock_p->connectionId = NULL;

      /*
      ** reconnect with the application callback
      */
      sock_p->connectionId = ruc_sockctl_connect(sock_p->socketRef,  // Reference of the socket
                                                sock_p->nickname,   // name of the socket
                                                3,                  // Priority within the socket controller
                                                (void*)sock_p,      // user param for socketcontroller callback
                                                &af_unix_generic_client_connected_callBack_sock);  // Default callbacks
      if (sock_p->connectionId == NULL)
      {

        /*
        ** Delete the client connection or attempt to re-connect
        */
        warning("socket cannot re-connect with socket controller %s",sock_p->nickname);
        ret =  RUC_NOK;
        break;
      }
      /*
      ** Make sure the transmitter and receiver will be ready again;
      */
      sock_p->xmit.state = XMIT_READY;
      sock_p->recv.state = RECV_IDLE;
      sock_p->cnx_availability_state = AF_UNIX_CNX_AVAILABLE;
      if (sock_p->userAvailabilityCallBack!= NULL)
      {
        /**
        * application has a polling callback for the connection supervision
        */
        (sock_p->userAvailabilityCallBack)(sock_p->availability_param);   
      }
      ret =  RUC_OK;
      break;
    }
    /*
    **______________________
    ** there is an error
    **______________________
    */

    switch (error)
    {
      case EADDRINUSE:
      case EBADF:
      case ENOTSOCK:
      case EISCONN:

      case ECONNREFUSED:
      case ETIMEDOUT:
      /*
      ** no listening on port
      */
      default:
#if 0
        perror("tcp client error on connect");
#endif
        break;
     }
     /*
     **  disconnect from the socket controller
     **  and close the socket
     */
     ruc_sockctl_disconnect(sock_p->connectionId);
     sock_p->connectionId =  NULL;
     close(socketId);
     sock_p->socketRef = -1;
     ret =  RUC_NOK;
     break;
   }