Пример #1
1
int32
sys_humber_nh_add_ref_item(uint32 nhid, sys_nh_info_com_t *p_ref_nhinfo, sys_info_ecmp_t *p_ecmpinfo)
{
    sys_nh_ref_list_node_t *p_ref_nh_list;

    p_ref_nh_list = mem_malloc(MEM_NEXTHOP_MODULE, sizeof(sys_nh_ref_list_node_t));
    if(NULL == p_ref_nh_list)
        return CTC_E_NO_MEMORY;

    /*Insert new node at first*/
    p_ref_nh_list->p_ref_nhinfo = p_ref_nhinfo;
    p_ref_nh_list->p_next = p_ecmpinfo->p_nhinfo->hdr.p_ref_nh_list;
    p_ecmpinfo->p_nhinfo->hdr.p_ref_nh_list = p_ref_nh_list;

    return CTC_E_NONE;
}
Пример #2
0
t_window *window_new(int with_glut)
{
	t_window *window = (t_window  *)mem_malloc(sizeof(t_window));

	window->fullscreen=0;
	window->width = 400;
	window->height = 300;
	window->width_def = 400;
	window->height_def = 300;
	window->viewport_width = 400;
	window->viewport_height = 300;
	window->change=0;

	return window;
}
Пример #3
0
void unbounded_buffer_init(unbounded_buffer_t *b) {
    node_t *node = (node_t *)mem_malloc(sizeof(node_t));
    node->ptr = NULL;
    node->next = NULL;
    b->head = node;
    b->tail = node;
    b->count = 0;
    mutex_init(&b->mutex);
    mutex_init(&b->head_mutex);
    mutex_init(&b->tail_mutex);
    cond_init(&b->fill);
    b->done = 0;
    b->workers = 0;
    mutex_init(&b->worker_mutex);
}
Пример #4
0
void text_init(const long max_text, const unsigned max_errors, const unsigned max_warnings, const unsigned tab_width)
{
  tabwidth = tab_width; 
  maxtext =(size_t) max_text;  /* set text buffer size */
  
  if ((long) maxtext != max_text)
    text_message(TEXT_WARNING, "-T%lu too large for architecture: recast to -T%u\n", max_text, maxtext); 
  maxerrors = max_errors;     /* set maximum number of errors per file */
  maxwarnings = max_warnings;  /* set maximum number of warnings per file */
  
  text_bot =(char *) mem_malloc(maxtext);  /* allocate text buffer */
  
  text_top = text_bot;        /* top of text character */
  text_current = last_char = first_char = text_bot + maxtext;  /* make new buffer region below top of text */
}
Пример #5
0
/**
 * Should be called at the beginning of the program to set up the
 * network interface. It calls the function low_level_init() to do the
 * actual setup of the hardware.
 *
 * This function should be passed as a parameter to netif_add().
 *
 * @param netif the lwip network interface structure for this ethernetif
 * @return ERR_OK if the loopif is initialized
 *         ERR_MEM if private data couldn't be allocated
 *         any other err_t on error
 */
err_t
ethernetif_init(struct netif *netif)
{
  struct ethernetif *ethernetif;

  LWIP_ASSERT("netif != NULL", (netif != NULL));
    
  ethernetif = mem_malloc(sizeof(struct ethernetif));
  if (ethernetif == NULL) {
    LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
    return ERR_MEM;
  }

#if LWIP_NETIF_HOSTNAME
  /* Initialize interface hostname */
  netif->hostname = "lwip";
#endif /* LWIP_NETIF_HOSTNAME */

  /*
   * Initialize the snmp variables and counters inside the struct netif.
   * The last argument should be replaced with your link speed, in units
   * of bits per second.
   */
  NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);

  netif->state = ethernetif;
  netif->name[0] = IFNAME0;
  netif->name[1] = IFNAME1;
  /* We directly use etharp_output() here to save a function call.
   * You can instead declare your own function an call etharp_output()
   * from it if you have to do some checks before sending (e.g. if link
   * is available...) */
  netif->output = etharp_output;
  netif->linkoutput = ethernetif_output;
  
  netif->hwaddr[0] =  MAC_ADDR_BYTE0;
  netif->hwaddr[1] =  MAC_ADDR_BYTE1;
  netif->hwaddr[2] =  MAC_ADDR_BYTE2;
  netif->hwaddr[3] =  MAC_ADDR_BYTE3;
  netif->hwaddr[4] =  MAC_ADDR_BYTE4;
  netif->hwaddr[5] =  MAC_ADDR_BYTE5;
  ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
  
  /* initialize the hardware */
  low_level_init(netif);
  lock = 0;
  return ERR_OK;
}
Пример #6
0
/**
 * Should be called at the beginning of the program to set up the
 * network interface. It calls the function prvLowLevelInit() to do the
 * actual setup of the hardware.
 *
 * This function should be passed as a parameter to pxNetIf_add().
 *
 * @param pxNetIf the lwip network interface structure for this etherpxNetIf
 * @return ERR_OK if the loopif is initialized
 *		 ERR_MEM if private data couldn't be allocated
 *		 any other err_t on error
 */
