Example #1
0
int main( void ) {
    char cmd_buf[10];
    unsigned short data = 0;

    prvSetupHardware();


    for( ;; ) {
        blinky(2);

        INFO(welcome);
        UARTgets(UART0_BASE,cmd_buf, 10);
        SELECT();
        //	wait_ready();
        data=recv_command(MSR);
        INFO("reg MSR: %X", data);

        data=recv_command(LSR);
        INFO("reg LSR: %X", data);

        data = xmit_spi( LCR); // write to LCR
        INFO("reg LCR: %X", data);
        data = xmit_spi( 0x83); // write to LCR
        INFO("data: %X", data);

//		for(size_t i = 0; i < 10; ++i)	{
//			spi_uart_send(UART4_SSI_BASE,"ABDC",4);
//		}

        DESELECT();
    }
    return 0;
}
Example #2
0
int
sp_writer_recv (ShmPipe * self, ShmClient * client)
{
    ShmBuffer *buf = NULL, *prev_buf = NULL;
    struct CommandBuffer cb;

    if (!recv_command (client->fd, &cb))
        return -1;

    switch (cb.type) {
    case COMMAND_ACK_BUFFER:

        for (buf = self->buffers; buf; buf = buf->next) {
            if (buf->shm_area->id == cb.area_id &&
                    buf->offset == cb.payload.ack_buffer.offset) {
                sp_shmbuf_dec (self, buf, prev_buf);
                break;
            }
            prev_buf = buf;
        }

        if (!buf)
            return -2;

        break;
    default:
        return -99;
    }

    return 0;
}
Example #3
0
void
insert_tuple(struct tnt_tuple *tuple)
{
	if (tnt_insert(tnt, 0, TNT_FLAG_RETURN, tuple) < 0)
		fail_tnt_perror("tnt_insert");
	if (tnt_flush(tnt) < 0)
		fail_tnt_perror("tnt_flush");
	recv_command("insert");
}
Example #4
0
void
update(int32_t key, struct tnt_stream *stream)
{
	struct tnt_tuple *k = tnt_tuple(NULL, "%d", key);
	if (tnt_update(tnt, 0, TNT_FLAG_RETURN, k, stream) < 0)
		fail_tnt_perror("tnt_update");
	if (tnt_flush(tnt) < 0)
		fail_tnt_perror("tnt_flush");
	tnt_tuple_free(k);
	recv_command("update fields");
}
Example #5
0
void
select_tuple(int32_t key)
{
	struct tnt_list tuple_list;
	tnt_list_init(&tuple_list);
	struct tnt_tuple *tuple = tnt_list_at(&tuple_list, NULL);
	tnt_tuple(tuple, "%d", key);
	if (tnt_select(tnt, 0, 0, 0, 1, &tuple_list) < 0)
		fail_tnt_perror("tnt_select");
	if (tnt_flush(tnt) < 0)
		fail_tnt_perror("tnt_flush");
	recv_command("select");
	tnt_list_free(&tuple_list);
}
Example #6
0
static void
finish_job(void *arg)
{
	struct build_peer *peer = arg;

	LIST_REMOVE(peer, peer_link);
	if (peer->tmp_buf[0] == 'D')
		process_job(peer->job, JOB_DONE, 1);
	else if (peer->tmp_buf[0] == 'F')
		process_job(peer->job, JOB_FAILED, 1);
	else
		kill_peer(peer);
	peer->job = NULL;
	recv_command(peer);

	peer = LIST_FIRST(&unassigned_peers);
	if (peer != NULL)
		assign_job(peer);
}
Example #7
0
static void
listen_handler(int sock, short event, void *arg)
{
	struct build_peer *peer;
	struct sockaddr_in src;
	socklen_t src_len;
	int fd;

	src_len = sizeof(src);
	if ((fd = accept(sock, (struct sockaddr *)&src, &src_len)) == -1) {
		warn("Could not accept connection");
		return;
	}
	if (set_nonblocking(fd) == -1) {
		(void)close(fd);
		warn("Could not set non-blocking IO");
		return;
	}

	peer = xmalloc(sizeof(*peer));
	peer->fd = fd;
	peer->buf = NULL;
	recv_command(peer);
}
Example #8
0
unsigned long
sp_client_recv (ShmPipe * self, char **buf)
{
    char *area_name = NULL;
    ShmArea *newarea, *oldarea;
    ShmArea *area;
    struct CommandBuffer cb;
    int retval;

    if (!recv_command (self->main_socket, &cb))
        return -1;

    switch (cb.type) {
    case COMMAND_NEW_SHM_AREA:
        assert (cb.payload.new_shm_area.path_size > 0);
        assert (cb.payload.new_shm_area.size > 0);

        area_name = malloc (cb.payload.new_shm_area.path_size);
        retval = recv (self->main_socket, area_name,
                       cb.payload.new_shm_area.path_size, 0);
        if (retval != cb.payload.new_shm_area.path_size) {
            free (area_name);
            return -3;
        }

        newarea = sp_open_shm (area_name, cb.area_id, 0, 0,
                               cb.payload.new_shm_area.size);
        free (area_name);
        if (!newarea)
            return -4;

        oldarea = self->shm_area;
        newarea->next = self->shm_area;
        self->shm_area = newarea;
        /*
           if (oldarea)
           sp_shm_area_dec (self, oldarea);
         */
        break;

    case COMMAND_CLOSE_SHM_AREA:
        for (area = self->shm_area; area; area = area->next) {
            if (area->id == cb.area_id) {
                sp_shm_area_dec (self, area);
                break;
            }
        }
        break;

    case COMMAND_NEW_BUFFER:
        assert (buf);
        for (area = self->shm_area; area; area = area->next) {
            if (area->id == cb.area_id) {
                *buf = area->shm_area + cb.payload.buffer.offset;
                sp_shm_area_inc (area);
                return cb.payload.buffer.size;
            }
        }
        return -23;

    default:
        return -99;
    }

    return 0;
}
Example #9
0
int main(int argc , char* argv[])//exe ip port
{
	signal(13,SIG_IGN);
	signal(17,sig_handle);
	if(argc != 3)
	{
		printf("usge : exe ip port");
		exit(-1);
	}
	int fd_server ,fd_client;
	struct sockaddr_in client_addr ;
	int addrlen = sizeof(client_addr);
	fd_server = listenfd_init(argv[1],argv[2]);
	while( (fd_client = accept(fd_server,(struct sockaddr*)&client_addr,&addrlen) ) > 0 )
	{
		if(fd_client == -1)
		{
			if(errno == EINTR)
			{
				continue ;
			}
		}
		printf("a client connect :%s:%d\n",inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
		if(fork() == 0)
		{
			close(fd_server);
			char comd[1024];
			//circle recv msg
			while(1)
			{
				fflush(stdout);
				char sign[32];
				bzero(comd, 1024);
				recv_command(fd_client,comd);
				
				printf("comd:%s\n", comd);
				if(strncmp(comd, "ls", 2) == 0)
				{
					send_dir(fd_client);
				}
				else if(strncmp(comd, "download", 8) == 0)
				{
					ul_file(fd_client);
				}
				else if(strncmp(comd, "cd", 2) == 0)	
				{
					send_path(fd_client, comd);		
				}
				else if(strncmp(comd, "rm", 2) == 0)
				{
					system(comd);
				}
				else if(strncmp(comd, "upload", 6) == 0)
				{
					dl_file(fd_client);
				}
				else if(strncmp(comd, "cl", 2) == 0)
				{
					system("clear");
				}

			}
			exit(0);
		}
	}

}
Example #10
0
void service_client(newsflash::native_socket_t sock)
{
    bool is_authenticated = false;

    send_response(sock, "200 welcome");
    for (;;)
    {
        const auto cmd = recv_command(sock);
        if (cmd.empty())
        {
            std::cout << "Client closed socket...\n";
            break;
        }

        if (cmd == "QUIT") {
            newsflash::closesocket(sock);
            break;
        }
        else if (cmd == "CAPABILITIES")
        {
            send_response(sock, "500 what?");
        }
        else if (cmd == "MODE READER")
        {
            if (is_authenticated)
                send_response(sock, "200 posting allowed");
            else
            {
                send_response(sock, "480 authentication required");
            }
        }
        else if (cmd == "AUTHINFO USER pass")
        {
            send_response(sock, "381 password required");
        }
        else if (cmd == "AUTHINFO PASS pass")
        {
            send_response(sock, "281 authentication accepted");
            is_authenticated = true;
        }
        else if (cmd == "AUTHINFO USER fail")
        {
            send_response(sock, "482 authentication rejected");
        }
        else if (cmd == "AUTHINFO PASS fail")
        {
            send_response(sock, "482 authentication rejected");
        }

        else if (cmd == "BODY 1")
        {
            send_response(sock, "420 no article with that message id");
        }
        else if (cmd == "BODY 2")
        {
            send_response(sock, "222 body follows");
            std::ifstream in("test_data/newsflash_2_0_0.yenc", std::ios::binary);
            if (!in.is_open())
                throw std::runtime_error("failed to open test_data/newsflash_2_0_0.yenc");

            std::string line;
            while (std::getline(in, line))
            {
                if (line.empty())
                    throw std::runtime_error("empty line!");
                if (line[0] == '.')
                    line = "." + line;
                send_response(sock, line, false);
            }
            send_response(sock, ".", false);
        }
        else if (cmd == "BODY 3")
        {
            send_response(sock, "222 body follows");
            std::ifstream in("test_data/newsflash_2_0_0.uuencode");
            if (!in.is_open())
                throw std::runtime_error("failed to open test_data/newsflash_2_0_0.uuencode");

            std::string line;
            while (std::getline(in, line))
            {
                if (line.empty())
                    throw std::runtime_error("empty line");
                if (line[0] == '.')
                    line = '.' + line;
                send_response(sock, line, false);
            }
            send_response(sock, ".", false);
        }
        else if (cmd == "BODY 4")
        {
            send_response(sock, "222 body follows");
            std::string content = 
               "here is some textual content\n"
               "first line.\n"
               ". second line starts with a dot\n"
               ".. two dots\n"
               "foo . bar\n"
               "...\n"
               "end\n";

            std::stringstream ss(content);

            std::string line;
            while (std::getline(ss, line))
            {
                if (line[0] == '.')
                    line = "." + line;
                send_response(sock, line, false);
            }
            send_response(sock, ".");
        }
        else if (cmd == "GROUP alt.binaries.foo")
        {
            send_response(sock, "211 5 1 5 alt.binaries.foo Group selected");
        }
        else if (cmd == "GROUP alt.binaries.bar")
        {
            send_response(sock, "411 no such newsgroup");
        }
        else if (cmd == "GROUP alt.binaries.authenticate")
        {

            send_response(sock, "480 authentication required");
        }
        else
        {
            send_response(sock, "500 what?");
        }

    }
    std::cout << "Thread exiting...\n";
}