/**
* test function that is called upon a failure on sending

 The application might use that callback if it has some other
 destination that can be used in case of failure of the current one
 If the application has no other destination to select, it is up to the
 application to release the buffer.
 

 @param userRef : pointer to a user reference: not used here
 @param socket_context_ref: socket context reference
 @param bufRef : pointer to the packet buffer on which the error has been encountered
 @param err_no : errno has reported by the sendto().
 
 @retval none
*/
void  storcli_lbg_north_userDiscCallBack(void *userRef,uint32_t socket_context_ref,void *bufRef,int err_no)
{

    /*
    ** release the current buffer if significant
    */
    if (bufRef != NULL) ruc_buf_freeBuffer(bufRef);
    
    severe("remote end disconnection");;
    /*
    ** release the context now and clean up all the attached buffer
    */
    af_unix_delete_socket(socket_context_ref);   
}
/**
*  Create a bunch of AF_UNIX socket associated with a Family

 @param  basename_p : Base name of the family
 @param  base_instance: index of the first instance
 @param  nb_instances: number of instance in the family
 @param  socket_tb_p : pointer to an array were the socket references will be stored
 @param  xmit_size : size for the sending buffer (SO_SNDBUF parameter)

 @retval: 0 success, all the socket have been created
 @retval < 0 error on at least one socket creation
*/
int af_unix_socket_listening_family_create (char *nicknamebase_p,char *basename_p, int base_instance,int nb_instances,
                                             int *socket_ctx_tb_p,af_unix_socket_conf_t *conf_p)
{
  int *local_socket_tb_p = socket_ctx_tb_p;
  char nickname[128];
  char sun_path[128];
  int i;
  int error = 0;


  /*
  ** Clear the socket table
  */
  memset(local_socket_tb_p,-1,sizeof(int)*nb_instances);
  /*
  ** Loop creation
  */
  for (i = 0; i < nb_instances; i++)
  {
     sprintf(sun_path,"%s_inst_%d",basename_p,base_instance+i);
     sprintf(nickname,"%s_%d",nicknamebase_p,base_instance+i);
     conf_p->instance_id = base_instance+i;
     local_socket_tb_p[i] = af_unix_sock_listening_create(nickname,sun_path,conf_p);
     if (local_socket_tb_p[i] == -1)
     {
       error = 1;
       break;
     }
  }
  if (error)
  {
    /*
    ** clean up the sockets that have been already created
    */
    for (i = 0; i < nb_instances; i++)
    {
      if (local_socket_tb_p[i] != -1) af_unix_delete_socket(local_socket_tb_p[i]);
      return -1;
    }
  }
  return 0;
}
Exemple #3
0
/**
* Load Balncing group deletion API

  - delete all the TCP of AF_UNIX conections
  - stop the timer  assoicated with each connection
  - release all the xmit pending buffers associated with the load balancing group 

 @param lbg_id : user ereference of the load balancing group
 
 @retval 0 : success
 @retval < 0  errno (see errno for details)
*/
int  north_lbg_delete(int lbg_id)
{
    int ret;
   north_lbg_entry_ctx_t *entry_p ;
   ruc_obj_desc_t        *pnext = (ruc_obj_desc_t*)NULL;
   north_lbg_ctx_t       *lbg_p;
   int i;
   void *bufRef;
   
   lbg_p = north_lbg_getObjCtx_p(lbg_id);
   if (lbg_p == NULL) 
   {
     errno = EINVAL;
     return -1;
   }

    lbg_p->state = NORTH_LBG_SHUTTING_DOWN;
    /*
    **get the pointer to the destination stored in the buffer
    */

    /*
    ** OK, now go the buffer that might be queued on that entry and do the same
    */
    for (i = 0;  i < lbg_p->nb_entries_conf; i++)
    {
      entry_p = &lbg_p->entry_tb[i];

      /*
      ** stop the timer
      */
      north_lbg_entry_stop_timer(entry_p);      
      /*
      ** delete the TCP or AF_UNIX connection
      */
      ret = af_unix_delete_socket(entry_p->sock_ctx_ref);
      if (ret < 0) severe("failure on af_unix_delete_socket()entry  %d",i);
      entry_p->sock_ctx_ref = -1;
      /*
      ** Purge the buffer that are queued in the xmitlist done of the entry
      */
      while ((bufRef = (void*) ruc_objGetNext((ruc_obj_desc_t*)&entry_p->xmitList,
                                           &pnext))
                  !=NULL) 
      { 
        /*
        ** remove it from the list because it might be queued afterwards on a new queue
        */        
        ruc_objRemove((ruc_obj_desc_t*)bufRef);
        while (1) 
        {	 	 
             if (lbg_p->userDiscCallBack!= NULL)
             {
              (lbg_p->userDiscCallBack)(NULL,lbg_p->index,bufRef, EPIPE); 
              break;        
             }
             /*
             ** release the buffer
             */
             ruc_buf_freeBuffer(bufRef); 
             break;               
        }   
      }
    }
    /*
    ** Purge the pending xmit list of the load balancer
    */
    for (i = 0; i < NORTH_LBG_MAX_PRIO; i++)
    {
      pnext = (ruc_obj_desc_t*)NULL;
      while ((bufRef = (void*) ruc_objGetNext((ruc_obj_desc_t*)&lbg_p->xmitList[i],
                                           &pnext))
                  !=NULL) 
      { 
        /*
        ** remove it from the list because it might be queued afterwards on a new queue
        */        
        ruc_objRemove((ruc_obj_desc_t*)bufRef);
        while (1) 
        {	 	 
             if (lbg_p->userDiscCallBack!= NULL)
             {
              (lbg_p->userDiscCallBack)(NULL,lbg_p->index,bufRef, EPIPE); 
              break;        
             }
             /*
             ** release the buffer
             */
             ruc_buf_freeBuffer(bufRef); 
             break;               
        }   
      }
    }
    /*
    ** release the lbg context
    */
    north_lbg_free_from_ptr(lbg_p);
    return 0;

}