err_t ethernetif_init( struct netif *pxNetIf )
{
err_t xReturn = ERR_OK;

	/* This is taken from lwIP example code and therefore does not conform
	to the FreeRTOS coding standard. */
	
struct xEthernetIf *pxEthernetIf;

	LWIP_ASSERT( "pxNetIf != NULL", ( pxNetIf != NULL ) );
	
	pxEthernetIf = mem_malloc( sizeof( struct xEthernetIf ) );
	if( pxEthernetIf == NULL ) 
	{
		LWIP_DEBUGF(NETIF_DEBUG, ( "ethernetif_init: out of memory\n" ) );
		xReturn = ERR_MEM;
	}
	else
	{
		#if LWIP_NETIF_HOSTNAME
		{
			/* Initialize interface hostname */
			pxNetIf->hostname = "lwip";
		}
		#endif /* LWIP_NETIF_HOSTNAME */

		pxNetIf->state = pxEthernetIf;
		pxNetIf->name[ 0 ] = IFNAME0;
		pxNetIf->name[ 1 ] = IFNAME1;

		/* We directly use etharp_output() here to save a function call.
		* You can instead declare your own function an call etharp_output()
		* from it if you have to do some checks before sending (e.g. if link
		* is available...) */
		pxNetIf->output = etharp_output;
		pxNetIf->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
		pxNetIf->hwaddr_len = ETHARP_HWADDR_LEN;
		pxNetIf->mtu = netifMAX_MTU;
		pxNetIf->linkoutput = prvLowLevelOutput;

		pxEthernetIf->ethaddr = ( struct eth_addr * ) &( pxNetIf->hwaddr[ 0 ] );

		/* initialize the hardware */
		prvLowLevelInit( pxNetIf );
	}

	return xReturn;
}
Пример #7
0
/**
 * Start AutoIP client
 *
 * @param netif network interface on which start the AutoIP client
 */
