示例#1
0
int main(int argc, char * argv[]) {

	/**
	 * Initialise CSP,
	 * No physical interfaces are initialised in this example,NjD
	 * so only the loopback interface is registered.
	 */

	/* Init buffer system with 10 packets of maximum 300 bytes each */
	printf("Initialising CSP\r\n");
	csp_buffer_init(2, 300);

	/* Init CSP with address MY_ADDRESS */
	csp_init(MY_ADDRESS);

	/* Start router task with 500 word stack, OS task priority 1 */
	csp_route_start_task(500, 1);

	/* Enable debug output from CSP */
	if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) {
		printf("Debug enabed\r\n");
		csp_debug_toggle_level(4);

		printf("Conn table\r\n");
		csp_conn_print_table();

		printf("Route table\r\n");
		csp_route_print_table();

		printf("Interfaces\r\n");
		csp_route_print_interfaces();

	}

	/**
	 * Initialise example threads, using pthreads.
	 */
	HANDLE threads[2];

	/* Server */
	printf("Starting Server task\r\n");
    threads[0] = (HANDLE) _beginthreadex(NULL, 0, task_server, NULL, 0, 0);	

	/* Client */
	printf("Starting Client task\r\n");
    threads[1] = (HANDLE) _beginthreadex(NULL, 0, task_client, NULL, 0, 0);	

	/* Wait for execution to end, except that is never going to happen here */
	WaitForMultipleObjects(2, threads, TRUE, INFINITE);

	return 0;

}
示例#2
0
文件: sendfile3.c 项目: janbre/NUTS
int main(int argc, char * argv[]) {

    /* Init buffer system with 10 packets of maximum 300 bytes each */
    csp_buffer_init(2, 800);

    /* Init CSP with address MY_ADDRESS */
    csp_init(MY_ADDRESS);

    /* Start router task with 500 word stack, OS task priority 1 */
    csp_route_start_task(500, 1);

    /* Enable debug output from CSP */
    if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) {
        printf("Debug eneabled\r\n");
        csp_debug_toggle_level(4);

        printf("Conn table\r\n");
        csp_conn_print_table();

        printf("Route table\r\n");
        csp_route_print_table();

        printf("Interfaces\r\n");
        csp_route_print_interfaces();

    }
    
	int iret1, iret2;

    csp_thread_handle_t handle_server;
    iret1 = csp_thread_create(task_server, (signed char *) "SERVER", 1000, NULL, 0, &handle_server);

    csp_thread_handle_t handle_client;
    iret2 = csp_thread_create(task_client, (signed char *) "CLIENT", 1000, NULL, 0, &handle_client);

	pthread_join(handle_client, NULL);
	printf("Client thread returns: %d\n", iret2);
	pthread_join(handle_server, NULL);
	printf("Server thread returns: %d\n", iret1);


    return 0;

}