Beispiel #1
0
/* always use this method to initiate osip_fifo_t.
*/
void
osip_fifo_init (osip_fifo_t * ff)
{
#ifdef OSIP_MT
  ff->qislocked = osip_mutex_init ();
  /*INIT SEMA TO BLOCK ON GET() WHEN QUEUE IS EMPTY */
  ff->qisempty = osip_sem_init (0);
#endif
  osip_list_init (&ff->queue);
  /* ff->nb_elt = 0; */
  ff->state = osip_empty;
}
Beispiel #2
0
/* always use this method to initiate osip_fifo_t.
*/
void
osip_fifo_init (osip_fifo_t * ff)
{
#ifdef OSIP_MT
  ff->qislocked = osip_mutex_init ();
  /*INIT SEMA TO BLOCK ON GET() WHEN QUEUE IS EMPTY */
  ff->qisempty = osip_sem_init (0);
#endif
  ff->queue = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
  osip_list_init (ff->queue);
  /* ff->nb_elt = 0; */
  ff->etat = vide;
}
struct osip_cond *
osip_cond_init ()
{
  osip_cond_t *cond = (osip_cond_t *) osip_malloc (sizeof (osip_cond_t));
  if (cond && (cond->mut = osip_mutex_init ()) != NULL)
    {
      cond->sem = osip_sem_init (0);	/* initially locked */
      return (struct osip_cond *) (cond);
    }
  osip_free (cond);

  return NULL;
}
Beispiel #4
0
void josua_printf(char *chfr, ...)
{
  va_list ap;  
  char buf1[256];
  
  VA_START (ap, chfr);
  vsnprintf(buf1,255, chfr, ap);

  if (log_mutex==NULL)
    {
      log_mutex = osip_mutex_init();
    }

  osip_mutex_lock(log_mutex);
  /* snprintf(log_buf1,199, "%80.80s\n", buf1); */
  if (log_buf1=='\0')
    snprintf(log_buf1,255, "[%s]", buf1);
  else if (log_buf2=='\0')
    {
      if (log_buf1!='\0')
	snprintf(log_buf2,255, "%s", log_buf1);
      snprintf(log_buf1,255, "[%s]", buf1);
    }
  else
    {
      if (log_buf2!='\0')
	snprintf(log_buf3,255, "%s", log_buf2);
      snprintf(log_buf2,255, "%s", log_buf1);
      snprintf(log_buf1,255, "[%s]", buf1);
    }
    
  osip_mutex_unlock(log_mutex);

  va_end (ap);

}
Beispiel #5
0
/*初始化将前承后继,finger表都设为自身
单节点状态*/
Node::Node(char * ip , char * port, char * ua_name)
{

	int i ;
	user_info_list=NULL;
	local_user_info_list=NULL;
	red_user_info_list=NULL;

	strcpy(localip,ip) ;

	strcpy(localport,port) ;

	if(user_agent)
	strcpy(user_agent,ua_name) ;

	constants = new Constants(NULL) ; 
	
	chordId = ChordId(localip , localport , constants) ;

	ip_family = AF_INET;

	j_bootstraps = NULL ; 

	expires = 3600 ;

	fingerTable = new FingerTable(constants, this)  ;

	gl_lock = osip_mutex_init ();

	#ifdef WIN32
		//-- Initializing windows socket library
		{
			WORD wVersionRequested;
			WSADATA wsaData;

			wVersionRequested = MAKEWORD(1,1);
			if(int i = WSAStartup(wVersionRequested,  &wsaData))
			{
				OSIP_TRACE (osip_trace
				 (__FILE__, __LINE__, OSIP_ERROR, NULL,
				 "node: Unable to initialize WINSOCK, reason: %d\n",i));
		    }
		}
	#endif

	adosip = new AdOsip() ;
	
	th_transport = new ThreadTransport(this) ;
	user_info_pipe=new jpipe_t();

	i  = initlog(LOGPATH) ;
	if (i < 0 )
	{
		printf("log open failed!") ;
	}

	//set the state 
	_state = new ClosedState() ;
	_state->Handle(this , INIT_SND , NULL , NULL) ;
	
}
Beispiel #6
0
eXosip_event_t *
eXosip_event_wait (int tv_s, int tv_ms)
{
  eXosip_event_t *je = NULL;

#if 0                           /* this does not seems to work. by now */
#if defined (CLOCK_REALTIME) || defined (WIN32) || defined (_WIN32_WCE)
  int i;

  struct timespec deadline;
  struct timespec interval;
  long tot_ms = (tv_s * 1000) + tv_ms;

  static struct osip_mutex *mlock = NULL;

  if (mlock == NULL)
    mlock = osip_mutex_init ();

  je = (eXosip_event_t *) osip_fifo_tryget (eXosip.j_events);
  if (je)
    return je;

  interval.tv_sec = tot_ms / 1000;
  interval.tv_nsec = (tot_ms % 1000) * 1000000L;

  __eXosip_clock_gettime (OSIP_CLOCK_REALTIME, &deadline);

  if ((deadline.tv_nsec += interval.tv_nsec) >= 1000000000L)
    {
      deadline.tv_nsec -= 1000000000L;
      deadline.tv_sec += 1;
  } else
    deadline.tv_nsec += interval.tv_nsec;

  deadline.tv_sec += interval.tv_sec;

  i = osip_cond_timedwait ((struct osip_cond *) eXosip.j_cond,
                           (struct osip_mutex *) mlock, &deadline);

#endif
#else
  /* basic replacement */
  {
    fd_set fdset;
    struct timeval tv;
    int max, i;

    FD_ZERO (&fdset);
#if defined (WIN32) || defined (_WIN32_WCE)
    FD_SET ((unsigned int) jpipe_get_read_descr (eXosip.j_socketctl_event),
            &fdset);
#else
    FD_SET (jpipe_get_read_descr (eXosip.j_socketctl_event), &fdset);
#endif
    max = jpipe_get_read_descr (eXosip.j_socketctl_event);
    tv.tv_sec = tv_s;
    tv.tv_usec = tv_ms * 1000;

    je = (eXosip_event_t *) osip_fifo_tryget (eXosip.j_events);
    if (je != NULL)
      return je;

	eXosip_lock();
	eXosip_retransmit_lost200ok();
	eXosip_unlock();

    if (tv_s == 0 && tv_ms == 0)
      return NULL;

    i = select (max + 1, &fdset, NULL, NULL, &tv);
    if (i <= 0)
      return 0;

    if (eXosip.j_stop_ua)
      return NULL;

    if (FD_ISSET (jpipe_get_read_descr (eXosip.j_socketctl_event), &fdset))
      {
        char buf[500];

        jpipe_read (eXosip.j_socketctl_event, buf, 499);
      }

    je = (eXosip_event_t *) osip_fifo_tryget (eXosip.j_events);
    if (je != NULL)
      return je;
  }
#endif

  return je;
}