err_t
autoip_start(struct netif *netif)
{
    struct autoip *autoip = netif->autoip;
    err_t result = ERR_OK;

    if(netif_is_up(netif)) {
        netif_set_down(netif);
    }

    /* Set IP-Address, Netmask and Gateway to 0 to make sure that
     * ARP Packets are formed correctly
     */
    netif->ip_addr.addr = 0;
    netif->netmask.addr = 0;
    netif->gw.addr      = 0;

    LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
                ("autoip_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0],
                 netif->name[1], (u16_t)netif->num));
    if(autoip == NULL) {
        /* no AutoIP client attached yet? */
        LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
                    ("autoip_start(): starting new AUTOIP client\n"));
        autoip = mem_malloc(sizeof(struct autoip));
        if(autoip == NULL) {
            LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
                        ("autoip_start(): could not allocate autoip\n"));
            return ERR_MEM;
        }
        memset( autoip, 0, sizeof(struct autoip));
        /* store this AutoIP client in the netif */
        netif->autoip = autoip;
        LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip"));
    } else {
        autoip->state = AUTOIP_STATE_OFF;
        autoip->ttw = 0;
        autoip->sent_num = 0;
        memset(&autoip->llipaddr, 0, sizeof(struct ip_addr));
        autoip->lastconflict = 0;
    }

    autoip_create_addr(netif, &(autoip->llipaddr));
    autoip->tried_llipaddr++;
    autoip_start_probing(netif);

    return result;
}
Пример #8
0
void paulosif_init (struct netif *netif, char *device_name)
{
    struct genericif *genericif;

    genericif = mem_malloc (sizeof (struct genericif));
    memset (genericif, 0, sizeof (struct genericif));
    netif->state = genericif;
    netif->name[0] = IFNAME0;
    netif->name[1] = IFNAME1;
    netif->output = paulosif_output;

    genericif->ethaddr = (struct eth_addr *) &(netif->hwaddr[0]);
    genericif->device_name = device_name;

    low_level_init (netif);
}
Пример #9
0
Value block_to_val(void* c_func, int num_params, int block_elems, ...)
{
  Func* func;
  Value f = obj_new(klass_func, (void**) &func);
  func->var_params = 0;
  func->num_params = num_params;
  func->func = c_func;
  func->is_block = true;
  func->block_elems = block_elems;
  
  va_list ap;
  va_start(ap, block_elems);
  func->block_data = mem_malloc(block_elems * sizeof(Value));
  for (int i = 0; i < block_elems; i++) func->block_data[i] = va_arg(ap, Value);
  return f;
}
Пример #10
0
void *
ur_alloc(size_t size)
{
    char *buf_p;

    total++;

    buf_p = mem_malloc(size);

    if (buf_p == NULL)
        return(NULL);

    memset(buf_p,0,size);

    return(buf_p);
}
Пример #11
0
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
                            int stacksize, int prio)
{
    kernel_pid_t res;
    char *stack = mem_malloc((size_t)stacksize);

    if (stack == NULL) {
        return ERR_MEM;
    }
    if ((res = thread_create(stack, stacksize, prio, THREAD_CREATE_STACKTEST,
                             (thread_task_func_t)thread, arg, name)) <= KERNEL_PID_UNDEF) {
        abort();
    }
    sched_switch((char)prio);
    return res;
}
Пример #12
0
static int response_file_process_request(struct http_state *http, const char *method, const char *url) {
    if (strcmp(method, "GET"))
        return 0;
    FILE *f = fopen(url + 1, "r");
    if (!f)
        return 0;
    http->response_priv = mem_malloc(sizeof (struct response_file_priv_s));
    if (!http->response_priv) {
        fclose(f);
        return 0;
    }
    struct response_file_priv_s *priv = http->response_priv;
    priv->f = f;
    http->code = 200;
    return 1;
}
Пример #13
0
t_engine *engine_new(const char *name)
{
	t_engine *engine = (t_engine *)mem_malloc(sizeof(t_engine));

	id_init(&engine->id, name);

	engine->processes=lst_new("lst");
	engine->garbage = lst_new("lst");
	engine->with_global_limit=ENGINE_WITH_GLOBAL_LIMIT;
	engine->global_limit = 0;
	engine->global_freq=ENGINE_GLOBAL_FREQ;
	engine->process_count=0;
	engine->process_id = 0;

	return engine;
}
Пример #14
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
err_t CallbackOnAccept(void *_arg, struct tcp_pcb *_newPCB, err_t _err)
{
    err_t ret_err;

    struct State *s;
    LWIP_UNUSED_ARG(_arg);
    LWIP_UNUSED_ARG(_err);
    

    /* Unless this pcb should have NORMAL priority, set its priority now.
        When running out of pcbs, low priority pcbs can be aborted to create
        new pcbs of higher priority. */
    tcp_setprio(_newPCB, TCP_PRIO_MIN);

    s = (struct State*)mem_malloc(sizeof(struct State));

    if (s)
    {
        s->state = S_ACCEPTED;
        s->numPort = ((unsigned short)POLICY_PORT == _newPCB->local_port) ? POLICY_PORT : DEFAULT_PORT;
        s->p = NULL;
        /* pass newly allocated s to our callbacks */
        tcp_arg(_newPCB, s);
        tcp_recv(_newPCB, CallbackOnRecieve);
        tcp_err(_newPCB, CallbackOnError);
        tcp_poll(_newPCB, CallbackOnPoll, 0);
        tcp_sent(_newPCB, CallbackOnSent);
        ret_err = ERR_OK;

        if (s->numPort == DEFAULT_PORT)
        {
            if (pcbClient == 0)
            {
                pcbClient = _newPCB;
                SocketFuncConnect();
                gEthIsConnected = true;
            }
        }

    }
    else
    {
        ret_err = ERR_MEM;
    }

    return ret_err;
}
Пример #15
0
hprocess_t process_alloc_with_io(hcchar * command,int inno,int outno){
    
    pid_t pid;
    
    pid = fork();
    
    if(pid < 0){
        
        hlog("fork error");
        close(inno);
        if(inno != outno){
            close(outno);
        }
    }
    else if(pid ==0 ){
        dup2(outno,STDIN_FILENO);
        dup2(inno,STDOUT_FILENO);
        execl(command,NULL);
        exit(EXIT_SUCCESS);
    }
    else{
        {
            process_t * process = (process_t *)mem_malloc(sizeof(process_t));
#ifdef O_NONBLOCK
            hint32 fl;
#endif
            mem_memset(process, 0, sizeof(process_t));
            
#ifdef O_NONBLOCK
            fl =  fcntl(inno, F_GETFL) ;
            fcntl(inno, F_SETFL, fl | O_NONBLOCK);
            fl =  fcntl(outno, F_GETFL) ;
            fcntl(outno, F_SETFL, fl | O_NONBLOCK);
#endif
            
            process->pipe_in = inno;
            process->pipe_out = outno;
            process->pid = pid;
            
            hlog("%s\n",command);
            
            return (hprocess_t)process;
        }
    }
    
    return NULL;
}
Пример #16
0
/**
 * SLIP netif initialization
 *
 * Call the arch specific sio_open and remember
 * the opened device in the state field of the netif.
 *
 * @param netif the lwip network interface structure for this slipif
 * @return ERR_OK if serial line could be opened,
 *         ERR_MEM if no memory could be allocated,
 *         ERR_IF is serial line couldn't be opened
 *
 * @note netif->num must contain the number of the serial port to open
 *       (0 by default)
 */
