Esempio n. 1
0
File: main.c Progetto: cz-it/magnode
int main(int argc, const char * argv[]) {
    mn_node *node = mn_new();
    mn_init(node);
    mn_connect(node, "tcp://127.0.0.1:8083", 50000);
    char *hello= "hello";
    mn_send(node, hello, strlen(hello), 50000);
    char recvbuf[1024] = {0};
    size_t len = 1024;
    mn_recv(node, recvbuf, &len, 5000);
    printf("len is %zu , buf is %s \n", len, recvbuf);
    
    mn_close(node);
    printf("Hello, World!\n");
    return 0;
}
Esempio n. 2
0
void gem_main(void)
{
    WORD    i;

    sh_rdinf();                 /* get start of emudesk.inf */
    if (!gl_changerez)          /* can't be here because of rez change,       */
        process_inf1();         /*  so see if .inf says we need to change rez */

    if (gl_changerez) {
        switch(gl_changerez) {
#if CONF_WITH_ATARI_VIDEO
        case 1:                     /* ST(e) or TT display */
            Setscreen(-1L,-1L,gl_nextrez-2,0);
            initialise_palette_registers(gl_nextrez-2,0);
            break;
#endif
#if CONF_WITH_VIDEL
        case 2:                     /* Falcon display */
            Setscreen(-1L, -1L, FALCON_REZ, gl_nextrez);
            initialise_palette_registers(FALCON_REZ,gl_nextrez);
            break;
#endif
        }
        gsx_wsclear();              /* avoid artefacts that may show briefly */
        /*
         * resolution change always resets the default drive to the
         * boot device.  TOS3 issues a Dsetdrv() when this happens,
         * which Hatari's GEMDOS drive emulation uses to keep track
         * of the current drive.  we do the same.
         */
        dos_sdrv(bootdev);
    }

    ml_ocnt = 0;

    gl_changerez = FALSE;

    mn_init();                      /* initialise variables for menu_register() */

    num_accs = count_accs();        /* puts ACC names in acc_name[] */

    D.g_acc = NULL;
    if (num_accs)
        D.g_acc = dos_alloc(num_accs*sizeof(AESPROCESS));
    if (D.g_acc)
        memset(D.g_acc,0x00,num_accs*sizeof(AESPROCESS));
    else num_accs = 0;

    totpds = num_accs + 2;

    disable_interrupts();
    set_aestrap();                  /* set trap#2 -> aestrap */

    /* init event recorder  */
    gl_recd = FALSE;
    gl_rlen = 0;
    gl_rbuf = NULL;

    /* link up all the evb's to the event unused list */
    eul = NULL;
    for (i = 0; i < 2; i++)
        ev_init(D.g_int[i].a_evb,EVBS_PER_PD);
    for (i = 0; i < num_accs; i++)
        ev_init(D.g_acc[i].a_evb,EVBS_PER_PD);

    /* initialize sync blocks */
    wind_spb.sy_tas = 0;
    wind_spb.sy_owner = NULL;
    wind_spb.sy_wait = 0;

    /*
     * init processes - TODO: should go in gempd or gemdisp.
     */

    /* initialize list and unused lists   */
    nrl = drl = NULL;
    dlr = zlr = NULL;
    fph = fpt = fpcnt = 0;

    /* init initial process */
    for(i=totpds-1; i>=0; i--)
    {
        rlr = pd_index(i);
        if (i < 2)
        {
            rlr->p_uda = &D.g_int[i].a_uda;
            rlr->p_cda = &D.g_int[i].a_cda;
        }
        else
        {
            rlr->p_uda = &D.g_acc[i-2].a_uda;
            rlr->p_cda = &D.g_acc[i-2].a_cda;
        }
        rlr->p_qaddr = rlr->p_queue;
        rlr->p_qindex = 0;
        memset(rlr->p_name, ' ', AP_NAMELEN);
        rlr->p_appdir[0] = '\0'; /* by default, no application directory */
        /* if not rlr then initialize his stack pointer */
        if (i != 0)
            rlr->p_uda->u_spsuper = &rlr->p_uda->u_supstk;
        rlr->p_pid = i;
        rlr->p_stat = 0;
    }
    curpid = 0;
    rlr->p_pid = curpid++;
    rlr->p_link = NULL;

    /* end of process init */

    /* restart the tick     */
    enable_interrupts();

    /*
     * screen manager process init. this process starts out owning the mouse
     * and the keyboard. it has a pid == 1
     */
    gl_mowner = ctl_pd = iprocess("SCRENMGR", ctlmgr);

    /*
     * run the accessories and the desktop until termination
     * (for shutdown or resolution change)
     */
    aes_run_rom_program(accdesk_start);

    /* restore previous trap#2 address */
    disable_interrupts();
    unset_aestrap();
    enable_interrupts();

    if (D.g_acc)
        dos_free((LONG)D.g_acc);
}
Esempio n. 3
0
void main(void)
{
   unsigned long last_time;
   unsigned char i;
   char str[80], bc_sock;
   float i1, i2;

   // initialize the C8051F12x
   setup();

   // initialize the CMX Micronet variables
   mn_init();

   // obtain IP address
   while (mn_dhcp_start(NULL, DHCP_DEFAULT_LEASE_TIME) != 1);

   // open UDP socket for broadcasts
   bc_sock = mn_open(multicast_addr, 1178, 1178, NO_OPEN, PROTO_UDP, STD_TYPE, udp_buf, DATA_BUFF_LEN);

   do {
      tcp_server();

      if (time() - last_time >= 100) {

         last_time = time();

         /* turn on LED */
         DAC0H = 0x0F;
         DAC0L = 0xFF;

         /* read ADC, convert to Ampere */
         i1 = adc_read(7) / 2.5 * 500;
         i2 = adc_read(6) / 2.5 * 500;

         /* apply calibration, measured 21.3.05 by WO */
         i1 = 0.9661*i1 + 0.63;
         i2 = 0.9692*i2 + 0.53;

         /* send time and socket states */
         sprintf(str, "COBRA SC: %6.2f A   COBRA NC: %6.2f A\r\n", i1, i2);

         /* broadcast data */
         udp_send(bc_sock, str, strlen(str));

         /* send data to all connected sockets */
         for (i = 0; i < NUM_SOCKETS; i++) {
            if (sock_info[i].tcp_state == TCP_ESTABLISHED) {
               tcp_send(i, str, strlen(str));
            }
         }
      }

      if (time() - last_time > 10) {
         /* turn off LED */
         DAC0H = 0x00;
         DAC0L = 0x00;
      }


   } while (1);
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	pthread_t sigth;
	sigset_t sigblock;
	int logflags = 0;
	int ret = 1;

	debug_init();

	sigemptyset(&sigblock);
	sigaddset(&sigblock, SIGHUP);
	sigaddset(&sigblock, SIGINT);
	sigaddset(&sigblock, SIGTERM);
#ifdef ENABLE_VT
	sigaddset(&sigblock, SIGPIPE);
#endif
	pthread_sigmask(SIG_BLOCK, &sigblock, NULL);

	if (conf_parse(&conf, argc, argv))
		return 1;

	if (conf.debug_level > 0)
		logflags = LOG_PERROR;

	openlog(basename(argv[0]), LOG_PID|logflags, LOG_DAEMON);

	syslog(LOG_INFO, "%s v%s started (%s)", PACKAGE_NAME, PACKAGE_VERSION,
	       entity_string[conf.mip6_entity]);
#ifdef ENABLE_VT
	if (vt_init() < 0)
		goto vt_failed;
#endif

	/* if not debugging, detach from tty */
	if (conf.debug_level == 0)
		daemon_start(1);
	else {
		/* if debugging with debug log file, detach from tty */
		if (conf.debug_log_file) {
			daemon_start(1);

			ret = debug_open(conf.debug_log_file);
			if (ret < 0) {
				fprintf(stderr, "can't init debug log:%s\n",
					strerror(-ret));
				goto debug_failed;
			}
			dbg("%s started in debug mode\n", PACKAGE_NAME);
		} else {
			dbg("%s started in debug mode, not detaching from terminal\n",
			    PACKAGE_NAME);
		}
		conf_show(&conf);
	}

	srandom(time(NULL));

	if (rr_cn_init() < 0)
		goto rr_cn_failed;
	if (policy_init() < 0)
		goto policy_failed;
	if (taskqueue_init() < 0)
		goto taskqueue_failed;
	if (bcache_init() < 0)
		goto bcache_failed;
	if (mh_init() < 0)
		goto mh_failed;
	if (icmp6_init() < 0)
		goto icmp6_failed;
	if (xfrm_init() < 0)
		goto xfrm_failed;
	cn_init();
	if ((is_ha() || is_mn()) && tunnelctl_init() < 0)
		goto tunnelctl_failed;
	if (is_ha() && ha_init() < 0) 
		goto ha_failed;
	if (is_mn() && mn_init() < 0)
		goto mn_failed;
#ifdef ENABLE_VT
	if (vt_start(conf.vt_hostname, conf.vt_service) < 0)
		goto vt_start_failed;
#endif
	if (pthread_create(&sigth, NULL, sigh, NULL))
		goto sigth_failed;
	pthread_join(sigth, NULL);
	ret = 0;
sigth_failed:
#ifdef ENABLE_VT
	vt_fini();
vt_start_failed:
#endif
	if (is_mn())
		mn_cleanup();
mn_failed:
	if (is_ha())
		ha_cleanup();
ha_failed:
	if (is_ha() || is_mn())
		tunnelctl_cleanup();
tunnelctl_failed:
	cn_cleanup();
	xfrm_cleanup();
xfrm_failed:
	icmp6_cleanup();
icmp6_failed:
	mh_cleanup();
mh_failed:
	bcache_cleanup();
bcache_failed:
	taskqueue_destroy();
taskqueue_failed:
	policy_cleanup();
policy_failed:
rr_cn_failed:
	debug_close();
debug_failed:
#ifdef ENABLE_VT
vt_failed:
#endif
	syslog(LOG_INFO, "%s v%s stopped (%s)", PACKAGE_NAME, PACKAGE_VERSION,
	       entity_string[conf.mip6_entity]);
	closelog();
	return ret;
}