err_t
slipif_init(struct netif *netif)
{
  struct slipif_priv *priv;

  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));

  /* Allocate private data */
  priv = mem_malloc(sizeof(struct slipif_priv));
  if (!priv) {
    return ERR_MEM;
  }

  netif->name[0] = 's';
  netif->name[1] = 'l';
  netif->output = slipif_output;
  netif->mtu = SLIP_MAX_SIZE;
  netif->flags |= NETIF_FLAG_POINTTOPOINT;

  /* Try to open the serial port (netif->num contains the port number). */
  priv->sd = sio_open(netif->num);
  if (!priv->sd) {
    /* Opening the serial port failed. */
    mem_free(priv);
    return ERR_IF;
  }

  /* Initialize private data */
  priv->p = NULL;
  priv->q = NULL;
  priv->state = SLIP_RECV_NORMAL;
  priv->i = 0;
  priv->recved = 0;

  netif->state = priv;

  /* initialize the snmp variables and counters inside the struct netif
   * ifSpeed: no assumption can be made without knowing more about the
   * serial line!
   */
  NETIF_INIT_SNMP(netif, snmp_ifType_slip, 0);

  /* Create a thread to poll the serial line. */
  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
    SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
  return ERR_OK;
}
Пример #17
0
/* Read a line from ``fp'' into the dynamically allocated ``s'',
 * increasing ``s'' if necessary. The ending "\n" or "\r\n" is removed.
 * If a line ends with "\", this char and the linefeed is removed,
 * and the next line is read too.
 */
char *mutt_read_line (char *s, size_t * size, FILE * fp, int *line)
{
  size_t offset = 0;
  char *ch;

  if (!s) {
    s = mem_malloc (STRING);
    *size = STRING;
  }

  FOREVER {
    if (fgets (s + offset, *size - offset, fp) == NULL) {
      mem_free (&s);
      return NULL;
    }
    if ((ch = strchr (s + offset, '\n')) != NULL) {
      (*line)++;
      *ch = 0;
      if (ch > s && *(ch - 1) == '\r')
        *--ch = 0;
      if (ch == s || *(ch - 1) != '\\')
        return s;
      offset = ch - s - 1;
    }
    else {
      int c;

      c = getc (fp);            /* This is kind of a hack. We want to know if the
                                   char at the current point in the input stream is EOF.
                                   feof() will only tell us if we've already hit EOF, not
                                   if the next character is EOF. So, we need to read in
                                   the next character and manually check if it is EOF. */
      if (c == EOF) {
        /* The last line of fp isn't \n terminated */
        (*line)++;
        return s;
      }
      else {
        ungetc (c, fp);         /* undo our dammage */
        /* There wasn't room for the line -- increase ``s'' */
        offset = *size - 1;     /* overwrite the terminating 0 */
        *size += STRING;
        mem_realloc (&s, *size);
      }
    }
  }
}
Пример #18
0
ps_image* PICAPI ps_image_create_from_image(ps_image* i, const ps_rect* r)
{
    if (!picasso::is_valid_system_device()) {
        global_status = STATUS_DEVICE_ERROR;
        return 0;
    }

    if (!i) {
        global_status = STATUS_INVALID_ARGUMENT;
        return 0;
    }

    ps_rect rc = {0, 0, (float)i->buffer.width(), (float)i->buffer.height()}; 
    if (!r) {
        //Note: if rect is NULL, It equal reference.
        global_status = STATUS_SUCCEED;
        return ps_image_ref(i);
    } else {
        if (r->x > 0)
            rc.x = r->x;
        if (r->y > 0)
            rc.y = r->y;
        if (r->w > 0)
            rc.w = r->w;
        if (r->h > 0)
            rc.h = r->h;
    }

    ps_image *img = (ps_image*)mem_malloc(sizeof(ps_image));
    if (img) {
        img->refcount = 1;
        img->fmt = i->fmt;
        img->flage = buffer_alloc_image;
        img->host = (void*)ps_image_ref(i);
        int bpp = picasso::_byte_pre_color(i->fmt);
        new ((void*)&(img->buffer)) picasso::rendering_buffer; 
        img->buffer.attach(i->buffer.buffer()+_iround(rc.y*i->buffer.stride()+rc.x*bpp), 
                                       _iround(rc.w), _iround(rc.h), i->buffer.stride());
        img->buffer.set_transparent(i->buffer.is_transparent());
        img->buffer.set_color_channel(i->buffer.get_color_channel());
        global_status = STATUS_SUCCEED;
        return img;
    } else {
        global_status = STATUS_OUT_OF_MEMORY;
        return 0;
    }
}
Пример #19
0
void hashset_insert(hashset_t *h, char *str) {
    size_t bucket = hashset_hash(str) % h->buckets;
    mutex_lock(&h->mutexes[bucket]);
    node_t *node = h->heads[bucket];
    while (node != NULL) {
        if (strcmp((char *)node->ptr, str) == 0)
            break;
        node = node->next;
    }
    if (node == NULL) {
        node = (node_t *)mem_malloc(sizeof(node_t));
        node->ptr = (void *)str_duplicate(str);
        node->next = h->heads[bucket];
        h->heads[bucket] = node;
    }
    mutex_unlock(&h->mutexes[bucket]);
}
Пример #20
0
// new client accepted
err_t server_newclient(void *arg, struct tcp_pcb *pcb, err_t err)
{
    struct client *c = mem_malloc(sizeof *c); // XXX should be pooled!
    if (!c) return ERR_MEM;

    c->st = ACCEPTED;
    c->pcb = pcb;
    c->p = NULL;

    // hook up callbacks
    tcp_arg(pcb, c);
    tcp_recv(pcb, client_recv); // on data received
    tcp_err(pcb, client_err); // on error
    tcp_poll(pcb, client_poll, 1); // poll status
    tcp_sent(pcb, client_sent); // queued data sent
    return ERR_OK;
}
Пример #21
0
// 返回-1,发送过慢异常,清空事件
// 返回 1,发送链刚刚建立,需要建立写事件
int connector_push_packet(int fd, void *data, int len) {
    connector_t *con = connector_get_ptr(fd);
    // 连接引用计数
    con->processing_count --;
    logging_trace("%s:%d %d push_packet %d bytes, processing_count %d", con->ip, con->port, fd, con->processing_count);

    if(con->closed_flag) {
        if(len)
            mem_free(data);
        if(con->processing_count == 0) {
            logging_trace("%s:%d %d check closed_flag processing_count 0", con->ip, con->port, fd);
            connector_destroy(fd);
        }
        return 0;
    }
    if(!len && con->closing_flag && con->processing_count == 0 && con->send_q_count == 0) {
        logging_trace("%s:%d %d check closing_flag processing_count 0, send_q_count 0", con->ip, con->port, fd);
        connector_destroy(fd);
        return -1;
    }
    if(!len) {
        return 0;
    }
    // 发送队列计数
    con->send_q_count ++;

    if(con->send_q_count > MAX_SEND_Q_COUNT) {
        logging_trace("%s:%d %d send_q_count %d overflow", con->ip, con->port, fd, con->send_q_count);
        con->closed_flag = 1;
        mem_free(data);
        con->send_q_count --;
        return -1;
    }

    logging_trace("%s:%d %d send_q_count %d", con->ip, con->port, fd, con->send_q_count);
    send_q_t *q_entry = (send_q_t *)mem_malloc(sizeof(send_q_t));
    q_entry->send_buf = data;
    q_entry->buf_len = len;
    q_entry->send_len = 0;
    q_entry->next = NULL;

    send_q_t **curr = &con->send_q_head;
    while(*curr) *curr = (*curr)->next;
    *curr = q_entry;
    return con->send_q_count;
}
Пример #22
0
CSession *get_http_session( void )
{
	CSession *pRetCode = NULL;

	pRetCode = mem_malloc( sizeof( *pRetCode ) );
	if ( pRetCode )
	{
		memset( pRetCode, 0x00, sizeof( *pRetCode ) );
		
		pRetCode->init = init;
		pRetCode->release = release;
		pRetCode->handle_input = handle_input;
		pRetCode->handle_output = handle_output;
	}
	
	return pRetCode;
}
Пример #23
0
char *filespectilde(char *filespec)
{
#if BSDUNIX
    struct passwd *passwdPtr;
    register char *f;

    if (filespec && *filespec == '~')
    {
        passwdPtr = NULL;
        if (filespec[1] == '/' || filespec[1] == 0)     /* if ~/... or ~ */
        {   f = filespec + 1;
            passwdPtr = getpwuid(getuid());
        }
        else                            /* else ~name   */
        {
            char c;

            f = strpbrk(filespec," /");
            if (!f)
                f = filespec + strlen(filespec); /* point at trailing 0 */
            c = *f;
            *f = 0;
            passwdPtr = getpwnam(filespec + 1);
            *f = c;
        }
        if (passwdPtr)
        {   char *p;

            p = (char *) mem_malloc(strlen(passwdPtr->pw_dir) + strlen(f) + 1);
            if (p)
            {
                strcpy(p,passwdPtr->pw_dir);
                strcat(p,f);
                mem_free(filespec);
                filespec = p;
            }
        }
    }
#endif
#if MSDOS || __OS2__ || __NT__ || _WIN32
#endif
#if VMS
    assert(0);
#endif
    return filespec;
}
Пример #24
0
CNetEngine *create_engine( void )
{
	CNetEngine *pRetCode = NULL;
	
	CNetEngine *pNewEngine = NULL;
		
	pNewEngine = mem_malloc( sizeof( *pNewEngine ) );
	if ( pNewEngine )
	{
		memset( pNewEngine, 0x00, sizeof( *pNewEngine ) );
		
		//create epoll id.
		pNewEngine->iEngineId = epoll_create( MAX_EPOLL_SIZE );
		if ( pNewEngine->iEngineId >= 0 )
		{
			//create epoll task.
			pNewEngine->iIsRunning = 1;
			pNewEngine->pEngineThread = os_thread_create( engin_proc_task, pNewEngine, OS_THREAD_PRIORITY_NORMAL, 1024 * 512 );
			if ( pNewEngine->pEngineThread )
			{
				pRetCode = pNewEngine;
			}
			else 
			{
				log_print( "%s %s:%d !if ( pNewEngine->iEngineTid > 0 ) failed????????????????", __FILE__, __FUNCTION__, __LINE__ );
				pNewEngine->iIsRunning = 0;
			}
				
			if ( NULL == pRetCode)
			{
				close( pNewEngine->iEngineId );
				pNewEngine->iEngineId = -1;
				
				mem_free( pNewEngine );
					
				pNewEngine = NULL;
			}
		}
		else 
			log_print( "%s %s:%d !if ( pNewEngine->iEngineId >= 0 ) failed????????????????", __FILE__, __FUNCTION__, __LINE__ );
	}
	else 
		log_print( "%s %s:%d !if ( pNewEngine ) failed????????????????", __FILE__, __FUNCTION__, __LINE__ );
	
	return pRetCode;	
}
Пример #25
0
int you_manager_reply(void *request){
	void *buf;
	if(((struct umanager_req*)request)->manager.main == YES)
		main_imanager_req();
	if(((struct umanager_req*)request)->manager.mutex == YES)
		mutex_imanager_req();
	if(((struct umanager_req*)request)->manager.sem == YES)
		sem_imanager_req();
	if(((struct umanager_req*)request)->manager.barrier == YES)
		barrier_imanager_req();
	buf = mem_malloc(sizeof(struct request_header));
	((struct request_header*)buf)->msg_type = MSG_YOU_OK;
	((struct request_header*)buf)->seq_number = ((struct umanager_req*)request)->req.src_seq_number;
	sendTo(((struct umanager_req*)request)->req.src_node, buf, sizeof(struct request_header));	
	mem_free(buf);
	return 1;
}
Пример #26
0
ps_image* PICAPI ps_image_create_from_canvas(ps_canvas* c, const ps_rect* r)
{
    if (!picasso::is_valid_system_device()) {
        global_status = STATUS_DEVICE_ERROR;
        return NULL;
    }

    if (!c) {
        global_status = STATUS_INVALID_ARGUMENT;
        return NULL;
    }

    ps_rect rc = {0, 0, (float)c->buffer.width(), (float)c->buffer.height()};
    if (r) {
        if (r->x > 0) {
            rc.x = r->x;
        }
        if (r->y > 0) {
            rc.y = r->y;
        }
        if (r->w > 0) {
            rc.w = r->w;
        }
        if (r->h > 0) {
            rc.h = r->h;
        }
    }

    ps_image* img = (ps_image*)mem_malloc(sizeof(ps_image));
    if (img) {
        img->refcount = 1;
        img->fmt = c->fmt;
        img->flage = buffer_alloc_canvas;
        img->host = (void*)ps_canvas_ref(c);
        int bpp = picasso::_bytes_per_color(c->fmt);
        new ((void*)&(img->buffer)) picasso::rendering_buffer;
        img->buffer.attach(c->buffer.buffer()+_iround(rc.y*c->buffer.stride()+rc.x*bpp),
                                       _iround(rc.w), _iround(rc.h), c->buffer.stride());
        img->buffer.set_transparent(true);
        global_status = STATUS_SUCCEED;
        return img;
    } else {
        global_status = STATUS_OUT_OF_MEMORY;
        return NULL;
    }
}
Пример #27
0
/*
 * 1. Count the number of words
 * 2. Allocate space for an array of cstrings. 
 * 3. Allocate each cstring.
 * 4. Copy each word
 */
size_t cstring_split(cstring** dest, const char* src, const char* delim)
{
	const char* s;
	size_t end, i, len, nelem;

	assert(dest != NULL);
	assert(src != NULL);
	assert(delim != NULL);

	/* Skip to first substring */
	len = strlen(src);
	s = src + strspn(src, delim);

	/* Only delimiters in src */
	if(s - src == (int)len) 
		return 0;

	/* Count elements */
	for(nelem = 0; *s != '\0'; nelem++) {
		s += strcspn(s, delim);
		s += strspn(s, delim);
	}

	/* allocate space */
	if( (*dest = mem_malloc(sizeof **dest * nelem)) == NULL)
		return 0;
	else if(cstring_multinew(*dest, nelem) == 0) {
		mem_free(*dest);
		return 0;
	}

	/* Now copy */
	s = src + strspn(src, delim); /* start of first substring */
	for(i = 0; *s != '\0'; i++) {
		end = strcspn(s, delim);
		if(!cstring_pcat((*dest)[i], s, s + end)) {
			cstring_multifree(*dest, nelem);
			return 0;
		}

		s += end;
		s += strspn(s, delim);
	}

	return nelem;
}
Пример #28
0
static void netlink_decode (struct stack *stack, void *msg,int size,int bufsize,struct pbuf **out,u32_t pid
#if LWIP_CAPABILITIES
		,int cap
#endif
		)
{
	//char buf[BUF_MAXLEN];
	struct netlinkbuf nlbuf;
	struct nlmsghdr *h=(struct nlmsghdr *)msg;

	int offset=0;	
	if ((nlbuf.data=(char *) mem_malloc (bufsize)) == NULL)
		nlbuf.length=0;
	else
		nlbuf.length=bufsize;
	/*int success=1;*/

	while (NLMSG_OK(h, size)) {
		/*int err;*/
		int type;

		/*printf("h->nlmsg_type %x %d\n",h->nlmsg_type,h->nlmsg_type);*/
		if (h->nlmsg_type == NLMSG_DONE)
			return;
		type=h->nlmsg_type - RTM_BASE;
		h->nlmsg_pid=pid;
		if (type >= 0 && type < MGMT_TABLE_SIZE && mgmt_table[type] != NULL) {
#if LWIP_CAPABILITIES
			if (!NETLINK_IS_GET(type) && (cap&LWIP_CAP_NET_ADMIN) == 0)
				netlink_ackerror(h,-EPERM,&nlbuf,&offset);
			else
#endif
				mgmt_table[type](stack, h,&nlbuf,&offset);
		}

		h = NLMSG_NEXT(h, size);
	}
	if (size) {
		fprintf(stderr, "netlink malformed packet: extra %d bytes\n", size);
	}
	if (offset > 0) {
		*out=pbuf_alloc(PBUF_RAW,offset,PBUF_RAM);
		memcpy((*out)->payload,nlbuf.data,offset);
	}
	mem_free(nlbuf.data);
}
Пример #29
0
/**
  * @brief  processes tftp read operation
  * @param  upcb: pointer on udp pcb 
  * @param  to: pointer on remote IP address
  * @param  to_port: pointer on remote udp port
  * @param  FileName: pointer on filename to be read
  * @retval error code
  */
int tftp_process_read(struct udp_pcb *upcb, struct ip_addr *to, int to_port, char* FileName)
{
  tftp_connection_args *args = NULL;

  /* If Could not open the file which will be transmitted  */
  if (f_open(&file_SD, (const TCHAR*)FileName, FA_READ) != FR_OK)
  {
    tftp_send_error_message(upcb, to, to_port, TFTP_ERR_FILE_NOT_FOUND);

    tftp_cleanup_rd(upcb, args);

    return 0;
  }
  
  args = mem_malloc(sizeof *args);
  /* If we aren't able to allocate memory for a "tftp_connection_args" */
  if (!args)
  {
    /* unable to allocate memory for tftp args  */
    tftp_send_error_message(upcb, to, to_port, TFTP_ERR_NOTDEFINED);

    /* no need to use tftp_cleanup_rd because no "tftp_connection_args" struct has been malloc'd   */
    tftp_cleanup_rd(upcb, args);

    return 0;
  }

  /* initialize connection structure  */
  args->op = TFTP_RRQ;
  args->to_ip.addr = to->addr;
  args->to_port = to_port;
  args->block = 1; /* block number starts at 1 (not 0) according to RFC1350  */
  args->tot_bytes = 0;


  /* set callback for receives on this UDP PCB  */
  udp_recv(upcb, rrq_recv_callback, args);

  /* initiate the transaction by sending the first block of data,
    further blocks will be sent when ACKs are received */

  tftp_send_next_block(upcb, args, to, to_port);

  return 1;
}
Пример #30
0
void *block_new(const char *name)
{
	t_block *block  = (t_block *) mem_malloc( sizeof( t_block));

	block->cls = NULL;

	vset3i( block->idcol, 0, 0, 0);

	id_init(&block->id, name);
	bzero(block->type,_NAME_);
	
	vset3f( block->pos, 0, 0, 0);
	block->width = 0;
	block->height = 0;

	block->block_state.is_root=0;
	block->block_state.draw_outline=0;
	block->block_state.draw_plugs=0;
	block->block_state.is_mouse_over=0;
	block->block_state.update_geometry=1;
	block->block_state.is_a_loop = 0;
	block->block_state.is_in_rhizome = 0;
	block->block_state.frame_based = 0;
	block->block_state.connecting = 0;
	block->block_state.draw_clone_link = 0;

	block->tot_bricks=0;
	block->rhizome_order = -1;
	block->rhizome_pos = 0;

	block->bricks=NULL;
	block->submenu = NULL;
	block->hover = NULL;
	block->selected = NULL;
	block->rhizome = NULL;
	block->set = NULL;

	block->state = NULL;
	block->clone = NULL;

	block->up = 1;
	block->clones = 0;

	return block;
}